mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Make 1px/2px compile to that, literally, when necessary for CSS compatibility.
This commit is contained in:
parent
eb534b4320
commit
2baed988d9
6 changed files with 30 additions and 10 deletions
|
@ -25,6 +25,8 @@ module Sass::Script
|
|||
# @return [Array<String>]
|
||||
attr_reader :denominator_units
|
||||
|
||||
attr_accessor :original
|
||||
|
||||
# The precision with which numbers will be printed to CSS files.
|
||||
# For example, if this is `1000.0`,
|
||||
# `3.1415926` will be printed as `3.142`.
|
||||
|
@ -134,7 +136,9 @@ module Sass::Script
|
|||
# @return [Literal] The result of the operation
|
||||
def div(other)
|
||||
if other.is_a? Number
|
||||
operate(other, :/)
|
||||
res = operate(other, :/)
|
||||
res.original = "#{self.original}/#{other.original}" if self.original && other.original
|
||||
res
|
||||
else
|
||||
super
|
||||
end
|
||||
|
@ -221,6 +225,7 @@ module Sass::Script
|
|||
# @raise [Sass::SyntaxError] if this number has units that can't be used in CSS
|
||||
# (e.g. `px*in`)
|
||||
def to_s
|
||||
return original if original
|
||||
raise Sass::SyntaxError.new("#{inspect} isn't a valid CSS value.") unless legal_units?
|
||||
inspect
|
||||
end
|
||||
|
|
|
@ -262,9 +262,13 @@ RUBY
|
|||
|
||||
def paren
|
||||
return variable unless try_tok(:lparen)
|
||||
was_in_parens = @in_parens
|
||||
@in_parens = true
|
||||
e = assert_expr(:expr)
|
||||
assert_tok(:rparen)
|
||||
return e
|
||||
ensure
|
||||
@in_parens = was_in_parens
|
||||
end
|
||||
|
||||
def variable
|
||||
|
@ -273,7 +277,7 @@ RUBY
|
|||
end
|
||||
|
||||
def string
|
||||
return literal unless first = try_tok(:string)
|
||||
return number unless first = try_tok(:string)
|
||||
return first.value unless try_tok(:begin_interpolation)
|
||||
line = @lexer.line
|
||||
mid = parse_interpolated
|
||||
|
@ -283,8 +287,15 @@ RUBY
|
|||
op
|
||||
end
|
||||
|
||||
def number
|
||||
return literal unless tok = try_tok(:number)
|
||||
num = tok.value
|
||||
num.original = num.to_s unless @in_parens
|
||||
num
|
||||
end
|
||||
|
||||
def literal
|
||||
(t = try_tok(:number, :color, :bool)) && (return t.value)
|
||||
(t = try_tok(:color, :bool)) && (return t.value)
|
||||
end
|
||||
|
||||
# It would be possible to have unified #assert and #try methods,
|
||||
|
|
|
@ -36,8 +36,12 @@ module Sass
|
|||
# @return [Literal] The SassScript object that is the value of the variable
|
||||
# @raise [Sass::SyntaxError] if the variable is undefined
|
||||
def _perform(environment)
|
||||
(val = environment.var(name)) && (return val)
|
||||
raise SyntaxError.new("Undefined variable: \"$#{name}\".")
|
||||
raise SyntaxError.new("Undefined variable: \"$#{name}\".") unless val = environment.var(name)
|
||||
if val.is_a?(Number)
|
||||
val = val.dup
|
||||
val.original = nil
|
||||
end
|
||||
return val
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -182,8 +182,8 @@ SASS
|
|||
assert_equal "2", resolve("1 + 1")
|
||||
assert_equal "0", resolve("1 - 1")
|
||||
assert_equal "8", resolve("2 * 4")
|
||||
assert_equal "0.5", resolve("2 / 4")
|
||||
assert_equal "2", resolve("4 / 2")
|
||||
assert_equal "0.5", resolve("(2 / 4)")
|
||||
assert_equal "2", resolve("(4 / 2)")
|
||||
|
||||
assert_equal "-1", resolve("-1")
|
||||
end
|
||||
|
|
|
@ -297,7 +297,7 @@ SCSS
|
|||
assert_parses <<SCSS
|
||||
foo {
|
||||
a: foo bar baz;
|
||||
b: foo, #abc, -12;
|
||||
b: foo, #aabbcc, -12;
|
||||
c: 1px/2px/-3px;
|
||||
d: foo bar, baz/bang; }
|
||||
SCSS
|
||||
|
|
|
@ -78,8 +78,8 @@ $complex = 1px/1em
|
|||
|
||||
#div
|
||||
:num
|
||||
:num= 10 / 3.0
|
||||
:num2= 10 / 3
|
||||
:num= (10 / 3.0)
|
||||
:num2= (10 / 3)
|
||||
:col
|
||||
:num= #12468a / 2
|
||||
:col= #abcdef / #0f0f0f
|
||||
|
|
Loading…
Add table
Reference in a new issue