Class: Props::BaseWithExtensions
- Inherits:
-
Base
- Object
- Base
- Props::BaseWithExtensions
show all
- Defined in:
- lib/props_template/base_with_extensions.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#item_context
Instance Method Summary
collapse
-
#deferred! ⇒ Object
-
#disable_deferments! ⇒ Object
-
#format_key(key) ⇒ Object
-
#fragments! ⇒ Object
-
#handle_collection(collection, options) ⇒ 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.
-
#scoped_state {|@stream, @em.deferred, @em.fragments| ... } ⇒ Object
-
#set!(key, options = {}, &block) ⇒ Object
-
#set_content!(options = {}) ⇒ Object
-
#traveled_path! ⇒ Object
Methods inherited from Base
#array!, #child!, #extract!, #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
17
18
19
|
# File 'lib/props_template/base_with_extensions.rb', line 17
def deferred!
@em.deferred
end
|
#disable_deferments! ⇒ Object
13
14
15
|
# File 'lib/props_template/base_with_extensions.rb', line 13
def disable_deferments!
@em.disable_deferments
end
|
49
50
51
|
# File 'lib/props_template/base_with_extensions.rb', line 49
def format_key(key)
key.to_s
end
|
#fragments! ⇒ Object
21
22
23
|
# File 'lib/props_template/base_with_extensions.rb', line 21
def fragments!
@em.fragments
end
|
#handle_collection(collection, options) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/props_template/base_with_extensions.rb', line 77
def handle_collection(collection, options)
if options[:cache]
key, rest = [*options[:cache]]
if ::Proc === key
cache_keys = collection.map do |item|
key.call(item)
end
@em.load_cache(cache_keys, rest || {})
end
end
super
end
|
#handle_collection_item(collection, item, index, options) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/props_template/base_with_extensions.rb', line 92
def handle_collection_item(collection, item, index, options)
if !options[:key]
@traveled_path.push(index)
else
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
end
if key.nil?
@traveled_path.push(index)
else
@traveled_path.push("#{key}=#{val}")
end
end
super
@traveled_path.pop
nil
end
|
#handle_set_block(key, options) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/props_template/base_with_extensions.rb', line 62
def handle_set_block(key, options)
n = 1
if (suffix = options[:path_suffix])
n += suffix.length
@traveled_path.push(suffix)
else
@traveled_path.push(key)
end
super
@traveled_path.pop(n)
nil
end
|
#scoped_state {|@stream, @em.deferred, @em.fragments| ... } ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/props_template/base_with_extensions.rb', line 37
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
53
54
55
56
57
58
59
60
|
# File 'lib/props_template/base_with_extensions.rb', line 53
def set!(key, options = {}, &block)
if !block && options.is_a?(Props::Options)
options.valid_for_set!
super {}
else
super
end
end
|
#set_content!(options = {}) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/props_template/base_with_extensions.rb', line 29
def set_content!(options = {})
return super if !@em.has_extensions(options)
@em.handle(options, item_context) do
yield
end
end
|
#traveled_path! ⇒ Object
25
26
27
|
# File 'lib/props_template/base_with_extensions.rb', line 25
def traveled_path!
@traveled_path.join(".")
end
|