Class: Plate::RichNode
- Inherits:
-
Struct
- Object
- Struct
- Plate::RichNode
- Includes:
- Inspector
- Defined in:
- lib/plate/nodes.rb,
lib/plate/compiler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#scripts ⇒ Object
Returns the value of attribute scripts.
-
#styles ⇒ Object
Returns the value of attribute styles.
Instance Method Summary collapse
- #compile_body(compiler, parent) ⇒ Object
-
#initialize(body) ⇒ RichNode
constructor
A new instance of RichNode.
- #parent_repeat? ⇒ Boolean
- #repeat? ⇒ Boolean
Methods included from Inspector
Constructor Details
#initialize(body) ⇒ RichNode
Returns a new instance of RichNode.
35 36 37 38 39 |
# File 'lib/plate/nodes.rb', line 35 def initialize(body) self.styles = [] self.scripts = {} self.body = body end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
32 33 34 |
# File 'lib/plate/nodes.rb', line 32 def body @body end |
#parent ⇒ Object
Returns the value of attribute parent.
136 137 138 |
# File 'lib/plate/compiler.rb', line 136 def parent @parent end |
#scripts ⇒ Object
Returns the value of attribute scripts
32 33 34 |
# File 'lib/plate/nodes.rb', line 32 def scripts @scripts end |
#styles ⇒ Object
Returns the value of attribute styles
32 33 34 |
# File 'lib/plate/nodes.rb', line 32 def styles @styles end |
Instance Method Details
#compile_body(compiler, parent) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/plate/compiler.rb', line 146 def compile_body(compiler, parent) self.parent = parent compiler.repeating = repeat? content = body.compile(compiler, self) style = styles.empty? ? '' : " style=\"#{styles.join(';')}\"" script = if scripts.empty? '' else scripts.map do |k, v| " v-#{k}=\"#{v.join(',')}\"" end.join('') end compiler.repeating = parent_repeat? [content, style, script] end |
#parent_repeat? ⇒ Boolean
138 139 140 |
# File 'lib/plate/compiler.rb', line 138 def parent_repeat? parent && parent.repeat? end |
#repeat? ⇒ Boolean
142 143 144 |
# File 'lib/plate/compiler.rb', line 142 def repeat? parent_repeat? || !scripts['repeat'].nil? end |