Class: MendixBridge::PageParser

Inherits:
Object
  • Object
show all
Defined in:
lib/mendix_bridge/page_parser.rb

Class Method Summary collapse

Class Method Details

.parse(description) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mendix_bridge/page_parser.rb', line 6

def parse(description)
  mdl = description.fetch("mdl")
  header = mdl.match(
    /\bpage\s+(?<name>[\w.]+)\s*\((?<settings>.*?)\)\s*\{/im
  )
  return { "mdl" => mdl, "parse_status" => "unsupported" } unless header

  settings = header[:settings]
  actions      = mdl.scan(/\bAction:\s*([^,\n\)]+)/i).flatten.map(&:strip)
  data_sources = mdl.scan(/\bDataSource:\s*([^,\n\)]+)/i).flatten.map(&:strip)

  # Build the hierarchical widget tree using the dedicated parser.
  widget_tree  = MdlParser.parse_page_widgets(mdl)
  all_widgets  = MdlParser.flat_widgets(widget_tree)
  widget_names = MdlParser.flat_widget_names(widget_tree)

  # Backward-compatible flat widget list (kept for existing consumers).
  flat_list = all_widgets.map do |node|
    entry = { "type" => node["type"], "name" => node["name"] }
    entry.compact
  end

  {
    "title"           => quoted_setting(settings, "Title"),
    "layout"          => scalar_setting(settings, "Layout"),
    "folder"          => quoted_setting(settings, "Folder"),
    "parameters"      => parse_parameters(settings),
    "widget_tree"     => widget_tree,
    "widgets"         => flat_list,
    "widget_names"    => widget_names,
    "widget_types"    => widget_counts(all_widgets),
    "data_sources"    => data_sources.uniq,
    "actions"         => actions.map { |a| parse_action(a) },
    "microflow_calls" => referenced(actions, "microflow"),
    "nanoflow_calls"  => referenced(actions, "nanoflow"),
    "page_links"      => referenced(actions, "show_page"),
    "attributes"      => mdl.scan(/\bAttribute:\s*([^,\n\)]+)/i).flatten.map(&:strip).uniq,
    "view_roles"      => mdl.scan(
      /^grant\s+view\s+on\s+page\s+[\w.]+\s+to\s+([\w.]+)/i
    ).flatten,
    "mdl"             => mdl,
    "parse_status"    => "parsed"
  }.compact
end