1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Add some piping that'll allow Sass::Script::Node to have access to options.

This commit is contained in:
Nathan Weizenbaum 2009-12-02 19:00:20 -08:00
parent 551f362ace
commit a9247c2f78
6 changed files with 62 additions and 0 deletions

View file

@ -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<Node>]
# @see Node#children
def children
@args
end
end
end
end

View file

@ -31,6 +31,14 @@ module Sass::Script
self
end
# Returns an empty array.
#
# @return [Array<Node>] empty
# @see Node#children
def children
[]
end
# The SassScript `and` operation.
#
# @param other [Literal] The right-hand side of the operator

View file

@ -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<Node>]
def children
raise NotImplementedError.new("All subclasses of Sass::Script::Node must override #children.")
end
end
end

View file

@ -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<Node>]
# @see Node#children
def children
[@operand1, @operand2]
end
end
end

View file

@ -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<Node>]
# @see Node#children
def children
[@operand]
end
end
end

View file

@ -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<Node>] empty
# @see Node#children
def children
[]
end
end
end
end