Class: LcpRuby::Presenter::LayoutBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/presenter/layout_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presenter_definition, model_definition) ⇒ LayoutBuilder

Returns a new instance of LayoutBuilder.



6
7
8
9
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 6

def initialize(presenter_definition, model_definition)
  @presenter_definition = presenter_definition
  @model_definition = model_definition
end

Instance Attribute Details

#model_definitionObject (readonly)

Returns the value of attribute model_definition.



4
5
6
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 4

def model_definition
  @model_definition
end

#presenter_definitionObject (readonly)

Returns the value of attribute presenter_definition.



4
5
6
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 4

def presenter_definition
  @presenter_definition
end

Instance Method Details



38
39
40
41
42
43
44
45
46
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 38

def enrich_link_options_on_section(section)
  fields = section["fields"] || []
  enriched = fields.map do |f|
    next f unless f.is_a?(Hash)

    Presenter::Enrichment.enrich(f, location: :field, model_def: model_definition, loader: LcpRuby.loader)
  end
  section.merge("fields" => enriched)
end

#form_layoutObject



30
31
32
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 30

def form_layout
  presenter_definition.form_config["layout"] || "flat"
end

#form_sectionsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 11

def form_sections
  config = presenter_definition.form_config
  sections = config["sections"] || []
  result = sections.map do |s|
    if s["type"] == "nested_fields"
      if s["json_field"]
        normalize_json_field_section(s)
      else
        normalize_nested_section(s)
      end
    elsif s["type"] == "custom"
      s
    else
      normalize_section(s)
    end
  end
  append_custom_field_sections(result, context: :form)
end

#show_sectionsObject



34
35
36
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 34

def show_sections
  @show_sections ||= compute_show_sections
end