Class: StyleScript::LiteralNode

Inherits:
Node
  • Object
show all
Defined in:
lib/style_script/nodes.rb

Overview

Literals are static values that can be passed through directly into JavaScript without translation, eg.: strings, numbers, true, false, null…

Constant Summary collapse

STATEMENTS =

Values of a literal node that much be treated as a statement – no sense returning or assigning them.

['break', 'continue']

Constants inherited from Node

Node::TAB

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#children, children, #compile, #compile_closure, #contains?, #idt, statement, statement_only, top_sensitive, #top_sensitive?, #unwrap, #write

Constructor Details

#initialize(value) ⇒ LiteralNode

Returns a new instance of LiteralNode.



197
198
199
# File 'lib/style_script/nodes.rb', line 197

def initialize(value)
  @value = value
end

Class Method Details

.wrap(string) ⇒ Object

Wrap up a compiler-generated string as a LiteralNode.



193
194
195
# File 'lib/style_script/nodes.rb', line 193

def self.wrap(string)
  self.new(Value.new(string))
end

Instance Method Details

#compile_node(o) ⇒ Object



206
207
208
209
210
# File 'lib/style_script/nodes.rb', line 206

def compile_node(o)
  indent = statement? ? idt : ''
  ending = statement? ? ';' : ''
  "#{indent}#{@value}#{ending}"
end

#statement?Boolean Also known as: statement_only?

Returns:

  • (Boolean)


201
202
203
# File 'lib/style_script/nodes.rb', line 201

def statement?
  STATEMENTS.include?(@value.to_s)
end