diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb index 62a6871b..e80ad009 100644 --- a/lib/sass/engine.rb +++ b/lib/sass/engine.rb @@ -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 diff --git a/lib/sass/script/funcall.rb b/lib/sass/script/funcall.rb index 169fab16..925610a8 100644 --- a/lib/sass/script/funcall.rb +++ b/lib/sass/script/funcall.rb @@ -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}'") diff --git a/lib/sass/script/functions.rb b/lib/sass/script/functions.rb index 0928ac00..490c4bfe 100644 --- a/lib/sass/script/functions.rb +++ b/lib/sass/script/functions.rb @@ -44,8 +44,17 @@ module Sass::Script # # Example: abs(-10px) => 10px 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), diff --git a/lib/sass/script/lexer.rb b/lib/sass/script/lexer.rb index 86e8febb..59fce9bd 100644 --- a/lib/sass/script/lexer.rb +++ b/lib/sass/script/lexer.rb @@ -65,10 +65,6 @@ module Sass @scanner.eos? && @tok.nil? end - def rest - @scanner.rest - end - private def read_token diff --git a/lib/sass/script/literal.rb b/lib/sass/script/literal.rb index c72b6cff..aef9b12a 100644 --- a/lib/sass/script/literal.rb +++ b/lib/sass/script/literal.rb @@ -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 diff --git a/lib/sass/script/number.rb b/lib/sass/script/number.rb index 0780075b..b3ad754c 100644 --- a/lib/sass/script/number.rb +++ b/lib/sass/script/number.rb @@ -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 diff --git a/lib/sass/script/string.rb b/lib/sass/script/string.rb index dff1e9aa..622172a4 100644 --- a/lib/sass/script/string.rb +++ b/lib/sass/script/string.rb @@ -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 diff --git a/lib/sass/tree/comment_node.rb b/lib/sass/tree/comment_node.rb index 2a82fef4..be61c25c 100644 --- a/lib/sass/tree/comment_node.rb +++ b/lib/sass/tree/comment_node.rb @@ -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 diff --git a/test/sass/functions_test.rb b/test/sass/functions_test.rb index 9f1283b1..8b937797 100644 --- a/test/sass/functions_test.rb +++ b/test/sass/functions_test.rb @@ -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)