Module: Mxrb::Scaffold::PageTemplates

Defined in:
lib/mxrb/scaffold/page_templates.rb

Overview

Audited page patterns that become ordinary editable Mendix pages.

Defined Under Namespace

Classes: Entry

Constant Summary collapse

ENTRIES =
[
  Entry.new('General', 'starter', 'Title and page header', false),
  Entry.new('General', 'blank', 'Empty responsive content area', false),
  Entry.new('Dashboards', 'dashboard', 'Header and three responsive cards', false),
  Entry.new('Forms', 'form-vertical', 'DataView with vertical inputs and actions', true)
].freeze

Class Method Summary collapse

Class Method Details

.category_lines(group, last:) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/mxrb/scaffold/page_templates.rb', line 33

def category_lines(group, last:)
  category, entries = group
  heading = "#{last ? '└──' : '├──'} #{category}"
  children = entries.map.with_index do |entry, index|
    branch = index == entries.size - 1 ? '└──' : '├──'
    "#{last ? '    ' : ''}#{branch} #{entry.name}#{entry.description}"
  end
  [heading, *children]
end

.fetch(name) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/mxrb/scaffold/page_templates.rb', line 17

def fetch(name)
  return unless name

  ENTRIES.find { _1.name == name.to_s } || raise(
    ArgumentError, "page template must be one of: #{ENTRIES.map(&:name).join(', ')}"
  )
end

.payloadObject



43
44
45
46
47
48
49
50
51
# File 'lib/mxrb/scaffold/page_templates.rb', line 43

def payload
  ENTRIES.group_by(&:category).map do |category, entries|
    {
      category:, templates: entries.map do |entry|
        { name: entry.name, description: entry.description, data_backed: entry.data_backed }
      end
    }
  end
end

.treeObject



25
26
27
28
29
30
31
# File 'lib/mxrb/scaffold/page_templates.rb', line 25

def tree
  groups = ENTRIES.group_by(&:category).to_a
  lines = ['Page templates'] + groups.flat_map.with_index do |group, index|
    category_lines(group, last: index == groups.size - 1)
  end
  lines.join("\n")
end