Class: Mxrb::Compiler::LegacyPageBuilder

Inherits:
Object
  • Object
show all
Includes:
ModelValues
Defined in:
lib/mxrb/compiler/legacy_page_builder.rb

Overview

rubocop:disable Metrics/AbcSize, Metrics/ClassLength, Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity Writes deterministic Dojo page XML for the built-in Data Grid 1 contract.

Constant Summary collapse

VISUAL_WIDGET_TYPES =

Model elements that own visible client widgets. Supporting a page means rendering these elements, not merely serializing their nested settings.

%w[
  Forms$ActionButton Forms$CheckBox Forms$DataGrid Forms$DataView Forms$DatePicker
  Forms$DivContainer Forms$DropDown Forms$DynamicText Forms$ImageUploader Forms$ImageViewer
  Forms$Label
  Forms$Header Forms$LayoutGrid Forms$ListView Forms$MenuBar Forms$NavigationTree
  Forms$RadioButtonGroup Forms$ReferenceSelector Forms$ScrollContainer
  Forms$ReferenceSetSelector Forms$Table Forms$TemplateGrid Forms$VerticalSplitPane
  Forms$SidebarToggleButton Forms$SimpleMenuBar
  Forms$MobileBackButton Forms$MobileCancelButton Forms$MobileSaveButton
  Forms$SnippetCallWidget Forms$StaticImageViewer Forms$TabControl Forms$TextArea
  Forms$TextBox Forms$InputReferenceSetSelector CustomWidgets$CustomWidget
].freeze
ACTION_BUTTON_TYPES =
%w[
  Forms$CancelChangesClientAction Forms$ClosePageClientAction Forms$FormAction
  Forms$MicroflowAction Forms$NoAction Forms$OpenLinkClientAction
  Forms$SaveChangesClientAction
].freeze
BOUND_WIDGET_TYPES =
%w[
  Forms$CheckBox Forms$DatePicker Forms$DropDown Forms$InputReferenceSetSelector
  Forms$RadioButtonGroup Forms$ReferenceSelector Forms$TextArea Forms$TextBox
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(source, web_root, profiles: [:dojo]) ⇒ LegacyPageBuilder

Returns a new instance of LegacyPageBuilder.



40
41
42
43
44
45
# File 'lib/mxrb/compiler/legacy_page_builder.rb', line 40

def initialize(source, web_root, profiles: [:dojo])
  @source = source
  @web_root = web_root
  @profiles = profiles
  @unsupported = Hash.new { |hash, key| hash[key] = [] }
end

Instance Method Details

#auditObject

Performs the same widget audit as #build without writing deployment files.



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mxrb/compiler/legacy_page_builder.rb', line 63

def audit
  @unsupported.clear
  (legacy_layouts + legacy_pages).each do |unit|
    name = "#{unit.module_name}.#{unit.document['Name']}"
    audit_unsupported_widgets(unit.document, name)
    descendants(unit.document).select { _1['$Type'] == 'Forms$DataGrid' }.each_with_index do |grid, index|
      compiler = LegacyDataGridCompiler.new(@source, name, grid, language: 'en_US', sequence: index + 1)
      compiler.html
      @unsupported[name].concat(compiler.unsupported)
    end
  end
  frozen_unsupported
end

#buildObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mxrb/compiler/legacy_page_builder.rb', line 47

def build
  pages = legacy_pages
  layouts = legacy_layouts
  languages.each do |language|
    layouts.each { write_layout(_1, language) }
    pages.each { write_page(_1, language) }
  end
  write_manifest
  files = Dir.glob(File.join(@web_root, 'pages', '**', '*.xml')).select { File.file?(_1) }
  LegacyPageBuild.new(
    directory: File.join(@web_root, 'pages'), files: files.length,
    bytes: files.sum { File.size(_1) }, unsupported_widgets: frozen_unsupported
  )
end