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
# 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)

  {
    "title" => quoted_setting(settings, "Title"),
    "layout" => scalar_setting(settings, "Layout"),
    "folder" => quoted_setting(settings, "Folder"),
    "parameters" => parse_parameters(settings),
    "widgets" => parse_widgets(mdl),
    "widget_types" => widget_counts(mdl),
    "data_sources" => data_sources.uniq,
    "actions" => actions.map { |action| parse_action(action) },
    "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