From 603871b68a484a9ae6721157ada9a85f5d53bb59 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 25 Apr 2009 13:12:04 -0700 Subject: [PATCH] [Sass] Convert Sass::Tree::AttrNode docs to YARD. --- lib/sass/tree/attr_node.rb | 54 +++++++++++++++++++++++++++++++------- lib/sass/tree/node.rb | 3 +++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/lib/sass/tree/attr_node.rb b/lib/sass/tree/attr_node.rb index c2feedbd..51d77775 100644 --- a/lib/sass/tree/attr_node.rb +++ b/lib/sass/tree/attr_node.rb @@ -1,17 +1,43 @@ module Sass::Tree + # A static node reprenting a CSS property. + # + # @see Sass::Tree 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 options [Hash] An options hash; + # see [the Sass options documentation](../../Sass.html#sass_options) def initialize(name, value, options) @name = name @value = value super(options) 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) self.class == other.class && name == other.name && value == other.value && super 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 def to_s(tabs, parent_name = nil) if value[-1] == ?; raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump} (This isn't CSS!).", @line) @@ -42,23 +68,33 @@ module Sass::Tree end 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) @name = interpolate(@name, environment) @value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s super 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 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 diff --git a/lib/sass/tree/node.rb b/lib/sass/tree/node.rb index 3a915bda..89cbf669 100644 --- a/lib/sass/tree/node.rb +++ b/lib/sass/tree/node.rb @@ -67,9 +67,12 @@ module Sass # if the contents of the nodes and all the child nodes are equivalent, # then the nodes are as well. # + # Only static nodes need to override this. + # # @param other [Object] The object to compare with # @return [Boolean] Whether or not this node and the other object # are the same + # @see Sass::Tree def ==(other) self.class == other.class && other.children == children end