Class: DisplayFor::Element::Base
- Inherits:
-
Object
- Object
- DisplayFor::Element::Base
- Defined in:
- lib/display_for/element/base.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #content(resource) ⇒ Object
- #default_label(resource_classs = nil) ⇒ Object
- #html_options ⇒ Object
-
#initialize(builder, name, options = {}, &block) ⇒ Base
constructor
A new instance of Base.
- #label(resource_class = nil) ⇒ Object
- #link_to(string, resource, html_options = {}) ⇒ Object
Constructor Details
#initialize(builder, name, options = {}, &block) ⇒ Base
Returns a new instance of Base.
6 7 8 |
# File 'lib/display_for/element/base.rb', line 6 def initialize(builder, name, = {}, &block) @builder, @name, @options, @block = builder, name, , block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/display_for/element/base.rb', line 4 def name @name end |
Instance Method Details
#content(resource) ⇒ Object
28 29 30 31 32 33 34 |
# 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) ⇒ Object
24 25 26 |
# File 'lib/display_for/element/base.rb', line 24 def default_label(resource_classs = nil) @name.to_s.humanize end |
#html_options ⇒ Object
10 11 12 |
# File 'lib/display_for/element/base.rb', line 10 def @options[:html] || {} end |
#label(resource_class = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# 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 = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/display_for/element/base.rb', line 36 def link_to(string, resource, = {}) 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 [:method] ||= @options[:method] [:confirm] ||= @options[:confirm] [:remote] ||= @options[:remote] [:class] ||= @options[:class] @builder.template.link_to(string, url, ) end |