2006-12-04 08:41:09 +00:00
|
|
|
module Sass::Tree
|
2008-10-13 09:49:35 -07:00
|
|
|
class AttrNode < Node
|
|
|
|
attr_accessor :name, :value
|
|
|
|
|
2008-07-19 23:27:17 -04:00
|
|
|
def initialize(name, value, options)
|
2006-12-04 08:41:09 +00:00
|
|
|
@name = name
|
2008-10-13 09:49:35 -07:00
|
|
|
@value = value
|
|
|
|
super(options)
|
2006-12-04 08:41:09 +00:00
|
|
|
end
|
2008-10-13 09:49:35 -07:00
|
|
|
|
2007-08-12 10:54:35 +00:00
|
|
|
def to_s(tabs, parent_name = nil)
|
2007-05-03 08:46:02 +00:00
|
|
|
if value[-1] == ?;
|
2008-04-19 10:16:10 -07:00
|
|
|
raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump} (This isn't CSS!).", @line)
|
2007-02-04 05:37:27 +00:00
|
|
|
end
|
2006-12-22 05:11:03 +00:00
|
|
|
real_name = name
|
|
|
|
real_name = "#{parent_name}-#{real_name}" if parent_name
|
2008-10-13 09:49:35 -07:00
|
|
|
|
2007-03-18 04:33:01 +00:00
|
|
|
if value.empty? && children.empty?
|
2008-04-19 10:16:10 -07:00
|
|
|
raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump}.", @line)
|
2007-03-18 04:33:01 +00:00
|
|
|
end
|
2008-10-13 09:49:35 -07:00
|
|
|
|
2007-09-07 09:00:58 +00:00
|
|
|
join_string = case @style
|
2007-12-26 02:22:23 +00:00
|
|
|
when :compact; ' '
|
|
|
|
when :compressed; ''
|
2007-09-07 09:00:58 +00:00
|
|
|
else "\n"
|
|
|
|
end
|
2007-08-12 10:54:35 +00:00
|
|
|
spaces = ' ' * (tabs - 1)
|
2007-03-18 04:33:01 +00:00
|
|
|
to_return = ''
|
|
|
|
if !value.empty?
|
2007-09-07 09:00:58 +00:00
|
|
|
to_return << "#{spaces}#{real_name}:#{@style == :compressed ? '' : ' '}#{value};#{join_string}"
|
2007-03-18 04:33:01 +00:00
|
|
|
end
|
2008-10-13 09:49:35 -07:00
|
|
|
|
2007-03-18 04:33:01 +00:00
|
|
|
children.each do |kid|
|
2007-09-07 09:00:58 +00:00
|
|
|
to_return << "#{kid.to_s(tabs, real_name)}" << join_string
|
2006-12-22 05:11:03 +00:00
|
|
|
end
|
2008-10-13 09:49:35 -07:00
|
|
|
|
2007-09-07 09:00:58 +00:00
|
|
|
(@style == :compressed && parent_name) ? to_return : to_return[0...-1]
|
2006-12-04 08:41:09 +00:00
|
|
|
end
|
2007-02-04 05:37:27 +00:00
|
|
|
|
2008-10-13 09:49:35 -07:00
|
|
|
protected
|
|
|
|
|
|
|
|
def perform!(environment)
|
|
|
|
@name = interpolate(@name, environment)
|
|
|
|
@value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s
|
|
|
|
super
|
|
|
|
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)
|
2007-12-07 20:09:16 +00:00
|
|
|
if !child.is_a?(AttrNode) && !child.is_a?(CommentNode)
|
2007-03-18 04:15:50 +00:00
|
|
|
"Illegal nesting: Only attributes may be nested beneath attributes."
|
|
|
|
end
|
|
|
|
end
|
2006-12-04 08:41:09 +00:00
|
|
|
end
|
|
|
|
end
|