Sha256: 4db08feaad71abbde4e7571627613b5de888435cf692b0099a7824cb31b3e5bc

Contents?: true

Size: 1.38 KB

Versions: 18

Compression:

Stored size: 1.38 KB

Contents

require 'sass/tree/node'

module Sass::Tree
  class AttrNode < ValueNode
    attr_accessor :name

    def initialize(name, value, style)
      @name = name
      super(value, style)
    end

    def to_s(tabs, parent_name = nil)
      if value[-1] == ?;
        raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump} (This isn't CSS!).", @line)
      end
      real_name = name
      real_name = "#{parent_name}-#{real_name}" if parent_name

      if value.empty? && children.empty?
        raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump}.", @line)
      end

      join_string = case @style
                    when :compact; ' '
                    when :compressed; ''
                    else "\n"
                    end
      spaces = '  ' * (tabs - 1)
      to_return = ''
      if !value.empty?
        to_return << "#{spaces}#{real_name}:#{@style == :compressed ? '' : ' '}#{value};#{join_string}"
      end

      children.each do |kid|
        to_return << "#{kid.to_s(tabs, real_name)}" << join_string
      end

      (@style == :compressed && parent_name) ? to_return : to_return[0...-1]
    end

    private

    def declaration
      ":#{name} #{value}"
    end

    def invalid_child?(child)
      if !child.is_a?(AttrNode) && !child.is_a?(CommentNode)
        "Illegal nesting: Only attributes may be nested beneath attributes."
      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/attr_node.rb
haml-2.0.4 lib/sass/tree/attr_node.rb
haml-2.0.6 lib/sass/tree/attr_node.rb
haml-2.0.3 lib/sass/tree/attr_node.rb
haml-2.0.7 lib/sass/tree/attr_node.rb
haml-2.0.0 lib/sass/tree/attr_node.rb
haml-2.0.2 lib/sass/tree/attr_node.rb
haml-2.0.1 lib/sass/tree/attr_node.rb
haml-2.0.8 lib/sass/tree/attr_node.rb
haml-2.0.5 lib/sass/tree/attr_node.rb
mack-haml-0.8.3.1 lib/gems/haml-2.0.4/lib/sass/tree/attr_node.rb
mack-haml-0.8.3 lib/gems/haml-2.0.4/lib/sass/tree/attr_node.rb
mack-haml-0.8.2 lib/gems/haml-2.0.4/lib/sass/tree/attr_node.rb
radiant-0.6.7 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiant-0.6.8 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiant-0.6.9 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiant-0.7.0 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiant-0.7.1 vendor/plugins/haml/lib/sass/tree/attr_node.rb