mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Merge branch 'yard' into yard-sassc
Conflicts: lib/sass/tree/attr_node.rb
This commit is contained in:
commit
d6776e803f
2 changed files with 49 additions and 9 deletions
|
@ -1,7 +1,23 @@
|
||||||
module Sass::Tree
|
module Sass::Tree
|
||||||
|
# A static node reprenting a CSS property.
|
||||||
|
#
|
||||||
|
# @see Sass::Tree
|
||||||
class AttrNode < Node
|
class AttrNode < Node
|
||||||
attr_accessor :name, :value
|
# The name of the property.
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
attr_accessor :name
|
||||||
|
|
||||||
|
# The value of the property,
|
||||||
|
# either a plain string or a SassScript parse tree.
|
||||||
|
#
|
||||||
|
# @return [String, Script::Node]
|
||||||
|
attr_accessor :value
|
||||||
|
|
||||||
|
# @param name [String] See \{#name}
|
||||||
|
# @param value [String] See \{#value}
|
||||||
|
# @param attr_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,
|
||||||
|
# `:old` if it uses `:a b`-style syntax
|
||||||
def initialize(name, value, attr_syntax)
|
def initialize(name, value, attr_syntax)
|
||||||
@name = name
|
@name = name
|
||||||
@value = value
|
@value = value
|
||||||
|
@ -9,10 +25,21 @@ module Sass::Tree
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Compares the names and values of two properties.
|
||||||
|
#
|
||||||
|
# @param other [Object] The object to compare with
|
||||||
|
# @return [Boolean] Whether or not this node and the other object
|
||||||
|
# are the same
|
||||||
def ==(other)
|
def ==(other)
|
||||||
self.class == other.class && name == other.name && value == other.value && super
|
self.class == other.class && name == other.name && value == other.value && super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Computes the CSS for the Property.
|
||||||
|
#
|
||||||
|
# @param tabs [Fixnum] The level of indentation for the CSS
|
||||||
|
# @param parent_name [String] The name of the parent property (e.g. `text`) or nil
|
||||||
|
# @return [String] The resulting CSS
|
||||||
|
# @raise [Sass::SyntaxError] if the attribute uses invalid syntax
|
||||||
def to_s(tabs, parent_name = nil)
|
def to_s(tabs, parent_name = nil)
|
||||||
if @options[:attribute_syntax] == :normal && @attr_syntax == :new
|
if @options[:attribute_syntax] == :normal && @attr_syntax == :new
|
||||||
raise Sass::SyntaxError.new("Illegal attribute syntax: can't use alternate syntax when :attribute_syntax => :normal is set.")
|
raise Sass::SyntaxError.new("Illegal attribute syntax: can't use alternate syntax when :attribute_syntax => :normal is set.")
|
||||||
|
@ -49,23 +76,33 @@ module Sass::Tree
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
# Runs any SassScript that may be embedded in the property.
|
||||||
|
#
|
||||||
|
# @param environment [Sass::Environment] The lexical environment containing
|
||||||
|
# variable and mixin values
|
||||||
def perform!(environment)
|
def perform!(environment)
|
||||||
@name = interpolate(@name, environment)
|
@name = interpolate(@name, environment)
|
||||||
@value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s
|
@value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns an error message if the given child node is invalid,
|
||||||
|
# and false otherwise.
|
||||||
|
#
|
||||||
|
# {AttrNode} only allows other {AttrNode}s and {CommentNode}s as children.
|
||||||
|
# @param child [Tree::Node] A potential child node
|
||||||
|
# @return [String] An error message if the child is invalid, or nil otherwise
|
||||||
|
def invalid_child?(child)
|
||||||
|
if !child.is_a?(AttrNode) && !child.is_a?(CommentNode)
|
||||||
|
"Illegal nesting: Only attributes may be nested beneath attributes."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def declaration
|
def declaration
|
||||||
":#{name} #{value}"
|
":#{name} #{value}"
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,9 +85,12 @@ module Sass
|
||||||
# if the contents of the nodes and all the child nodes are equivalent,
|
# if the contents of the nodes and all the child nodes are equivalent,
|
||||||
# then the nodes are as well.
|
# then the nodes are as well.
|
||||||
#
|
#
|
||||||
|
# Only static nodes need to override this.
|
||||||
|
#
|
||||||
# @param other [Object] The object to compare with
|
# @param other [Object] The object to compare with
|
||||||
# @return [Boolean] Whether or not this node and the other object
|
# @return [Boolean] Whether or not this node and the other object
|
||||||
# are the same
|
# are the same
|
||||||
|
# @see Sass::Tree
|
||||||
def ==(other)
|
def ==(other)
|
||||||
self.class == other.class && other.children == children
|
self.class == other.class && other.children == children
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue