Class: Props::BaseWithExtensions
- Inherits:
-
Base
- Object
- Base
- Props::BaseWithExtensions
show all
- Defined in:
- lib/props_template/base_with_extensions.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#deferred! ⇒ Object
-
#format_key(key) ⇒ Object
-
#fragments! ⇒ Object
-
#handle_collection_item(collection, item, index, options) ⇒ Object
-
#handle_set_block(key, options) ⇒ Object
-
#initialize(builder, context = nil, options = {}) ⇒ BaseWithExtensions
constructor
A new instance of BaseWithExtensions.
-
#refine_all_item_options(all_options) ⇒ Object
-
#refine_item_options(item, options) ⇒ Object
-
#scoped_state {|@stream, @em.deferred, @em.fragments| ... } ⇒ Object
-
#set!(key, options = {}, &block) ⇒ Object
-
#set_block_content!(options = {}) ⇒ Object
-
#traveled_path! ⇒ Object
Methods inherited from Base
#array!, #handle_collection, #result!
Constructor Details
#initialize(builder, context = nil, options = {}) ⇒ BaseWithExtensions
Returns a new instance of BaseWithExtensions.
5
6
7
8
9
10
11
|
# File 'lib/props_template/base_with_extensions.rb', line 5
def initialize(builder, context = nil, options = {})
@context = context
@builder = builder
@em = ExtensionManager.new(self)
@traveled_path = []
super()
end
|
Instance Attribute Details
#builder ⇒ Object
Returns the value of attribute builder.
3
4
5
|
# File 'lib/props_template/base_with_extensions.rb', line 3
def builder
@builder
end
|
#context ⇒ Object
Returns the value of attribute context.
3
4
5
|
# File 'lib/props_template/base_with_extensions.rb', line 3
def context
@context
end
|
#deferred ⇒ Object
Returns the value of attribute deferred.
3
4
5
|
# File 'lib/props_template/base_with_extensions.rb', line 3
def deferred
@deferred
end
|
#fragments ⇒ Object
Returns the value of attribute fragments.
3
4
5
|
# File 'lib/props_template/base_with_extensions.rb', line 3
def fragments
@fragments
end
|
#stream ⇒ Object
Returns the value of attribute stream.
3
4
5
|
# File 'lib/props_template/base_with_extensions.rb', line 3
def stream
@stream
end
|
#traveled_path ⇒ Object
Returns the value of attribute traveled_path.
3
4
5
|
# File 'lib/props_template/base_with_extensions.rb', line 3
def traveled_path
@traveled_path
end
|
Instance Method Details
#deferred! ⇒ Object
13
14
15
|
# File 'lib/props_template/base_with_extensions.rb', line 13
def deferred!
@em.deferred
end
|
45
46
47
|
# File 'lib/props_template/base_with_extensions.rb', line 45
def format_key(key)
key.to_s
end
|
#fragments! ⇒ Object
17
18
19
|
# File 'lib/props_template/base_with_extensions.rb', line 17
def fragments!
@em.fragments
end
|
#handle_collection_item(collection, item, index, options) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/props_template/base_with_extensions.rb', line 71
def handle_collection_item(collection, item, index, options)
if !options[:key]
@traveled_path.push(index)
else
id, val = options[:key]
if id.nil?
@traveled_path.push(index)
else
@traveled_path.push("#{id}=#{val}")
end
end
super
@traveled_path.pop
nil
end
|
#handle_set_block(key, options) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/props_template/base_with_extensions.rb', line 57
def handle_set_block(key, options)
@traveled_path.push(key)
n = 1
if (suffix = options[:path_suffix])
n += suffix.length
@traveled_path.push(suffix)
end
super
@traveled_path.pop(n)
nil
end
|
#refine_all_item_options(all_options) ⇒ Object
90
91
92
|
# File 'lib/props_template/base_with_extensions.rb', line 90
def refine_all_item_options(all_options)
@em.refine_all_item_options(all_options)
end
|
#refine_item_options(item, options) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/props_template/base_with_extensions.rb', line 94
def refine_item_options(item, options)
return options if options.empty?
if (key = options[:key])
val = if item.respond_to? key
item.send(key)
elsif item.is_a? Hash
item[key] || item[key.to_sym]
end
options[:key] = [options[:key], val]
end
@em.refine_options(options, item)
end
|
#scoped_state {|@stream, @em.deferred, @em.fragments| ... } ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/props_template/base_with_extensions.rb', line 33
def scoped_state
prev_state = [@stream, @em.deferred, @em.fragments]
@em = ExtensionManager.new(self)
prev_scope = @scope
@scope = nil
yield @stream, @em.deferred, @em.fragments
@scope = prev_scope
@em = ExtensionManager.new(self, prev_state[1], prev_state[2])
end
|
#set!(key, options = {}, &block) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/props_template/base_with_extensions.rb', line 49
def set!(key, options = {}, &block)
if block
options = @em.refine_options(options)
end
super(key, options, &block)
end
|
#set_block_content!(options = {}) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/props_template/base_with_extensions.rb', line 25
def set_block_content!(options = {})
return super if !@em.has_extensions(options)
@em.handle(options) do
yield
end
end
|
#traveled_path! ⇒ Object
21
22
23
|
# File 'lib/props_template/base_with_extensions.rb', line 21
def traveled_path!
@traveled_path.join(".")
end
|