From a9247c2f78693c3060609a6e4007555e6b4348c6 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Wed, 2 Dec 2009 19:00:20 -0800 Subject: [PATCH] [Sass] Add some piping that'll allow Sass::Script::Node to have access to options. --- lib/sass/script/funcall.rb | 8 ++++++++ lib/sass/script/literal.rb | 8 ++++++++ lib/sass/script/node.rb | 22 ++++++++++++++++++++++ lib/sass/script/operation.rb | 8 ++++++++ lib/sass/script/unary_operation.rb | 8 ++++++++ lib/sass/script/variable.rb | 8 ++++++++ 6 files changed, 62 insertions(+) diff --git a/lib/sass/script/funcall.rb b/lib/sass/script/funcall.rb index e7045b8c..d11f2d42 100644 --- a/lib/sass/script/funcall.rb +++ b/lib/sass/script/funcall.rb @@ -46,6 +46,14 @@ module Sass raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/} raise Sass::SyntaxError.new("#{e.message} for `#{name}'") end + + # Returns the arguments to the function. + # + # @return [Array] + # @see Node#children + def children + @args + end end end end diff --git a/lib/sass/script/literal.rb b/lib/sass/script/literal.rb index cdb2cf78..ef88e088 100644 --- a/lib/sass/script/literal.rb +++ b/lib/sass/script/literal.rb @@ -31,6 +31,14 @@ module Sass::Script self end + # Returns an empty array. + # + # @return [Array] empty + # @see Node#children + def children + [] + end + # The SassScript `and` operation. # # @param other [Literal] The right-hand side of the operator diff --git a/lib/sass/script/node.rb b/lib/sass/script/node.rb index 2aacf7a8..7f641a9e 100644 --- a/lib/sass/script/node.rb +++ b/lib/sass/script/node.rb @@ -3,6 +3,21 @@ module Sass::Script # # Use \{#perform} to evaluate a parse tree. class Node + # The options hash for this node. + # + # @return [{Symbol => Object}] + attr_reader :options + + # Sets the options hash for this node, + # as well as for all child nodes. + # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}. + # + # @param options [{Symbol => Object}] The options + def options=(options) + @options = options + children.each {|c| c.options = options} + end + # Evaluates the node. # # @param environment [Sass::Environment] The environment in which to evaluate the SassScript @@ -10,5 +25,12 @@ module Sass::Script def perform(environment) raise NotImplementedError.new("All subclasses of Sass::Script::Node must override #perform.") end + + # Returns all child nodes of this node. + # + # @return [Array] + def children + raise NotImplementedError.new("All subclasses of Sass::Script::Node must override #children.") + end end end diff --git a/lib/sass/script/operation.rb b/lib/sass/script/operation.rb index f8b2f59f..d184bb02 100644 --- a/lib/sass/script/operation.rb +++ b/lib/sass/script/operation.rb @@ -41,5 +41,13 @@ module Sass::Script raise Sass::SyntaxError.new("Undefined operation: \"#{literal1} #{@operator} #{literal2}\".") end end + + # Returns the operands for this operation. + # + # @return [Array] + # @see Node#children + def children + [@operand1, @operand2] + end end end diff --git a/lib/sass/script/unary_operation.rb b/lib/sass/script/unary_operation.rb index 5623920a..89c60b22 100644 --- a/lib/sass/script/unary_operation.rb +++ b/lib/sass/script/unary_operation.rb @@ -30,5 +30,13 @@ module Sass::Script raise e unless e.name.to_s == operator.to_s raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{literal}\".") end + + # Returns the operand of the operation. + # + # @return [Array] + # @see Node#children + def children + [@operand] + end end end diff --git a/lib/sass/script/variable.rb b/lib/sass/script/variable.rb index 74c28fe0..29914591 100644 --- a/lib/sass/script/variable.rb +++ b/lib/sass/script/variable.rb @@ -26,6 +26,14 @@ module Sass (val = environment.var(name)) && (return val) raise SyntaxError.new("Undefined variable: \"!#{name}\".") end + + # Returns an empty array. + # + # @return [Array] empty + # @see Node#children + def children + [] + end end end end