Class: SparkEngine::BlockHelper
- Inherits:
-
Object
- Object
- SparkEngine::BlockHelper
show all
- Defined in:
- lib/spark_engine/helpers/block_helper.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/spark_engine/helpers/block_helper.rb', line 76
def method_missing(method, *args, &block)
if helper.respond_to?(method)
self.class_eval "def #{method}(*args, &block); helper.send('#{method}', *args, &block); end"
self.send(method, *args, &block)
else
super
end
end
|
Class Attribute Details
.current_helper ⇒ Object
Returns the value of attribute current_helper.
51
52
53
|
# File 'lib/spark_engine/helpers/block_helper.rb', line 51
def current_helper
@current_helper
end
|
.current_parent_block_helper ⇒ Object
Returns the value of attribute current_parent_block_helper.
51
52
53
|
# File 'lib/spark_engine/helpers/block_helper.rb', line 51
def current_parent_block_helper
@current_parent_block_helper
end
|
Class Method Details
.inherited(klass) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/spark_engine/helpers/block_helper.rb', line 10
def inherited(klass)
method_name = klass.name.split('::').last.underscore
klass.parent.class_eval %(
def #{method_name}(*args, &block)
# Get the current helper object which has all the normal helper methods
if self.is_a?(SparkEngine::BlockHelper)
top_level_helper = self.helper
parent_block_helper = self
else
top_level_helper = self
parent_block_helper = nil
end
# We need to save the current helper and parent block helper in the class so that
# it's visible to the renderer's 'initialize' method...
#{klass.name}.current_helper = top_level_helper
#{klass.name}.current_parent_block_helper = parent_block_helper
renderer = #{klass.name}.new(*args)
# ...then set them anyway on the renderer so that renderer methods can use it
renderer.send(:helper=, top_level_helper)
renderer.send(:parent=, parent_block_helper)
body = block ? capture(renderer, &block) : nil
if processed_body = renderer.display(body)
return processed_body
end
end
)
end
|
Instance Method Details
#display(body) ⇒ Object
55
56
57
|
# File 'lib/spark_engine/helpers/block_helper.rb', line 55
def display(body)
body
end
|
#respond_to?(method, include_all = false) ⇒ Boolean
59
60
61
|
# File 'lib/spark_engine/helpers/block_helper.rb', line 59
def respond_to?(method, include_all = false)
super or helper.respond_to?(method, include_all)
end
|