Class: StyleScript::ObjectNode
Overview
An object literal.
Constant Summary
Constants inherited from Node
Instance Method Summary collapse
-
#compile_node(o) ⇒ Object
All the mucking about with commas is to make sure that CommentNodes and AssignNodes get interleaved correctly, with no trailing commas or commas affixed to comments.
-
#initialize(properties = []) ⇒ ObjectNode
constructor
A new instance of ObjectNode.
Methods inherited from Node
#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write
Constructor Details
#initialize(properties = []) ⇒ ObjectNode
Returns a new instance of ObjectNode.
720 721 722 |
# File 'lib/style_script/nodes.rb', line 720 def initialize(properties = []) @properties = properties end |
Instance Method Details
#compile_node(o) ⇒ Object
All the mucking about with commas is to make sure that CommentNodes and AssignNodes get interleaved correctly, with no trailing commas or commas affixed to comments. TODO: Extract this and add it to ArrayNode.
727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/style_script/nodes.rb', line 727 def compile_node(o) o[:indent] = idt(1) joins = Hash.new("\n") non_comments = @properties.select {|p| !p.is_a?(CommentNode) } non_comments.each {|p| joins[p] = p == non_comments.last ? "\n" : ",\n" } props = @properties.map { |prop| join = joins[prop] join = '' if prop == @properties.last indent = prop.is_a?(CommentNode) ? '' : idt(1) "#{indent}#{prop.compile(o)}#{join}" }.join('') write("{\n#{props}\n#{idt}}") end |