Class: Plate::RichNode

Inherits:
Struct
  • Object
show all
Includes:
Inspector
Defined in:
lib/plate/nodes.rb,
lib/plate/compiler.rb

Direct Known Subclasses

ClassNode, DivNode, HeaderNode, ParagraphNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspector

#inspect_with

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

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



32
33
34
# File 'lib/plate/nodes.rb', line 32

def body
  @body
end

#parentObject

Returns the value of attribute parent.



143
144
145
# File 'lib/plate/compiler.rb', line 143

def parent
  @parent
end

#scriptsObject

Returns the value of attribute scripts

Returns:

  • (Object)

    the current value of scripts



32
33
34
# File 'lib/plate/nodes.rb', line 32

def scripts
  @scripts
end

#stylesObject

Returns the value of attribute styles

Returns:

  • (Object)

    the current value of styles



32
33
34
# File 'lib/plate/nodes.rb', line 32

def styles
  @styles
end

Instance Method Details

#compile_body(compiler, parent) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/plate/compiler.rb', line 153

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

Returns:

  • (Boolean)


145
146
147
# File 'lib/plate/compiler.rb', line 145

def parent_repeat?
  parent && parent.repeat?
end

#repeat?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/plate/compiler.rb', line 149

def repeat?
  parent_repeat? || !scripts['repeat'].nil?
end