Merge branch 'master' into sassc

Conflicts:

	lib/sass/tree/comment_node.rb
This commit is contained in:
Nathan Weizenbaum 2009-04-25 01:44:28 -07:00
commit 04d30c599c
9 changed files with 85 additions and 105 deletions

View File

@ -185,10 +185,10 @@ END
node.line = line.index
node.filename = line.filename
unless node.is_a?(Tree::CommentNode)
append_children(node, line.children, false)
if node.is_a?(Tree::CommentNode)
node.lines = line.children
else
node.children = line.children
append_children(node, line.children, false)
end
return node
end

View File

@ -2,17 +2,6 @@ require File.join(File.dirname(__FILE__), 'functions')
module Sass
module Script
class Funcall # :nodoc:
class EvaluationContext # :nodoc:
include Sass::Script::Functions
attr_reader :options
def initialize(options)
@options = options
end
end
attr_reader :name, :args
def initialize(name, args)
@ -30,7 +19,7 @@ module Sass
return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
end
return EvaluationContext.new(environment.options).send(name, *args)
return Functions::EvaluationContext.new(environment.options).send(name, *args)
rescue ArgumentError => e
raise e unless e.backtrace.first =~ /:in `(#{name}|perform)'$/
raise Sass::SyntaxError.new("#{e.message} for `#{name}'")

View File

@ -44,8 +44,17 @@ module Sass::Script
#
# Example: <tt>abs(-10px) => 10px</tt>
module Functions
class EvaluationContext # :nodoc:
include Sass::Script::Functions
attr_reader :options
def initialize(options)
@options = options
end
end
instance_methods.each { |m| undef_method m unless m.to_s =~ /^__/ }
extend self
# Creates a Sass::Script::Color object from hue, saturation, and lightness.
# As per the CSS3 spec (http://www.w3.org/TR/css3-color/#hsl-color),

View File

@ -65,10 +65,6 @@ module Sass
@scanner.eos? && @tok.nil?
end
def rest
@scanner.rest
end
private
def read_token

View File

@ -1,80 +1,82 @@
class Sass::Script::Literal # :nodoc:
require 'sass/script/string'
require 'sass/script/number'
require 'sass/script/color'
require 'sass/script/bool'
module Sass::Script
class Literal # :nodoc:
require 'sass/script/string'
require 'sass/script/number'
require 'sass/script/color'
require 'sass/script/bool'
attr_reader :value
attr_reader :value
def initialize(value = nil)
@value = value
end
def initialize(value = nil)
@value = value
end
def perform(environment)
self
end
def perform(environment)
self
end
def and(other)
to_bool ? other : self
end
def and(other)
to_bool ? other : self
end
def or(other)
to_bool ? self : other
end
def or(other)
to_bool ? self : other
end
def eq(other)
Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
end
def eq(other)
Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
end
def neq(other)
Sass::Script::Bool.new(!eq(other).to_bool)
end
def neq(other)
Sass::Script::Bool.new(!eq(other).to_bool)
end
def unary_not
Sass::Script::Bool.new(!to_bool)
end
def unary_not
Sass::Script::Bool.new(!to_bool)
end
def concat(other)
Sass::Script::String.new("#{self.to_s} #{other.to_s}")
end
def concat(other)
Sass::Script::String.new("#{self.to_s} #{other.to_s}")
end
def comma(other)
Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
end
def comma(other)
Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
end
def plus(other)
Sass::Script::String.new(self.to_s + other.to_s)
end
def plus(other)
Sass::Script::String.new(self.to_s + other.to_s)
end
def minus(other)
Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
end
def minus(other)
Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
end
def div(other)
Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
end
def div(other)
Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
end
def unary_minus
Sass::Script::String.new("-#{self.to_s}")
end
def unary_minus
Sass::Script::String.new("-#{self.to_s}")
end
def unary_div
Sass::Script::String.new("/#{self.to_s}")
end
def unary_div
Sass::Script::String.new("/#{self.to_s}")
end
def inspect
value.inspect
end
def inspect
value.inspect
end
def to_bool
true
end
def to_bool
true
end
def ==(other)
eq(other).to_bool
end
def ==(other)
eq(other).to_bool
end
def to_i
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
def to_i
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
end
end
end

View File

@ -20,7 +20,7 @@ module Sass::Script
elsif other.is_a?(Color)
other.plus(self)
else
Sass::Script::String.new(self.to_s + other.to_s)
super
end
end
@ -77,17 +77,17 @@ module Sass::Script
end
def gte(other)
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
raise NoMethodError.new(nil, :gte) unless other.is_a?(Number)
operate(other, :>=)
end
def lt(other)
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
raise NoMethodError.new(nil, :lt) unless other.is_a?(Number)
operate(other, :<)
end
def lte(other)
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
raise NoMethodError.new(nil, :lte) unless other.is_a?(Number)
operate(other, :<=)
end

View File

@ -2,15 +2,6 @@ require 'sass/script/literal'
module Sass::Script
class String < Literal # :nodoc:
INTERPOLATION = /(^|[^\\])\#\{([^}]*)\}/
#TODO pass line & char context to perform
def perform(environment)
interpolated = @value.gsub(INTERPOLATION) do |match|
"#{$1}#{Sass::Script.resolve($2, 0, 0, environment)}"
end
Sass::Script::String.new(interpolated)
end
def to_s
@value
end

View File

@ -2,34 +2,27 @@ require 'sass/tree/node'
module Sass::Tree
class CommentNode < Node
attr_accessor :lines
attr_accessor :value
attr_accessor :silent
def initialize(value, silent)
@lines = []
@value = value[2..-1].strip
@silent = silent
super()
end
def options=(options)
@options = options
end
def ==(other)
self.value == other.value && super
self.class == other.class && value == other.value && silent == other.silent && lines == other.lines
end
def to_s(tabs = 0, parent_name = nil)
return if (style == :compressed || @silent)
spaces = ' ' * (tabs - 1)
spaces + "/* " + ([value] + children.map {|c| c.text}).
spaces + "/* " + ([value] + lines.map {|l| l.text}).
map{|l| l.sub(%r{ ?\*/ *$},'')}.join(style == :compact ? ' ' : "\n#{spaces} * ") + " */"
end
protected
def _perform(environment)
self
end
end
end

View File

@ -92,7 +92,7 @@ class SassFunctionTest < Test::Unit::TestCase
def assert_rgb_hsl(rgb, hsl)
hsl = hsl.map {|v| Sass::Script::Parser.parse v, 0, 0 }
assert_equal(rgb, Sass::Script::Functions.hsl(*hsl).value)
assert_equal(rgb, Sass::Script::Functions::EvaluationContext.new({}).hsl(*hsl).value)
end
def evaluate(value)