Class: GridFu::Element
- Inherits:
-
Object
- Object
- GridFu::Element
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/grid_fu/element.rb,
lib/grid_fu/element/nesting.rb,
lib/grid_fu/element/rendering.rb,
lib/grid_fu/element/configuration.rb
Instance Method Summary collapse
- #element_to_html(element, *args) ⇒ Object
-
#initialize(*args, &definition) ⇒ Element
constructor
A new instance of Element.
-
#to_html(*args) ⇒ Object
Translates element to html tag.
Constructor Details
#initialize(*args, &definition) ⇒ Element
Returns a new instance of Element.
5 6 7 8 9 |
# File 'lib/grid_fu/element.rb', line 5 def initialize(*args, &definition) instance_exec(&definition) if block_given? = args. config.merge!() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (protected)
Catches a call to configuration option setter.
Example: body do
{ class: 'test' } # Holds such calls
end
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/grid_fu/element/configuration.rb', line 10 def method_missing(method_name, *args, &block) return super unless method_name.to_s.in?(config.) config[method_name] = args.first || block class_eval do define_method method_name do |value| config[method_name] = value end protected method_name end config[method_name] end |
Instance Method Details
#element_to_html(element, *args) ⇒ Object
25 26 27 |
# File 'lib/grid_fu/element/rendering.rb', line 25 def element_to_html(element, *args) send(element).map { |item| item.to_html(*args) }.join end |
#to_html(*args) ⇒ Object
Translates element to html tag.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/grid_fu/element/rendering.rb', line 4 def to_html(*args) tag, , = ([:tag, :override_html_options, :html_options], *args) raise "Set tag option for #{self.class.name}" if tag.blank? = .merge() = _to_html_args() html = [] html << "<#{tag}" html << " #{html_options}" if .present? html << '>' html << html_content(*args).to_s html << "</#{tag}>" html.join end |