Class: Arbre::Context
- Defined in:
- lib/arbre/context.rb
Overview
Root of any Arbre construct. Each elements in any Arbre construct will have a reference to this context, which provides information like what the current arbre element is.
Instance Method Summary collapse
-
#assigns ⇒ Object
Attributes.
-
#current_element ⇒ Object
Element & flow stack.
- #current_flow ⇒ Object
- #helpers ⇒ Object
- #indent_level ⇒ Object
-
#initialize(assigns = nil, helpers = nil, &block) ⇒ Context
constructor
Initialize a new Arbre::Context.
- #parent= ⇒ Object
-
#replace_current_flow(flow) ⇒ Object
Replaces the current flow.
- #with_current(element: nil, flow: :append) ⇒ Object
Methods inherited from Container
Methods inherited from Element
#+, #<<, #ancestors, #arbre_context, #build!, #children, #content, #content=, #descendants, #empty?, #has_children?, #inspect, #orphan?, #parent, #remove!, #respond_to?, #to_html, #to_s
Methods included from Html::Querying
#child_tags, #descendant_tags, #find, #find_by_classes, #find_by_id, #find_by_tag, #find_by_tag_and_classes, #find_first
Methods included from Element::Building
#append_within, #append_within?, #build, included, #insert, #insert_child, #prepend_within, #prepend_within?, #temporary
Constructor Details
#initialize(assigns = nil, helpers = nil, &block) ⇒ Context
Initialize a new Arbre::Context. Any passed block will be instance-exec’d.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/arbre/context.rb', line 23 def initialize(assigns = nil, helpers = nil, &block) @_assigns = (assigns || {}).symbolize_keys @_helpers = helpers @_element_stack = [ self ] @_flow_stack = [ :append ] # Pass ourselves as the arbre context to the element. super self instance_exec &block if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Arbre::Element
Instance Method Details
#assigns ⇒ Object
Attributes
38 39 40 |
# File 'lib/arbre/context.rb', line 38 def assigns @_assigns end |
#current_element ⇒ Object
Element & flow stack
57 58 59 |
# File 'lib/arbre/context.rb', line 57 def current_element @_element_stack.last end |
#current_flow ⇒ Object
61 62 63 |
# File 'lib/arbre/context.rb', line 61 def current_flow @_flow_stack.last end |
#helpers ⇒ Object
42 43 44 |
# File 'lib/arbre/context.rb', line 42 def helpers @_helpers end |
#indent_level ⇒ Object
50 51 52 |
# File 'lib/arbre/context.rb', line 50 def indent_level -1 end |
#parent= ⇒ Object
46 47 48 |
# File 'lib/arbre/context.rb', line 46 def parent=(*) raise NotImplementedError, "Arbre::Context cannot have a parent" end |
#replace_current_flow(flow) ⇒ Object
Replaces the current flow. For internal usie!
77 78 79 80 |
# File 'lib/arbre/context.rb', line 77 def replace_current_flow(flow) @_flow_stack.pop @_flow_stack.push flow end |
#with_current(element: nil, flow: :append) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/arbre/context.rb', line 65 def with_current(element: nil, flow: :append) raise ArgumentError, "can't be in the context of nil" unless element @_element_stack.push element @_flow_stack.push flow yield if block_given? ensure @_flow_stack.pop @_element_stack.pop end |