Class: LcpRuby::Dsl::CardBuilder
- Inherits:
-
Object
- Object
- LcpRuby::Dsl::CardBuilder
- Defined in:
- lib/lcp_ruby/dsl/presenter_builder.rb
Overview
Shared across all card-based layouts (tiles, kanban, future). Resolves to ‘index_config`; consumed by LcpRuby::Display::CardHelper.
Instance Method Summary collapse
- #actions(value) ⇒ Object
- #avatar_field(name, alt: nil) ⇒ Object
- #color_field(name, map: nil) ⇒ Object
- #description_field(name, max_lines: nil) ⇒ Object
- #field(name, **options) ⇒ Object
- #image_field(name, alt: nil) ⇒ Object
-
#initialize ⇒ CardBuilder
constructor
A new instance of CardBuilder.
- #render_with(partial) ⇒ Object
- #subtitle_field(name, renderer: nil, options: nil) ⇒ Object
- #title_field(name) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ CardBuilder
Returns a new instance of CardBuilder.
610 611 612 613 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 610 def initialize @hash = {} @fields = [] end |
Instance Method Details
#actions(value) ⇒ Object
645 646 647 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 645 def actions(value) @hash["actions"] = value.to_s end |
#avatar_field(name, alt: nil) ⇒ Object
635 636 637 638 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 635 def avatar_field(name, alt: nil) @hash["avatar_field"] = name.to_s @hash["avatar_alt_field"] = alt.to_s if alt end |
#color_field(name, map: nil) ⇒ Object
640 641 642 643 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 640 def color_field(name, map: nil) @hash["color_field"] = name.to_s @hash["color_map"] = HashUtils.stringify_deep(map) if map end |
#description_field(name, max_lines: nil) ⇒ Object
625 626 627 628 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 625 def description_field(name, max_lines: nil) @hash["description_field"] = name.to_s @hash["description_max_lines"] = max_lines if max_lines end |
#field(name, **options) ⇒ Object
653 654 655 656 657 658 659 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 653 def field(name, **) f = { "field" => name.to_s } .each do |k, v| f[k.to_s] = v.is_a?(Symbol) ? v.to_s : HashUtils.stringify_deep(v) end @fields << f end |
#image_field(name, alt: nil) ⇒ Object
630 631 632 633 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 630 def image_field(name, alt: nil) @hash["image_field"] = name.to_s @hash["image_alt_field"] = alt.to_s if alt end |
#render_with(partial) ⇒ Object
649 650 651 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 649 def render_with(partial) @hash["render_with"] = partial.to_s end |
#subtitle_field(name, renderer: nil, options: nil) ⇒ Object
619 620 621 622 623 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 619 def subtitle_field(name, renderer: nil, options: nil) @hash["subtitle_field"] = name.to_s @hash["subtitle_renderer"] = renderer.to_s if renderer @hash["subtitle_options"] = HashUtils.stringify_deep() if end |
#title_field(name) ⇒ Object
615 616 617 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 615 def title_field(name) @hash["title_field"] = name.to_s end |
#to_hash ⇒ Object
661 662 663 664 665 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 661 def to_hash result = @hash.dup result["fields"] = @fields unless @fields.empty? result end |