Class: LcpRuby::Presenter::LayoutBuilder
- Inherits:
-
Object
- Object
- LcpRuby::Presenter::LayoutBuilder
- Defined in:
- lib/lcp_ruby/presenter/layout_builder.rb
Instance Attribute Summary collapse
-
#model_definition ⇒ Object
readonly
Returns the value of attribute model_definition.
-
#presenter_definition ⇒ Object
readonly
Returns the value of attribute presenter_definition.
Instance Method Summary collapse
- #enrich_link_options_on_section(section) ⇒ Object
- #form_layout ⇒ Object
- #form_sections ⇒ Object
-
#initialize(presenter_definition, model_definition) ⇒ LayoutBuilder
constructor
A new instance of LayoutBuilder.
- #show_sections ⇒ Object
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_definition ⇒ Object (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_definition ⇒ Object (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
#enrich_link_options_on_section(section) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 38 def (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_layout ⇒ Object
30 31 32 |
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 30 def form_layout presenter_definition.form_config["layout"] || "flat" end |
#form_sections ⇒ Object
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_sections ⇒ Object
34 35 36 |
# File 'lib/lcp_ruby/presenter/layout_builder.rb', line 34 def show_sections @show_sections ||= compute_show_sections end |