From ad36db1346d960355c9c8afdaa8c6ee9c65c636d Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 23 Apr 2009 18:02:58 -0700 Subject: [PATCH 1/8] [Sass] Dry up Script::Number#plus a little. --- lib/sass/script/number.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sass/script/number.rb b/lib/sass/script/number.rb index 0780075b..3047caee 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 From 05bf43915c12724553f7748506df2662e239ecb1 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 24 Apr 2009 01:13:10 -0700 Subject: [PATCH 2/8] [Sass] Make Number#{gte,lt,lte} raise proper errors when used with non-Numbers. --- lib/sass/script/number.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sass/script/number.rb b/lib/sass/script/number.rb index 3047caee..b3ad754c 100644 --- a/lib/sass/script/number.rb +++ b/lib/sass/script/number.rb @@ -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 From 13a27a185665d8608a9f9344f93678f5361ae5e2 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 24 Apr 2009 13:51:35 -0700 Subject: [PATCH 3/8] [Sass] Format Sass::Script::Literal like other similar classes. --- lib/sass/script/literal.rb | 120 +++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 59 deletions(-) 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 From 6161e5fd5c7f13438d164576eb61c400678942d6 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 24 Apr 2009 18:09:01 -0700 Subject: [PATCH 4/8] [Sass] Move Funcall::EvaluationContext to Functions. --- lib/sass/script/funcall.rb | 13 +------------ lib/sass/script/functions.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) 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..7e2d7035 100644 --- a/lib/sass/script/functions.rb +++ b/lib/sass/script/functions.rb @@ -44,6 +44,16 @@ 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 From ca9ffcb039801ae54310da1a95daadad15929d13 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 24 Apr 2009 18:58:56 -0700 Subject: [PATCH 5/8] [Sass] Don't have Script::Functions extend self. --- lib/sass/script/functions.rb | 1 - test/sass/functions_test.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/sass/script/functions.rb b/lib/sass/script/functions.rb index 7e2d7035..490c4bfe 100644 --- a/lib/sass/script/functions.rb +++ b/lib/sass/script/functions.rb @@ -55,7 +55,6 @@ module Sass::Script 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/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) From d97a5c7c4a360b8b9b572d18f95e260b345194c0 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 24 Apr 2009 19:31:05 -0700 Subject: [PATCH 6/8] [Sass] Get rid of Script::Lexer#rest; it's unused and incorrect. --- lib/sass/script/lexer.rb | 4 ---- 1 file changed, 4 deletions(-) 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 From d39d2eba13fa106245b5797a12e32f9556cde07e Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 24 Apr 2009 20:19:06 -0700 Subject: [PATCH 7/8] [Sass] Get rid of some now-useless interpolation code in Script::String. --- lib/sass/script/string.rb | 9 --------- 1 file changed, 9 deletions(-) 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 From ebd8872b8e03cd4468c22bd89510d1013ec6a5b5 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 25 Apr 2009 00:09:44 -0700 Subject: [PATCH 8/8] [Sass] Don't violate #children's typing in Tree::CommentNode. --- lib/sass/engine.rb | 6 +++--- lib/sass/tree/comment_node.rb | 12 ++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb index 6c384a1b..2b2417a4 100644 --- a/lib/sass/engine.rb +++ b/lib/sass/engine.rb @@ -186,10 +186,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/tree/comment_node.rb b/lib/sass/tree/comment_node.rb index 8f1bdb3f..59d36029 100644 --- a/lib/sass/tree/comment_node.rb +++ b/lib/sass/tree/comment_node.rb @@ -2,15 +2,17 @@ require 'sass/tree/node' module Sass::Tree class CommentNode < Node + attr_accessor :lines attr_accessor :value def initialize(value, options) + @lines = [] @value = value[2..-1].strip super(options) end def ==(other) - self.value == other.value && super + self.class == other.class && value == other.value && lines == other.lines end def silent? @@ -21,14 +23,8 @@ module Sass::Tree 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