2006-12-04 08:41:09 +00:00
|
|
|
require 'sass/tree/node'
|
|
|
|
|
|
|
|
module Sass::Tree
|
|
|
|
class AttrNode < ValueNode
|
|
|
|
attr_accessor :name
|
|
|
|
|
2007-02-06 01:58:23 +00:00
|
|
|
def initialize(name, value, style)
|
2006-12-04 08:41:09 +00:00
|
|
|
@name = name
|
2007-02-06 01:58:23 +00:00
|
|
|
super(value, style)
|
2006-12-04 08:41:09 +00:00
|
|
|
end
|
|
|
|
|
2006-12-22 05:11:03 +00:00
|
|
|
def to_s(parent_name = nil)
|
2007-02-04 05:37:27 +00:00
|
|
|
if name[-1] == ?: || value[-1] == ?;
|
|
|
|
raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump} (This isn't CSS!)", @line)
|
|
|
|
end
|
2006-12-22 05:11:03 +00:00
|
|
|
real_name = name
|
|
|
|
real_name = "#{parent_name}-#{real_name}" if parent_name
|
2007-01-28 10:14:15 +00:00
|
|
|
|
2007-03-18 04:33:01 +00:00
|
|
|
if value.empty? && children.empty?
|
|
|
|
raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump}", @line)
|
|
|
|
end
|
|
|
|
|
|
|
|
join_string = @style == :compact ? ' ' : "\n"
|
|
|
|
to_return = ''
|
|
|
|
if !value.empty?
|
|
|
|
to_return << "#{real_name}: #{value};#{join_string}"
|
|
|
|
end
|
|
|
|
|
|
|
|
children.each do |kid|
|
|
|
|
if @style == :compact
|
|
|
|
to_return << "#{kid.to_s(real_name)} "
|
|
|
|
else
|
|
|
|
to_return << "#{kid.to_s(real_name)}\n"
|
|
|
|
end
|
2006-12-22 05:11:03 +00:00
|
|
|
end
|
2007-03-18 04:33:01 +00:00
|
|
|
to_return << "\n" unless children.empty? || @style == :compact
|
|
|
|
to_return[0...-1]
|
2006-12-04 08:41:09 +00:00
|
|
|
end
|
2007-02-04 05:37:27 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def declaration
|
|
|
|
":#{name} #{value}"
|
|
|
|
end
|
2007-03-18 04:15:50 +00:00
|
|
|
|
|
|
|
def invalid_child?(child)
|
|
|
|
if !child.is_a?(AttrNode)
|
|
|
|
"Illegal nesting: Only attributes may be nested beneath attributes."
|
|
|
|
end
|
|
|
|
end
|
2006-12-04 08:41:09 +00:00
|
|
|
end
|
|
|
|
end
|