Sha256: 4a8124bbe1360881e79ea205d320da1f1983929d32319cf59e94538a08a4a1b4

Contents?: true

Size: 1.46 KB

Versions: 16

Compression:

Stored size: 1.46 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 ==(other)
      self.class == other.class && name == other.name && super
    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

16 entries across 16 versions & 4 rubygems

Version Path
radiantcms-couchrest_model-0.2.4 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiantcms-couchrest_model-0.2.2 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiantcms-couchrest_model-0.2.1 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiantcms-couchrest_model-0.2 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiantcms-couchrest_model-0.1.9 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiantcms-couchrest_model-0.1.8 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiantcms-couchrest_model-0.1.7 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiantcms-couchrest_model-0.1.6 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiantcms-couchrest_model-0.1.5 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiant-0.8.2 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiant-0.9.0.rc2 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiant-rc-0.9.0 vendor/plugins/haml/lib/sass/tree/attr_node.rb
radiant-0.8.1 vendor/plugins/haml/lib/sass/tree/attr_node.rb
haml-2.0.10 lib/sass/tree/attr_node.rb
haml-2.0.9 lib/sass/tree/attr_node.rb
radiant-0.8.0 vendor/plugins/haml/lib/sass/tree/attr_node.rb