Class: SimpleDataPresentation::SimpleDataList::Base
- Inherits:
-
Object
- Object
- SimpleDataPresentation::SimpleDataList::Base
- Defined in:
- lib/simple_data_presentation/simple_data_list/base.rb
Instance Method Summary collapse
-
#initialize(context, resource, options = {}, &content_block) ⇒ Base
constructor
A new instance of Base.
- #item(*args, &block) ⇒ Object
- #render! ⇒ Object
- #title(*args, &block) ⇒ Object
- #value(*args, &block) ⇒ Object
Constructor Details
#initialize(context, resource, options = {}, &content_block) ⇒ Base
Returns a new instance of Base.
2 3 4 5 6 7 8 9 10 |
# File 'lib/simple_data_presentation/simple_data_list/base.rb', line 2 def initialize(context, resource, = {}, &content_block) @context = context @resource = resource @options = @content_block = content_block @resource_class = @options.delete(:resource_class) || @resource.class @html_options = SimpleDataPresentation::HtmlOptions.new(@options.delete(:html) || {}) @html_options[:class] = "dl-horizontal" end |
Instance Method Details
#item(*args, &block) ⇒ Object
12 13 14 |
# File 'lib/simple_data_presentation/simple_data_list/base.rb', line 12 def item(*args, &block) self.title(*args.clone) + self.value(*args.clone, &block) end |
#render! ⇒ Object
54 55 56 |
# File 'lib/simple_data_presentation/simple_data_list/base.rb', line 54 def render! @context.raw @context.content_tag :dl, @context.capture(self, &@content_block), @html_options end |
#title(*args, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/simple_data_presentation/simple_data_list/base.rb', line 16 def title(*args, &block) = args. content = if block.present? @context.capture(@resource_class, &block) else if [:label].is_a?(Symbol) @resource_class.human_attribute_name [:label] elsif ![:label].nil? [:label] elsif args.any? @resource_class.human_attribute_name args.join("_").to_sym end end @context.content_tag :dt, content, SimpleDataPresentation::HtmlOptions.new([:html] || {}).merge([:label_html] || {}) end |
#value(*args, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/simple_data_presentation/simple_data_list/base.rb', line 32 def value(*args, &block) = args. if block.present? content = @context.capture @resource, &block else if (value_option = [:value]).present? content = value_option.respond_to?(:call) ? value_option.call(@resource) : value_option else content = value_for_method_chain *args end as_formatter = [:as] if as_formatter.present? as_formatter = @context.method(as_formatter).to_proc if as_formatter.is_a?(Symbol) content = case as_formatter.arity when 1; as_formatter.call content when 2; as_formatter.call @resource, content end end end @context.content_tag :dd, content, SimpleDataPresentation::HtmlOptions.new([:html] || {}).merge([:value_html] || {}) end |