Class: Attrtastic::SemanticAttributesBuilder
- Inherits:
-
Object
- Object
- Attrtastic::SemanticAttributesBuilder
- Defined in:
- lib/attrtastic/semantic_attributes_builder.rb
Instance Attribute Summary (collapse)
-
- (Object) record
readonly
Only for testing purposes.
-
- (Object) template
readonly
Only for testing purposes.
Instance Method Summary (collapse)
-
- (Object) attribute(*args, &block)
Creates list entry for single record attribute.
-
- (Object) attributes(*args, &block)
Creates block of attributes with optional header.
-
- (SemanticAttributesBuilder) initialize(record, template)
constructor
A new instance of SemanticAttributesBuilder.
Constructor Details
- (SemanticAttributesBuilder) initialize(record, template)
A new instance of SemanticAttributesBuilder
9 10 11 |
# File 'lib/attrtastic/semantic_attributes_builder.rb', line 9 def initialize(record, template) @record, @template = record, template end |
Instance Attribute Details
- (Object) record (readonly)
Only for testing purposes
7 8 9 |
# File 'lib/attrtastic/semantic_attributes_builder.rb', line 7 def record @record end |
- (Object) template (readonly)
Only for testing purposes
7 8 9 |
# File 'lib/attrtastic/semantic_attributes_builder.rb', line 7 def template @template end |
Instance Method Details
- (Object) attribute(method, options = {}) - (Object) attribute(method, options = {}) { ... } - (Object) attribute(options = {}) { ... }
Creates list entry for single record attribute
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/attrtastic/semantic_attributes_builder.rb', line 255 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] ].compact.join(" ") label = .key?(:label) ? [:label] : label_for_attribute(method) unless block_given? value = .key?(:value) ? [:value] : value_of_attribute(method) 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 |
- (Object) attributes(options = {}) { ... } - (Object) attributes(header, options = {}) {|builder| ... } - (Object) attributes(*symbols, options = {}) - (Object) attributes(header, *symbols, options = {})
Creates block of attributes with optional header. Attributes are surrounded with ordered list.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/attrtastic/semantic_attributes_builder.rb', line 174 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 end end |