Class: ActiveAdmin::Renderer
- Includes:
- ViewHelpers::RendererHelper, Arbre::HTML
- Defined in:
- lib/active_admin/renderer.rb
Direct Known Subclasses
Constant Summary
Constants included from Arbre::HTML
Arbre::HTML::AUTO_BUILD_ELEMENTS, Arbre::HTML::HTML5_ELEMENTS
Instance Attribute Summary collapse
-
#assigns ⇒ Object
Returns the value of attribute assigns.
-
#view ⇒ Object
(also: #helpers)
Returns the value of attribute view.
Instance Method Summary collapse
- #haml(template) ⇒ Object
-
#initialize(view_or_renderer) ⇒ Renderer
constructor
A new instance of Renderer.
- #method_missing(name, *args, &block) ⇒ Object
- #to_html(*args) ⇒ Object
- #to_s(*args) ⇒ Object
Methods included from Arbre::HTML
Methods included from ViewHelpers::RendererHelper
Constructor Details
#initialize(view_or_renderer) ⇒ Renderer
Returns a new instance of Renderer.
12 13 14 15 16 17 18 19 20 |
# File 'lib/active_admin/renderer.rb', line 12 def initialize(view_or_renderer) @view = view_or_renderer.is_a?(Renderer) ? view_or_renderer.view : view_or_renderer if view.respond_to?(:assigns) @assigns = view.assigns.each { |key, value| instance_variable_set("@#{key}", value) } else @assigns = {} end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/active_admin/renderer.rb', line 22 def method_missing(name,*args, &block) if view.respond_to?(name) view.send(name, *args, &block) else super end end |
Instance Attribute Details
#assigns ⇒ Object
Returns the value of attribute assigns.
7 8 9 |
# File 'lib/active_admin/renderer.rb', line 7 def assigns @assigns end |
#view ⇒ Object Also known as: helpers
Returns the value of attribute view.
7 8 9 |
# File 'lib/active_admin/renderer.rb', line 7 def view @view end |
Instance Method Details
#haml(template) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/active_admin/renderer.rb', line 37 def haml(template) begin require 'haml' unless defined?(Haml) rescue LoadError raise LoadError, "Please install the HAML gem to use the HAML method with ActiveAdmin" end # Find the first non whitespace character in the template indent = template.index(/\S/) # Remove the indent if its greater than 0 if indent > 0 template = template.split("\n").collect do |line| line[indent..-1] end.join("\n") end # Render it baby Haml::Engine.new(template).render(self) end |
#to_html(*args) ⇒ Object
30 31 |
# File 'lib/active_admin/renderer.rb', line 30 def to_html(*args) end |
#to_s(*args) ⇒ Object
33 34 35 |
# File 'lib/active_admin/renderer.rb', line 33 def to_s(*args) to_html(*args) end |