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