Class: Arbo::Context
Overview
The Arbo::Context class is the frontend for using Arbo.
The simplest example possible:
html = Arbo::Context.new do
h1 "Hello World"
end
html.render_in
The contents of the block are instance eval’d within the Context object. This means that you lose context to the outside world from within the block. To pass local variables into the Context, use the assigns param.
html = Arbo::Context.new({one: 1}) do
h1 "Your number #{one}"
end
html.render_in
Instance Attribute Summary
Attributes inherited from Element
#children, #parent
Instance Method Summary
collapse
Methods inherited from Element
#+, #<<, #add_child, #ancestors, #build, #children?, #content, #content=, #each, #find_first_ancestor, #get_elements_by_class_name, #get_elements_by_tag_name, #html_safe, #parent?, #remove_child, #render_in, #render_in_or_to_s, #tag_name, #to_ary, #to_s, #to_str
#build_tag, included, #insert_tag
Constructor Details
#initialize(assigns = {}, helpers = nil) { ... } ⇒ Context
Initialize a new Arbo::Context
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/arbo/context.rb', line 38
def initialize(assigns = {}, helpers = nil, &block)
assigns = assigns || {}
@_assigns = assigns.symbolize_keys
@_helpers = helpers
@_current_arbo_element_buffer = [self]
super(self)
instance_eval(&block) if block_given?
end
|
Instance Method Details
#arbo_context ⇒ Object
54
55
56
|
# File 'lib/arbo/context.rb', line 54
def arbo_context
self
end
|
#assigns ⇒ Object
58
59
60
|
# File 'lib/arbo/context.rb', line 58
def assigns
@_assigns
end
|
#bytesize ⇒ Object
Also known as:
length
71
72
73
|
# File 'lib/arbo/context.rb', line 71
def bytesize
cached_html.bytesize
end
|
#current_arbo_element ⇒ Object
91
92
93
|
# File 'lib/arbo/context.rb', line 91
def current_arbo_element
@_current_arbo_element_buffer.last
end
|
#helpers ⇒ Object
62
63
64
|
# File 'lib/arbo/context.rb', line 62
def helpers
@_helpers
end
|
#indent_level ⇒ Object
66
67
68
69
|
# File 'lib/arbo/context.rb', line 66
def indent_level
super - 1
end
|
#inspect ⇒ Object
Override default implementation, which would call deprecated Element#to_s
50
51
52
|
# File 'lib/arbo/context.rb', line 50
def inspect
"#<#{self.class}:0x#{(object_id << 1).to_s(16)}"
end
|
#output_buffer ⇒ Object
103
104
105
|
# File 'lib/arbo/context.rb', line 103
def output_buffer
@output_buffer ||= ActiveSupport::SafeBuffer.new
end
|
#respond_to_missing?(method, include_all) ⇒ Boolean
76
77
78
|
# File 'lib/arbo/context.rb', line 76
def respond_to_missing?(method, include_all)
super || cached_html.respond_to?(method, include_all)
end
|
#with_current_arbo_element(tag) ⇒ Object
Also known as:
within
95
96
97
98
99
100
|
# File 'lib/arbo/context.rb', line 95
def with_current_arbo_element(tag)
raise ArgumentError, "Can't be in the context of nil. #{@_current_arbo_element_buffer.inspect}" unless tag
@_current_arbo_element_buffer.push tag
yield
@_current_arbo_element_buffer.pop
end
|