Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Per the CSS spec, There are 96px in 1in.

  • Loading branch information...
commit 1bd914960252ead6876b816d7335696d43ecbd35 1 parent 02947c9
@chriseppstein authored
View
13 lib/sass/script/number.rb
@@ -422,12 +422,13 @@ def normalize!
end
# A hash of unit names to their index in the conversion table
- CONVERTABLE_UNITS = {"in" => 0, "cm" => 1, "pc" => 2, "mm" => 3, "pt" => 4}
- CONVERSION_TABLE = [[ 1, 2.54, 6, 25.4, 72 ], # in
- [ nil, 1, 2.36220473, 10, 28.3464567], # cm
- [ nil, nil, 1, 4.23333333, 12 ], # pc
- [ nil, nil, nil, 1, 2.83464567], # mm
- [ nil, nil, nil, nil, 1 ]] # pt
+ CONVERTABLE_UNITS = {"in" => 0, "cm" => 1, "pc" => 2, "mm" => 3, "pt" => 4, "px" => 5 }
+ CONVERSION_TABLE = [[ 1, 2.54, 6, 25.4, 72 , 96 ], # in
+ [ nil, 1, 2.36220473, 10, 28.3464567, 37.795275591], # cm
+ [ nil, nil, 1, 4.23333333, 12 , 16 ], # pc
+ [ nil, nil, nil, 1, 2.83464567, 3.7795275591], # mm
+ [ nil, nil, nil, nil, 1 , 1.3333333333], # pt
+ [ nil, nil, nil, nil, nil , 1 ]] # px
def conversion_factor(from_unit, to_unit)
res = CONVERSION_TABLE[CONVERTABLE_UNITS[from_unit]][CONVERTABLE_UNITS[to_unit]]
View
3  test/sass/functions_test.rb
@@ -865,7 +865,8 @@ def test_unit
assert_equal(%Q{"px"}, evaluate("unit(100px)"))
assert_equal(%Q{"em*px"}, evaluate("unit(10px * 5em)"))
assert_equal(%Q{"em*px"}, evaluate("unit(5em * 10px)"))
- assert_equal(%Q{"em*px/cm*rem"}, evaluate("unit(10px * 5em / 30cm / 1rem)"))
+ assert_equal(%Q{"em/rem"}, evaluate("unit(10px * 5em / 30cm / 1rem)"))
+ assert_equal(%Q{"em*vh/cm*rem"}, evaluate("unit(10vh * 5em / 30cm / 1rem)"))
assert_equal(%Q{"px"}, evaluate("unit($number: 100px)"))
assert_error_message("#ff0000 is not a number for `unit'", "unit(#f00)")
end
View
2  test/sass/results/units.css
@@ -8,4 +8,4 @@ b {
pt: -72pt;
inches: 2in;
more-inches: 3.5in;
- mixed: 6px; }
+ mixed: 2.042in; }
View
1  test/sass/script_test.rb
@@ -359,6 +359,7 @@ def test_functions
def test_operator_unit_conversion
assert_equal "1.1cm", resolve("1cm + 1mm")
+ assert_equal "2in", resolve("1in + 96px")
assert_equal "true", resolve("2mm < 1cm")
assert_equal "true", resolve("10mm == 1cm")
assert_equal "true", resolve("1 == 1cm")
Please sign in to comment.
Something went wrong with that request. Please try again.