Module: Arbre::Builder
- Included in:
- ActiveAdmin::Renderer, HTML::Element
- Defined in:
- lib/active_admin/arbre/builder.rb
Overview
Include this module in any context to start building html.
assigns = {}
include Arbre::Builder
span("foo").to_s #=> "<span>foo</span>
When you include the module, you are required to setup 2 variables:
-
assigns: This is a hash that includes local variables
-
helpers: This is an object that provides helper methods to all
objects within the context.
Defined Under Namespace
Modules: BuilderMethods
Instance Method Summary collapse
-
#current_dom_context ⇒ Arbre::Element
Retrieve the current DOM context.
- #helpers ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
Implements the method lookup chain.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Implements the method lookup chain. When you call a method that doesn’t exist, we:
1. Try to call the method on the current DOM context
2. Return an assigned variable of the same name
3. Call the method on the helper object
4. Call super
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_admin/arbre/builder.rb', line 39 def method_missing(name, *args, &block) if current_dom_context.respond_to?(name) current_dom_context.send name, *args, &block elsif assigns && assigns.has_key?(name) assigns[name] elsif helpers.respond_to?(name) helpers.send(name, *args, &block) else super end end |
Instance Method Details
#current_dom_context ⇒ Arbre::Element
Retrieve the current DOM context.
If no ‘@current_dom_element` has been set, this method will setup the initial context.
22 23 24 25 |
# File 'lib/active_admin/arbre/builder.rb', line 22 def current_dom_context @__current_dom_element__ ||= Arbre::Context.new(assigns, helpers) @__current_dom_element__.current_dom_context end |
#helpers ⇒ Object
27 28 29 |
# File 'lib/active_admin/arbre/builder.rb', line 27 def helpers @_helpers end |