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

[Sass] Fixed some handling of units in loops and comparisons.

This commit is contained in:
Chris Eppstein 2009-06-28 23:40:47 -07:00
parent 4a901ed14f
commit ae4f3193f4
3 changed files with 23 additions and 8 deletions

View file

@ -155,9 +155,19 @@ module Sass::Script
# @param other [Literal] The right-hand side of the operator
# @return [Boolean] Whether this number is equal to the other object
def eq(other)
Sass::Script::Bool.new(super.to_bool &&
self.numerator_units.sort == other.numerator_units.sort &&
self.denominator_units.sort == other.denominator_units.sort)
return Sass::Script::Bool.new(false) unless other.is_a?(Sass::Script::Number)
this = self
begin
if unitless?
this = this.coerce(other.numerator_units, other.denominator_units)
else
other = other.coerce(numerator_units, denominator_units)
end
rescue Sass::SyntaxError
return Sass::Script::Bool.new(false)
end
Sass::Script::Bool.new(this.value == other.value)
end
# The SassScript `>` operation.
@ -253,7 +263,7 @@ module Sass::Script
def operate(other, operation)
this = self
if [:+, :-].include?(operation)
if [:+, :-, :<=, :<, :>, :>=].include?(operation)
if unitless?
this = this.coerce(other.numerator_units, other.denominator_units)
else

View file

@ -28,14 +28,17 @@ module Sass::Tree
# @return [Array<Tree::Node>] The resulting static nodes
# @see Sass::Tree
def _perform(environment)
from = @from.perform(environment).to_i
to = @to.perform(environment).to_i
range = Range.new(from, to, @exclusive)
from = @from.perform(environment)
to = @to.perform(environment)
if to.respond_to?(:coerce)
to = to.send(:coerce, from.numerator_units, from.denominator_units)
end
range = Range.new(from.to_i, to.to_i, @exclusive)
children = []
environment = Sass::Environment.new(environment)
range.each do |i|
environment.set_local_var(@var, Sass::Script::Number.new(i))
environment.set_local_var(@var, Sass::Script::Number.new(i, from.numerator_units, from.denominator_units))
children += perform_children(environment)
end
children

View file

@ -76,8 +76,10 @@ class SassEngineTest < Test::Unit::TestCase
"@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.",
"a\n !b = 12\nc\n d = !b" => 'Undefined variable: "!b".',
"=foo\n !b = 12\nc\n +foo\n d = !b" => 'Undefined variable: "!b".',
'@for !a from 1 to "2"' => '"2" is not an integer.',
'@for !a from 1 to "foo"' => '"foo" is not an integer.',
'@for !a from 1 to 1.232323' => '1.232 is not an integer.',
'@for !a from 1px to 3em' => "Incompatible units: 'em' and 'px'.",
'@if' => "Invalid if directive '@if': expected expression.",
'@while' => "Invalid while directive '@while': expected expression.",
'@debug' => "Invalid debug directive '@debug': expected expression.",