class IndexFor::Builder
Attributes
html_options[RW]
object[RW]
template[RW]
Public Class Methods
new(object, html_options, template)
click to toggle source
# File lib/index_for/builder.rb, line 10 def initialize object, html_options, template @object, @html_options, @template = object, html_options, template end
Public Instance Methods
actions(*action_names, █)
click to toggle source
# File lib/index_for/builder.rb, line 44 def actions *action_names, █ end
association(attribute_name, options = {})
click to toggle source
# File lib/index_for/builder.rb, line 15 def association attribute_name, options = {}, &block attribute attribute_name, options, &block end
attribute(attribute_name, options = {})
click to toggle source
# File lib/index_for/builder.rb, line 14 def attribute attribute_name, options = {}, █ end
attributes(*attribute_names)
click to toggle source
# File lib/index_for/builder.rb, line 19 def attributes *attribute_names options = attribute_names.extract_options! attribute_names.map do |attribute_name| attribute attribute_name, options end.join.html_safe end
fields_for(attribute_name, options = {})
click to toggle source
# File lib/index_for/builder.rb, line 27 def fields_for attribute_name, options = {}, &block object = @object html_options = @html_options @object = @object.send(attribute_name) fields_for = @html_options[:fields_for] ? @html_options[:fields_for].clone : [] fields_for.push attribute_name @html_options = html_options.merge(options).merge(fields_for: fields_for) result = @template.capture(self, &block) @object = object @html_options = html_options result end
Private Instance Methods
apply_html_options(type, options = {})
click to toggle source
# File lib/index_for/builder.rb, line 55 def apply_html_options type, options = {} type_class = IndexFor.try(:"#{type}_class") type_html_options = {} type_html_options.merge!(html_options[:"#{type}_html"]) if html_options[:"#{type}_html"] type_html_options.merge!(options[:html]) if options[:html] append_class type_html_options, type_class type_html_options end
attribute_class_name(attribute_name)
click to toggle source
# File lib/index_for/builder.rb, line 67 def attribute_class_name attribute_name class_name = ["attr", *@html_options[:fields_for], attribute_name] class_name.compact! class_name.join("_").to_sym end
blank_content(options)
click to toggle source
# File lib/index_for/builder.rb, line 116 def blank_content options options[:if_blank] || translate(:blank, :default => "Not specified") end
collection_content(collection, options)
click to toggle source
# File lib/index_for/builder.rb, line 120 def collection_content collection, options collection_tag = options[:collection_tag] || IndexFor.collection_tag collection_column_tag = options[:collection_column_tag] || IndexFor.collection_column_tag @template.content_tag collection_tag do collection.map do |content| @template.content_tag collection_column_tag, content end.join.html_safe end end
format_content(content, options = {})
click to toggle source
# File lib/index_for/builder.rb, line 88 def format_content content, options = {} # We need to convert content to_a because when dealing with ActiveRecord # Array proxies, the follow statement Array# === content return false content = content.to_ary if content.respond_to?(:to_ary) formatter = options[:format] && IndexFor.formatters[options[:format]] return @template.instance_exec(content, @object, &formatter) if formatter case content when String content.empty? ? blank_content(options) : content when TrueClass translate :yes, :default => "Yes" when FalseClass translate :no, :default => "No" when NilClass blank_content(options) when Date, Time, DateTime I18n.l content, :format => options[:format] || IndexFor.i18n_format when Array, Hash content.empty? ? blank_content(options) : collection_content(content, options) when Proc @template.capture(@object, &content) else content.to_s end end
wrap_attribute_with(type, attribute, options = {})
click to toggle source
# File lib/index_for/builder.rb, line 73 def wrap_attribute_with type, attribute, options = {}, &block type_tag, type_html_options = apply_html type, options if block content = block else content = attribute_value attribute, options append_class type_html_options, IndexFor.blank_content_class if content.blank? end @template.content_tag type_tag, type_html_options do format_content(content, options) end end