Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'stable'

* stable:
  [Sass] Proper fix for GH-275 that doesn't break other tests. Closes GH-281.
  [Haml] Fix :encoding under 1.9.2.
  [Sass] Make rgba respect precision.

Conflicts:
	doc-src/HAML_CHANGELOG.md
	lib/haml/buffer.rb
	lib/haml/engine.rb
	lib/sass/script/color.rb
	lib/sass/script/number.rb
	test/haml/engine_test.rb
  • Loading branch information...
commit 85aa757517a4c51f6c6796e0e23bae3bc758908b 2 parents 9819c42 + 50d89b5
@chriseppstein authored
View
2  doc-src/SASS_CHANGELOG.md
@@ -20,6 +20,8 @@
## 3.0.19 (Unreleased)
+* Make the alpha value for `rgba` colors respect {Sass::Script::Number::PRECISION}.
+
* Remove all newlines in selectors in `:compressed` mode.
* Make color names case-insensitive.
View
2  lib/sass/script/color.rb
@@ -401,7 +401,7 @@ def smallest
end
def rgba_str
- "rgba(#{rgb.join(', ')}, #{Sass::Util.tolerate(alpha)})"
+ "rgba(#{rgb.join(', ')}, #{Number.round(alpha)})"
end
def hex_str
View
27 lib/sass/script/number.rb
@@ -10,6 +10,12 @@ module Sass::Script
# Numbers can also have more complex units, such as `1px*em/in`.
# These cannot be inputted directly in Sass code at the moment.
class Number < Literal
+ # 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`.
+ # @api public
+ PRECISION = 1000.0
+
# The Ruby value of the number.
#
# @return [Numeric]
@@ -242,15 +248,7 @@ def to_s
#
# @return [String] The representation
def inspect(opts = {})
- value =
- if self.value.is_a?(Float) && (self.value.infinite? || self.value.nan?)
- self.value
- elsif int?
- self.value.to_i
- else
- Sass::Util.tolerate(self.value)
- end
- "#{value}#{unit_str}"
+ "#{self.class.round(self.value)}#{unit_str}"
end
alias_method :to_sass, :inspect
@@ -328,6 +326,17 @@ def unit_str
private
+ # @private
+ def self.round(num)
+ if num.is_a?(Float) && (num.infinite? || num.nan?)
+ num
+ elsif num % 1 == 0.0
+ num.to_i
+ else
+ (num * PRECISION).round / PRECISION
+ end
+ end
+
def operate(other, operation)
this = self
if [:+, :-, :<=, :<, :>, :>=].include?(operation)
View
2  lib/sass/tree/rule_node.rb
@@ -134,7 +134,7 @@ def _to_s(tabs)
per_rule_indent, total_indent = [:nested, :expanded].include?(style) ? [rule_indent, ''] : ['', rule_indent]
total_rule = total_indent + resolved_rules.members.
- map {|seq| seq.to_a.join.gsub("\n", style == :compressed ? " " : "\n")}.
+ map {|seq| seq.to_a.join.gsub(/([^,])\n/m, style == :compressed ? '\1 ' : "\\1\n")}.
join(rule_separator).split("\n").map do |line|
per_rule_indent + line.strip
end.join(line_separator)
View
14 lib/sass/util.rb
@@ -623,20 +623,6 @@ def set_eql?(set1, set2)
set1.to_a.uniq.sort_by {|e| e.hash}.eql?(set2.to_a.uniq.sort_by {|e| e.hash})
end
- # 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`.
- # @api public
- PRECISION = 1000.0
-
- # Round to the nearest decimal point digit
- # @param number - the number to tolerate
- # @param precision - a multiple of 10
- def tolerate(number, precision = PRECISION)
- n = (number * precision).round / precision.to_f
- n % 1 == 0 ? n.to_i : n
- end
-
## Static Method Stuff
# The context in which the ERB for \{#def\_static\_method} will be run.
View
4 test/sass/script_test.rb
@@ -79,6 +79,10 @@ def test_rgba_number_math
assert_equal "rgba(100, 100, 100, 0.75)", resolve("rgba(50, 50, 50, 0.75) * 2")
end
+ def test_rgba_rounding
+ assert_equal "rgba(10, 1, 0, 0.123)", resolve("rgba(10.0, 1.23456789, 0.0, 0.1234567)")
+ end
+
def test_compressed_colors
assert_equal "#123456", resolve("#123456", :style => :compressed)
assert_equal "rgba(1, 2, 3, 0.5)", resolve("rgba(1, 2, 3, 0.5)", :style => :compressed)
Please sign in to comment.
Something went wrong with that request. Please try again.