Class: LcpRuby::Dsl::ShowBuilder
- Inherits:
-
Object
- Object
- LcpRuby::Dsl::ShowBuilder
- Includes:
- SourceLocationCapture
- Defined in:
- lib/lcp_ruby/dsl/presenter_builder.rb
Instance Method Summary collapse
- #association_list(title = nil, association:, key: nil, display_template: nil, link: nil, link_through: nil, sort: nil, limit: nil, empty_message: nil, scope: nil, visible_when: nil, disable_when: nil) ⇒ Object
- #copy_url(value) ⇒ Object
- #custom_section(title = nil, partial:, key: nil, visible_when: nil) ⇒ Object
- #description(text) ⇒ Object
- #eager_load(*assocs) ⇒ Object
- #includes(*assocs) ⇒ Object
-
#initialize ⇒ ShowBuilder
constructor
A new instance of ShowBuilder.
- #json_items_list(title = nil, json_field:, key: nil, target_model: nil, columns: nil, empty_message: nil, visible_when: nil, disable_when: nil, &block) ⇒ Object
- #render_with(partial) ⇒ Object
- #section(title = nil, key: nil, columns: 1, description: nil, responsive: nil, visible_when: nil, disable_when: nil, type: nil, association: nil, &block) ⇒ Object
- #to_hash ⇒ Object
Methods included from SourceLocationCapture
Constructor Details
#initialize ⇒ ShowBuilder
Returns a new instance of ShowBuilder.
829 830 831 832 833 834 835 836 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 829 def initialize @layout = [] @includes_list = nil @eager_load_list = nil @description_value = nil @copy_url_value = nil @render_with_value = nil end |
Instance Method Details
#association_list(title = nil, association:, key: nil, display_template: nil, link: nil, link_through: nil, sort: nil, limit: nil, empty_message: nil, scope: nil, visible_when: nil, disable_when: nil) ⇒ Object
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 911 def association_list(title = nil, association:, key: nil, display_template: nil, link: nil, link_through: nil, sort: nil, limit: nil, empty_message: nil, scope: nil, visible_when: nil, disable_when: nil) raise ArgumentError, "association_list requires either a title or key:" if title.nil? && key.nil? entry = { "type" => "association_list", "association" => association.to_s } entry["section"] = title if title entry["section_key"] = key.to_s if key entry["display_template"] = display_template.to_s if display_template entry["link"] = link unless link.nil? entry["link_through"] = link_through.to_s if link_through entry["sort"] = stringify_deep(sort) if sort entry["limit"] = limit if limit entry["empty_message"] = if entry["scope"] = scope.to_s if scope entry["visible_when"] = stringify_deep(visible_when) if visible_when entry["disable_when"] = stringify_deep(disable_when) if disable_when @layout << entry end |
#copy_url(value) ⇒ Object
843 844 845 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 843 def copy_url(value) @copy_url_value = value end |
#custom_section(title = nil, partial:, key: nil, visible_when: nil) ⇒ Object
851 852 853 854 855 856 857 858 859 860 861 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 851 def custom_section(title = nil, partial:, key: nil, visible_when: nil) raise ArgumentError, "custom_section requires either a title or key:" if title.nil? && key.nil? entry = { "type" => "custom", "partial" => partial.to_s } entry["section"] = title if title entry["section_key"] = key.to_s if key entry["visible_when"] = stringify_deep(visible_when) if visible_when @layout << entry end |
#description(text) ⇒ Object
838 839 840 841 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 838 def description(text) @description_value = text @description_source_loc = capture_source_loc end |
#eager_load(*assocs) ⇒ Object
937 938 939 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 937 def eager_load(*assocs) @eager_load_list = assocs.flatten.map { |a| a.is_a?(Hash) ? HashUtils.stringify_deep(a) : a.to_s } end |
#includes(*assocs) ⇒ Object
933 934 935 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 933 def includes(*assocs) @includes_list = assocs.flatten.map { |a| a.is_a?(Hash) ? HashUtils.stringify_deep(a) : a.to_s } end |
#json_items_list(title = nil, json_field:, key: nil, target_model: nil, columns: nil, empty_message: nil, visible_when: nil, disable_when: nil, &block) ⇒ Object
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 885 def json_items_list(title = nil, json_field:, key: nil, target_model: nil, columns: nil, empty_message: nil, visible_when: nil, disable_when: nil, &block) raise ArgumentError, "json_items_list requires either a title or key:" if title.nil? && key.nil? entry = { "type" => "json_items_list", "json_field" => json_field.to_s } entry["section"] = title if title entry["section_key"] = key.to_s if key entry["target_model"] = target_model.to_s if target_model entry["columns"] = columns if columns entry["empty_message"] = if entry["visible_when"] = stringify_deep(visible_when) if visible_when entry["disable_when"] = stringify_deep(disable_when) if disable_when if block builder = NestedSectionBuilder.new builder.instance_eval(&block) if builder.has_sub_sections? entry["sub_sections"] = builder.to_sub_sections else entry["fields"] = builder.to_fields end end @layout << entry end |
#render_with(partial) ⇒ Object
847 848 849 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 847 def render_with(partial) @render_with_value = partial.to_s end |
#section(title = nil, key: nil, columns: 1, description: nil, responsive: nil, visible_when: nil, disable_when: nil, type: nil, association: nil, &block) ⇒ Object
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 863 def section(title = nil, key: nil, columns: 1, description: nil, responsive: nil, visible_when: nil, disable_when: nil, type: nil, association: nil, &block) raise ArgumentError, "section requires either a title or key:" if title.nil? && key.nil? section_hash = { "columns" => columns } section_hash["section"] = title if title section_hash["_label_source_loc"] = capture_source_loc if title section_hash["section_key"] = key.to_s if key section_hash["type"] = type.to_s if type section_hash["association"] = association.to_s if association section_hash["description"] = description if description section_hash["responsive"] = stringify_deep(responsive) if responsive section_hash["visible_when"] = stringify_deep(visible_when) if visible_when section_hash["disable_when"] = stringify_deep(disable_when) if disable_when if block builder = SectionBuilder.new builder.instance_eval(&block) section_hash["fields"] = builder.to_fields end @layout << section_hash end |
#to_hash ⇒ Object
941 942 943 944 945 946 947 948 949 950 951 |
# File 'lib/lcp_ruby/dsl/presenter_builder.rb', line 941 def to_hash hash = {} hash["description"] = @description_value if @description_value hash["_description_source_loc"] = @description_source_loc if @description_source_loc hash["copy_url"] = @copy_url_value unless @copy_url_value.nil? hash["render_with"] = @render_with_value if @render_with_value hash["layout"] = @layout hash["includes"] = @includes_list if @includes_list hash["eager_load"] = @eager_load_list if @eager_load_list hash end |