Sha256: 0a39b9b024acd41da9d78670b73b19e5728612a38244272e0f1b7aba542bd5fa

Contents?: true

Size: 1.01 KB

Versions: 18

Compression:

Stored size: 1.01 KB

Contents

module Sass
  module Tree
    class Node
      attr_accessor :children
      attr_accessor :line
      attr_accessor :filename

      def initialize(style)
        @style = style
        @children = []
      end

      def <<(child)
        if msg = invalid_child?(child)
          raise Sass::SyntaxError.new(msg, child.line)
        end
        @children << child
      end

      def to_s
        result = String.new
        children.each do |child|
          if child.is_a? AttrNode
            raise SyntaxError.new('Attributes aren\'t allowed at the root of a document.', child.line)
          else
            result << "#{child.to_s(1)}" + (@style == :compressed ? '' : "\n")
          end
        end
        @style == :compressed ? result+"\n" : result[0...-1]
      end

      private

      # This method should be overridden by subclasses to return an error message
      # if the given child node is invalid,
      # and false or nil otherwise.
      def invalid_child?(child)
        false
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
radiant-0.7.2 vendor/plugins/haml/lib/sass/tree/node.rb
haml-2.0.0 lib/sass/tree/node.rb
haml-2.0.1 lib/sass/tree/node.rb
haml-2.0.2 lib/sass/tree/node.rb
haml-2.0.4 lib/sass/tree/node.rb
haml-2.0.8 lib/sass/tree/node.rb
haml-2.0.7 lib/sass/tree/node.rb
haml-2.0.6 lib/sass/tree/node.rb
haml-2.0.5 lib/sass/tree/node.rb
haml-2.0.3 lib/sass/tree/node.rb
mack-haml-0.8.3 lib/gems/haml-2.0.4/lib/sass/tree/node.rb
mack-haml-0.8.2 lib/gems/haml-2.0.4/lib/sass/tree/node.rb
mack-haml-0.8.3.1 lib/gems/haml-2.0.4/lib/sass/tree/node.rb
radiant-0.6.7 vendor/plugins/haml/lib/sass/tree/node.rb
radiant-0.6.9 vendor/plugins/haml/lib/sass/tree/node.rb
radiant-0.6.8 vendor/plugins/haml/lib/sass/tree/node.rb
radiant-0.7.0 vendor/plugins/haml/lib/sass/tree/node.rb
radiant-0.7.1 vendor/plugins/haml/lib/sass/tree/node.rb