Class: Manageable::Helpers::AttributesBuilder
- Inherits:
-
Object
- Object
- Manageable::Helpers::AttributesBuilder
- Defined in:
- lib/manageable/helpers/attributes_builder.rb
Instance Attribute Summary collapse
-
#record ⇒ Object
(also: #object)
readonly
Only for testing purposes.
-
#template ⇒ Object
readonly
Only for testing purposes.
Instance Method Summary collapse
- #attribute(*args, &block) ⇒ Object
- #attributes(*args, &block) ⇒ Object
-
#initialize(record, template) ⇒ AttributesBuilder
constructor
A new instance of AttributesBuilder.
Constructor Details
#initialize(record, template) ⇒ AttributesBuilder
Returns a new instance of AttributesBuilder.
12 13 14 |
# File 'lib/manageable/helpers/attributes_builder.rb', line 12 def initialize(record, template) @record, @template = record, template end |
Instance Attribute Details
#record ⇒ Object (readonly) Also known as: object
Only for testing purposes
7 8 9 |
# File 'lib/manageable/helpers/attributes_builder.rb', line 7 def record @record end |
#template ⇒ Object (readonly)
Only for testing purposes
7 8 9 |
# File 'lib/manageable/helpers/attributes_builder.rb', line 7 def template @template end |
Instance Method Details
#attribute(*args, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/manageable/helpers/attributes_builder.rb', line 42 def attribute(*args, &block) = args. [:html] ||= {} method = args.shift html_label_class = [ "label", [:html][:label_class] ].compact.join(" ") html_value_class = [ "value", [:html][:value_class] ].compact.join(" ") html_class = [ "attribute", [:html][:class] ] position = .delete(:position) html_class << "column_left" if position == :left html_class << "column_right" if position == :right html_class = html_class.compact.join(" ") label = .key?(:label) ? [:label] : label_for_attribute(method) unless block_given? value = if .key?(:value) case [:value] when Symbol attribute_value = value_of_attribute(method) case attribute_value when Hash attribute_value[[:value]] else attribute_value.send([:value]) end else [:value] end else value_of_attribute(method) end value = case [:format] when false value when nil format_attribute_value(value) else template.send([:format], value) end if value.present? or [:display_empty] output = template.tag(:li, {:class => html_class}, true) output << template.content_tag(:span, label, :class => html_label_class) output << template.content_tag(:span, value, :class => html_value_class) output.safe_concat("</li>") end else output = template.tag(:li, {:class => html_class}, true) output << template.content_tag(:span, label, :class => html_label_class) output << template.tag(:span, {:class => html_value_class}, true) output << template.capture(&block) output.safe_concat("</span>") output.safe_concat("</li>") end end |
#attributes(*args, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/manageable/helpers/attributes_builder.rb', line 16 def attributes(*args, &block) = args. [:html] ||= {} if args.first and args.first.is_a? String [:name] = args.shift end if [:for].blank? attributes_for(record, args, , &block) else for_value = if [:for].is_a? Symbol record.send([:for]) else [:for] end [*for_value].map do |value| = .clone [:html][:class] = [ [:html][:class], value.class.to_s.underscore ].compact.join(" ") attributes_for(value, args, , &block) end.join.html_safe end end |