class DisplayFor::Element::Base
Attributes
name[R]
Public Class Methods
new(builder, name, options = {}, &block)
click to toggle source
# File lib/display_for/element/base.rb, line 6 def initialize(builder, name, options = {}, &block) @builder, @name, @options, @block = builder, name, options, block end
Public Instance Methods
content(resource)
click to toggle source
# File lib/display_for/element/base.rb, line 28 def content(resource) if @block @block.call(resource) else nil end end
default_label(resource_classs = nil)
click to toggle source
# File lib/display_for/element/base.rb, line 24 def default_label(resource_classs = nil) @name.to_s.humanize end
html_options()
click to toggle source
# File lib/display_for/element/base.rb, line 10 def html_options @options[:html] || {} end
label(resource_class = nil)
click to toggle source
# File lib/display_for/element/base.rb, line 14 def label(resource_class = nil) return nil if @options[:label] === false name = @options[:label] || @name.to_sym return name unless name.is_a?(Symbol) I18n.t(name, :scope => 'display_for.labels', :default => default_label(resource_class) ) end
link_to(string, resource, html_options = {})
click to toggle source
# File lib/display_for/element/base.rb, line 36 def link_to(string, resource, html_options = {}) url = if @options[:link_to].respond_to?(:call) @options[:link_to].call(resource) elsif @options[:link_to].is_a?(Symbol) @builder.template.send(@options[:link_to], resource) else @builder.namespace + [resource] end return nil unless url html_options[:method] ||= @options[:method] html_options[:confirm] ||= @options[:confirm] html_options[:remote] ||= @options[:remote] html_options[:class] ||= @options[:class] @builder.template.link_to(string, url, html_options) end