Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 1bd914960252ead6876b816d7335696d43ecbd35 1 parent 02947c9
Chris Eppstein authored
13 lib/sass/script/number.rb
@@ -422,12 +422,13 @@ def normalize!
422 422 end
423 423
424 424 # A hash of unit names to their index in the conversion table
425   - CONVERTABLE_UNITS = {"in" => 0, "cm" => 1, "pc" => 2, "mm" => 3, "pt" => 4}
426   - CONVERSION_TABLE = [[ 1, 2.54, 6, 25.4, 72 ], # in
427   - [ nil, 1, 2.36220473, 10, 28.3464567], # cm
428   - [ nil, nil, 1, 4.23333333, 12 ], # pc
429   - [ nil, nil, nil, 1, 2.83464567], # mm
430   - [ nil, nil, nil, nil, 1 ]] # pt
  425 + CONVERTABLE_UNITS = {"in" => 0, "cm" => 1, "pc" => 2, "mm" => 3, "pt" => 4, "px" => 5 }
  426 + CONVERSION_TABLE = [[ 1, 2.54, 6, 25.4, 72 , 96 ], # in
  427 + [ nil, 1, 2.36220473, 10, 28.3464567, 37.795275591], # cm
  428 + [ nil, nil, 1, 4.23333333, 12 , 16 ], # pc
  429 + [ nil, nil, nil, 1, 2.83464567, 3.7795275591], # mm
  430 + [ nil, nil, nil, nil, 1 , 1.3333333333], # pt
  431 + [ nil, nil, nil, nil, nil , 1 ]] # px
431 432
432 433 def conversion_factor(from_unit, to_unit)
433 434 res = CONVERSION_TABLE[CONVERTABLE_UNITS[from_unit]][CONVERTABLE_UNITS[to_unit]]
3  test/sass/functions_test.rb
@@ -865,7 +865,8 @@ def test_unit
865 865 assert_equal(%Q{"px"}, evaluate("unit(100px)"))
866 866 assert_equal(%Q{"em*px"}, evaluate("unit(10px * 5em)"))
867 867 assert_equal(%Q{"em*px"}, evaluate("unit(5em * 10px)"))
868   - assert_equal(%Q{"em*px/cm*rem"}, evaluate("unit(10px * 5em / 30cm / 1rem)"))
  868 + assert_equal(%Q{"em/rem"}, evaluate("unit(10px * 5em / 30cm / 1rem)"))
  869 + assert_equal(%Q{"em*vh/cm*rem"}, evaluate("unit(10vh * 5em / 30cm / 1rem)"))
869 870 assert_equal(%Q{"px"}, evaluate("unit($number: 100px)"))
870 871 assert_error_message("#ff0000 is not a number for `unit'", "unit(#f00)")
871 872 end
2  test/sass/results/units.css
@@ -8,4 +8,4 @@ b {
8 8 pt: -72pt;
9 9 inches: 2in;
10 10 more-inches: 3.5in;
11   - mixed: 6px; }
  11 + mixed: 2.042in; }
1  test/sass/script_test.rb
@@ -359,6 +359,7 @@ def test_functions
359 359
360 360 def test_operator_unit_conversion
361 361 assert_equal "1.1cm", resolve("1cm + 1mm")
  362 + assert_equal "2in", resolve("1in + 96px")
362 363 assert_equal "true", resolve("2mm < 1cm")
363 364 assert_equal "true", resolve("10mm == 1cm")
364 365 assert_equal "true", resolve("1 == 1cm")

0 comments on commit 1bd9149

Please sign in to comment.
Something went wrong with that request. Please try again.