haml 2.2.13 → 2.2.14

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

data/README.md CHANGED
@@ -49,6 +49,16 @@ To do so, just add
49
49
  to `config/dependencies.rb` (or `config/init.rb` in a flat/very flat Merb application).
50
50
  Then it'll work just like it does in Rails.
51
51
 
52
+ Sass can also be used with any Rack-enabled web framework.
53
+ To do so, just add
54
+
55
+ require 'sass/plugin/rack'
56
+ use Sass::Plugin::Rack
57
+
58
+ to `config.ru`.
59
+ Then any Sass files in `public/stylesheets/sass`
60
+ will be compiled CSS files in `public/stylesheets` on every request.
61
+
52
62
  To use Haml and Sass programatically,
53
63
  check out the [YARD documentation](http://haml-lang.com/docs/yardoc).
54
64
 
data/Rakefile CHANGED
@@ -80,6 +80,7 @@ task :release => [:check_release, :release_elpa, :package] do
80
80
  sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz}
81
81
  sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.bz2}
82
82
  sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.zip}
83
+ sh %{gem push pkg/haml-#{version}.gem}
83
84
  end
84
85
 
85
86
  # Releases haml-mode.el and sass-mode.el to ELPA.
@@ -312,11 +313,11 @@ rescue LoadError; end
312
313
  # ----- Testing Multiple Rails Versions -----
313
314
 
314
315
  rails_versions = [
315
- "v2.3.0",
316
+ "v2.3.4",
316
317
  "v2.2.2",
317
318
  "v2.1.2",
318
- "v2.0.5"
319
319
  ]
320
+ rails_versions << "v2.0.5" if RUBY_VERSION =~ /^1\.8/
320
321
 
321
322
  namespace :test do
322
323
  desc "Test all supported versions of rails. This takes a while."
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.13
1
+ 2.2.14
@@ -483,7 +483,9 @@ END
483
483
  # @param text [String] The string to sanitize
484
484
  # @return [String] The sanitized string
485
485
  def escape_once(text)
486
- text.to_s.gsub(/[\"><]|&(?!(?:[a-zA-Z]+|(#\d+));)/n) {|s| HTML_ESCAPE[s]}
486
+ Haml::Util.silence_warnings do
487
+ text.to_s.gsub(/[\"><]|&(?!(?:[a-zA-Z]+|(#\d+));)/n) {|s| HTML_ESCAPE[s]}
488
+ end
487
489
  end
488
490
 
489
491
  # Returns whether or not the current template is a Haml template.
@@ -152,10 +152,7 @@ module Haml
152
152
  end
153
153
 
154
154
  version = " #{version}" if version
155
- if strictness
156
- strictness[0] = strictness[0] - 32
157
- strictness = " #{strictness}"
158
- end
155
+ strictness = " #{strictness.capitalize}" if strictness
159
156
 
160
157
  "#{tabulate(tabs)}!!!#{version}#{strictness}\n"
161
158
  end
@@ -82,7 +82,7 @@ module Haml
82
82
  MID_BLOCK_KEYWORD_REGEX = /^-\s*(#{%w[else elsif rescue ensure when end].join('|')})\b/
83
83
 
84
84
  # The Regex that matches a Doctype command.
85
- DOCTYPE_REGEX = /(\d\.\d)?[\s]*([a-z]*)/i
85
+ DOCTYPE_REGEX = /(\d(?:\.\d)?)?[\s]*([a-z]*)/i
86
86
 
87
87
  # The Regex that matches a literal string or symbol value
88
88
  LITERAL_VALUE_REGEX = /:(\w*)|(["'])((?![\\#]|\2).|\\.)*\2/
@@ -848,6 +848,8 @@ END
848
848
  if xhtml?
849
849
  if version == "1.1"
850
850
  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
851
+ elsif version == "5"
852
+ '<!DOCTYPE html>'
851
853
  else
852
854
  case type
853
855
  when "strict"; '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
@@ -1,6 +1,7 @@
1
1
  require 'erb'
2
2
  require 'set'
3
3
  require 'enumerator'
4
+ require 'stringio'
4
5
 
5
6
  module Haml
6
7
  # A module containing various useful functions.
@@ -122,6 +123,16 @@ module Haml
122
123
  end
123
124
  end
124
125
 
126
+ # Silence all output to STDERR within a block.
127
+ #
128
+ # @yield A block in which no output will be printed to STDERR
129
+ def silence_warnings
130
+ the_real_stderr, $stderr = $stderr, StringIO.new
131
+ yield
132
+ ensure
133
+ $stderr = the_real_stderr
134
+ end
135
+
125
136
  ## Cross Rails Version Compatibility
126
137
 
127
138
  # Returns the root of the Rails application,
@@ -1,4 +1,4 @@
1
- require 'sass/engine'
1
+ require 'sass'
2
2
 
3
3
  module Sass
4
4
  # This module handles the compilation of Sass files.
@@ -7,7 +7,9 @@ module Sass
7
7
  #
8
8
  # This module is used as the primary interface with Sass
9
9
  # when it's used as a plugin for various frameworks.
10
- # Currently Rails and Merb are supported out of the box.
10
+ # All Rack-enabled frameworks are supported out of the box.
11
+ # The plugin is {file:SASS_REFERENCE.md#rails_merb_plugin automatically activated for Rails and Merb}.
12
+ # Other frameworks must enable it explicitly; see {Sass::Plugin::Rack}.
11
13
  module Plugin
12
14
  extend self
13
15
 
@@ -27,11 +27,7 @@ unless defined?(Sass::MERB_LOADED)
27
27
 
28
28
  class Merb::Rack::Application
29
29
  def call_with_sass(env)
30
- if !Sass::Plugin.checked_for_updates ||
31
- Sass::Plugin.options[:always_update] || Sass::Plugin.options[:always_check]
32
- Sass::Plugin.update_stylesheets
33
- end
34
-
30
+ Sass::Plugin.check_for_updates
35
31
  call_without_sass(env)
36
32
  end
37
33
  alias_method :call_without_sass, :call
@@ -42,11 +38,7 @@ unless defined?(Sass::MERB_LOADED)
42
38
 
43
39
  class MerbHandler
44
40
  def process_with_sass(request, response)
45
- if !Sass::Plugin.checked_for_updates ||
46
- Sass::Plugin.options[:always_update] || Sass::Plugin.options[:always_check]
47
- Sass::Plugin.update_stylesheets
48
- end
49
-
41
+ Sass::Plugin.check_for_updates
50
42
  process_without_sass(request, response)
51
43
  end
52
44
  alias_method :process_without_sass, :process
@@ -0,0 +1,65 @@
1
+ require 'sass/plugin'
2
+
3
+ module Sass
4
+ module Plugin
5
+ # Rack middleware for compiling Sass code.
6
+ #
7
+ # ## Activate
8
+ #
9
+ # require 'sass/plugin/rack'
10
+ # use Sass::Plugin::Rack
11
+ #
12
+ # ## Customize
13
+ #
14
+ # Sass::Plugin.options.merge(
15
+ # :cache_location => './tmp/sass-cache',
16
+ # :never_update => environment != :production,
17
+ # :full_exception => environment != :production)
18
+ #
19
+ # {file:SASS_REFERENCE.md#options See the Reference for more options}.
20
+ #
21
+ # ## Use
22
+ #
23
+ # Put your Sass files in `public/stylesheets/sass`.
24
+ # Your CSS will be generated in `public/stylesheets`,
25
+ # and regenerated every request if necessary.
26
+ # The locations and frequency {file:SASS_REFERENCE.md#options can be customized}.
27
+ # That's all there is to it!
28
+ class Rack
29
+ # Initialize the middleware.
30
+ #
31
+ # @param app [#call] The Rack application
32
+ def initialize(app)
33
+ @app = app
34
+ self.class.disable_native_plugin!
35
+ end
36
+
37
+ # Process a request, checking the Sass stylesheets for changes
38
+ # and updating them if necessary.
39
+ #
40
+ # @param env The Rack request environment
41
+ # @return [(#to_i, Hash<String, String>, Object)] The Rack response
42
+ def call(env)
43
+ Sass::Plugin.check_for_updates
44
+ @app.call(env)
45
+ end
46
+
47
+ # Disable the native Rails or Merb plugins, if they're enabled.
48
+ # This is automatically done once the Rack plugin is activated.
49
+ # This is done so that the stylesheets aren't checked twice for each request.
50
+ def self.disable_native_plugin!
51
+ if defined?(Merb::Rack::Application) &&
52
+ Haml::Util.has?(:instance_method, Merb::Rack::Application, :call_without_sass)
53
+ Merb::Rack::Application.instance_eval {alias_method :call, :call_without_sass}
54
+ end
55
+
56
+ if defined?(ActionDispatch::Callbacks.to_prepare)
57
+ ActionDispatch::Callbacks.skip_callback(:prepare, :__sass_process)
58
+ elsif defined?(ActionController::Base) &&
59
+ Haml::Util.has?(:instance_method, ActionController::Base, :sass_old_process)
60
+ ActionController::Base.instance_eval {alias_method :process, :sass_old_process}
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -9,7 +9,7 @@ unless defined?(Sass::RAILS_LOADED)
9
9
 
10
10
  if defined?(ActionDispatch::Callbacks.to_prepare)
11
11
  # Rails >= 3.0.0
12
- ActionDispatch::Callbacks.to_prepare {Sass::Plugin.check_for_updates}
12
+ ActionDispatch::Callbacks.to_prepare(:sass_process) {Sass::Plugin.check_for_updates}
13
13
  else
14
14
  module ActionController
15
15
  class Base
@@ -36,6 +36,25 @@ module Sass::Script
36
36
  super(rgb)
37
37
  end
38
38
 
39
+ # @deprecated This will be removed in version 2.6.
40
+ # @see #rgb
41
+ def value
42
+ warn <<END
43
+ DEPRECATION WARNING:
44
+ The Sass::Script::Color #value attribute is deprecated and will be
45
+ removed in version 2.6. Use the #rgb attribute instead.
46
+ END
47
+ rgb
48
+ end
49
+
50
+ # Returns the red, green, and blue components of the color.
51
+ #
52
+ # @return [Array<Fixnum>] A three-element array of the red, green, and blue
53
+ # values (respectively) of the color
54
+ def rgb
55
+ @value
56
+ end
57
+
39
58
  # The SassScript `+` operation.
40
59
  # Its functionality depends on the type of its argument:
41
60
  #
@@ -157,8 +176,8 @@ module Sass::Script
157
176
  #
158
177
  # @return [String] The string representation
159
178
  def to_s
160
- return HTML4_COLORS_REVERSE[@value] if HTML4_COLORS_REVERSE[@value]
161
- red, green, blue = @value.map { |num| num.to_s(16).rjust(2, '0') }
179
+ return HTML4_COLORS_REVERSE[rgb] if HTML4_COLORS_REVERSE[rgb]
180
+ red, green, blue = rgb.map { |num| num.to_s(16).rjust(2, '0') }
162
181
  "##{red}#{green}#{blue}"
163
182
  end
164
183
  alias_method :inspect, :to_s
@@ -167,17 +186,16 @@ module Sass::Script
167
186
 
168
187
  def piecewise(other, operation)
169
188
  other_num = other.is_a? Number
170
- other_val = other.value
171
189
  if other_num && !other.unitless?
172
190
  raise Sass::SyntaxError.new("Cannot add a number with units (#{other}) to a color (#{self}).")
173
191
  end
174
192
 
175
- rgb = []
193
+ result = []
176
194
  for i in (0...3)
177
- res = @value[i].send(operation, other_num ? other_val : other_val[i])
178
- rgb[i] = [ [res, 255].min, 0 ].max
195
+ res = rgb[i].send(operation, other_num ? other.value : other.rgb[i])
196
+ result[i] = [ [res, 255].min, 0 ].max
179
197
  end
180
- Color.new(rgb)
198
+ Color.new(result)
181
199
  end
182
200
  end
183
201
  end
@@ -42,7 +42,7 @@ module Sass
42
42
 
43
43
  return Functions::EvaluationContext.new(environment.options).send(name, *args)
44
44
  rescue ArgumentError => e
45
- raise e unless e.backtrace.first =~ /:in `(block in )?(#{name}|perform)'$/
45
+ raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/}
46
46
  raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
47
47
  end
48
48
  end
@@ -11,6 +11,9 @@ module Sass::Script
11
11
  # \{#hsl}
12
12
  # : Converts an `hsl(hue, saturation, lightness)` triplet into a color.
13
13
  #
14
+ # \{#rgb}
15
+ # : Converts an `rgb(red, green, blue)` triplet into a color.
16
+ #
14
17
  # \{#percentage}
15
18
  # : Converts a unitless number to a percentage.
16
19
  #
@@ -26,10 +29,28 @@ module Sass::Script
26
29
  # \{#abs}
27
30
  # : Returns the absolute value of a number.
28
31
  #
29
- # You can add your own functions to this module,
30
- # but there are a few things to keep in mind.
32
+ # These functions are described in more detail below.
33
+ #
34
+ # ## Adding Custom Functions
35
+ #
36
+ # New Sass functions can be added by adding Ruby methods to this module.
37
+ # For example:
38
+ #
39
+ # module Sass::Script::Functions
40
+ # def reverse(string)
41
+ # assert_type string, :String
42
+ # Sass::Script::String.new(string.value.reverse)
43
+ # end
44
+ # end
45
+ #
46
+ # There are a few things to keep in mind when modifying this module.
31
47
  # First of all, the arguments passed are {Sass::Script::Literal} objects.
32
48
  # Literal objects are also expected to be returned.
49
+ # This means that Ruby values must be unwrapped and wrapped.
50
+ #
51
+ # Most Literal objects support the {Sass::Script::Literal#value value} accessor
52
+ # for getting their Ruby values.
53
+ # Color objects, though, must be accessed using {Sass::Script::Color#rgb rgb}.
33
54
  #
34
55
  # Second, making Ruby functions accessible from Sass introduces the temptation
35
56
  # to do things like database access within stylesheets.
@@ -57,6 +78,22 @@ module Sass::Script
57
78
  def initialize(options)
58
79
  @options = options
59
80
  end
81
+
82
+ # Asserts that the type of a given SassScript value
83
+ # is the expected type (designated by a symbol).
84
+ # For example:
85
+ #
86
+ # assert_type value, :String
87
+ # assert_type value, :Number
88
+ #
89
+ # Valid types are `:Bool`, `:Color`, `:Number`, and `:String`.
90
+ #
91
+ # @param value [Sass::Script::Literal] A SassScript value
92
+ # @param type [Symbol] The name of the type the value is expected to be
93
+ def assert_type(value, type)
94
+ return if value.is_a?(Sass::Script.const_get(type))
95
+ raise ArgumentError.new("#{value.inspect} is not a #{type.to_s.downcase}")
96
+ end
60
97
  end
61
98
 
62
99
  instance_methods.each { |m| undef_method m unless m.to_s =~ /^__/ }
@@ -64,21 +101,34 @@ module Sass::Script
64
101
 
65
102
  # Creates a {Color} object from red, green, and blue values.
66
103
  # @param red
67
- # A number between 0 and 255 inclusive
104
+ # A number between 0 and 255 inclusive,
105
+ # or between 0% and 100% inclusive
68
106
  # @param green
69
- # A number between 0 and 255 inclusive
107
+ # A number between 0 and 255 inclusive,
108
+ # or between 0% and 100% inclusive
70
109
  # @param blue
71
- # A number between 0 and 255 inclusive
110
+ # A number between 0 and 255 inclusive,
111
+ # or between 0% and 100% inclusive
72
112
  def rgb(red, green, blue)
73
- [red.value, green.value, blue.value].each do |v|
74
- next unless v < 0 || v > 255
75
- raise ArgumentError.new("Color value #{v} must be between 0 and 255 inclusive")
113
+ assert_type red, :Number
114
+ assert_type green, :Number
115
+ assert_type blue, :Number
116
+
117
+ rgb = [red, green, blue].map do |c|
118
+ v = c.value
119
+ if c.numerator_units == ["%"] && c.denominator_units.empty?
120
+ next v * 255 / 100.0 if (0..100).include?(v)
121
+ raise ArgumentError.new("Color value #{c} must be between 0% and 100% inclusive")
122
+ else
123
+ next v if (0..255).include?(v)
124
+ raise ArgumentError.new("Color value #{v} must be between 0 and 255 inclusive")
125
+ end
76
126
  end
77
- Color.new([red.value, green.value, blue.value])
127
+ Color.new(rgb)
78
128
  end
79
129
 
80
- # Creates a {Color} object from hue, saturation, and lightness
81
- # as per the CSS3 spec (http://www.w3.org/TR/css3-color/#hsl-color).
130
+ # Creates a {Color} object from hue, saturation, and lightness.
131
+ # Uses the algorithm from the [CSS3 spec](http://www.w3.org/TR/css3-color/#hsl-color).
82
132
  #
83
133
  # @param hue [Number] The hue of the color.
84
134
  # Should be between 0 and 360 degrees, inclusive
@@ -89,6 +139,10 @@ module Sass::Script
89
139
  # @return [Color] The resulting color
90
140
  # @raise [ArgumentError] if `saturation` or `lightness` are out of bounds
91
141
  def hsl(hue, saturation, lightness)
142
+ assert_type hue, :Number
143
+ assert_type saturation, :Number
144
+ assert_type lightness, :Number
145
+
92
146
  original_s = saturation
93
147
  original_l = lightness
94
148
  # This algorithm is from http://www.w3.org/TR/css3-color#hsl-color
@@ -117,7 +171,7 @@ module Sass::Script
117
171
  # @raise [ArgumentError] If `value` isn't a unitless number
118
172
  def percentage(value)
119
173
  unless value.is_a?(Sass::Script::Number) && value.unitless?
120
- raise ArgumentError.new("#{value} is not a unitless number")
174
+ raise ArgumentError.new("#{value.inspect} is not a unitless number")
121
175
  end
122
176
  Sass::Script::Number.new(value.value * 100, ['%'])
123
177
  end
@@ -180,10 +234,7 @@ module Sass::Script
180
234
  # another numeric value with the same units.
181
235
  # It yields a number to a block to perform the operation and return a number
182
236
  def numeric_transformation(value)
183
- unless value.is_a?(Sass::Script::Number)
184
- calling_function = caller.first.scan(/`([^']+)'/).first.first
185
- raise Sass::SyntaxError.new("#{value} is not a number for `#{calling_function}'")
186
- end
237
+ assert_type value, :Number
187
238
  Sass::Script::Number.new(yield(value.value), value.numerator_units, value.denominator_units)
188
239
  end
189
240
 
@@ -53,8 +53,8 @@ module Sass
53
53
  REGULAR_EXPRESSIONS = {
54
54
  :whitespace => /\s*/,
55
55
  :variable => /!(\w+)/,
56
- :ident => /(\\.|\#\{|[^\s\\+\-*\/%(),=!])+/,
57
- :string_end => /((?:\\.|\#[^{]|[^"\\#])*)(?:"|(?=#\{))/,
56
+ :ident => /(\\.|[^\s\\+\-*\/%(),=!])+/,
57
+ :string_end => /((?:\\.|\#(?!\{)|[^"\\#])*)(?:"|(?=#\{))/,
58
58
  :number => /(-)?(?:(\d*\.\d+)|(\d+))([a-zA-Z%]+)?/,
59
59
  :color => /\##{"([0-9a-fA-F]{1,2})" * 3}|(#{Color::HTML4_COLORS.keys.join("|")})/,
60
60
  :bool => /(true|false)\b/,
@@ -729,6 +729,7 @@ HAML
729
729
  def test_doctypes
730
730
  assert_equal('<!DOCTYPE html>',
731
731
  render('!!!', :format => :html5).strip)
732
+ assert_equal('<!DOCTYPE html>', render('!!! 5').strip)
732
733
  assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
733
734
  render('!!! strict').strip)
734
735
  assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
@@ -1033,6 +1034,11 @@ END
1033
1034
  assert_equal("<a></a>\n", render('%a{:b => "a #{1 + 1} b", :c => "d"}', :suppress_eval => true))
1034
1035
  end
1035
1036
 
1037
+ def test_utf8_attrs
1038
+ assert_equal("<a href='héllo'></a>\n", render("%a{:href => 'héllo'}"))
1039
+ assert_equal("<a href='héllo'></a>\n", render("%a(href='héllo')"))
1040
+ end
1041
+
1036
1042
  # HTML 4.0
1037
1043
 
1038
1044
  def test_html_has_no_self_closing_tags
@@ -112,6 +112,15 @@ HTML
112
112
  render_rhtml('<p foo="<%= "#{bar} baz" %>"></p>'))
113
113
  end
114
114
 
115
+ # Regression Tests
116
+
117
+ def test_xhtml_strict_doctype
118
+ assert_equal('!!! Strict', render(<<HTML))
119
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
120
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
121
+ HTML
122
+ end
123
+
115
124
  protected
116
125
 
117
126
  def render(text, options = {})
@@ -59,6 +59,16 @@ class UtilTest < Test::Unit::TestCase
59
59
  merge_adjacent_strings(["foo ", "bar ", "baz", :bang, "biz", " bop", 12]))
60
60
  end
61
61
 
62
+ def test_silence_warnings
63
+ old_stderr, $stderr = $stderr, StringIO.new
64
+ warn "Out"
65
+ assert_equal("Out\n", $stderr.string)
66
+ silence_warnings {warn "In"}
67
+ assert_equal("Out\n", $stderr.string)
68
+ ensure
69
+ $stderr = old_stderr
70
+ end
71
+
62
72
  def test_has
63
73
  assert(has?(:instance_method, String, :chomp!))
64
74
  assert(has?(:private_instance_method, Haml::Engine, :set_locals))
@@ -48,13 +48,22 @@ class SassFunctionTest < Test::Unit::TestCase
48
48
  assert_error_message("Lightness 256 must be between 0% and 100% for `hsl'", "hsl(10, 10, 256%)");
49
49
  end
50
50
 
51
+ def test_hsl_checks_types
52
+ assert_error_message("\"foo\" is not a number for `hsl'", "hsl(\"foo\", 10, 12)");
53
+ assert_error_message("\"foo\" is not a number for `hsl'", "hsl(10, \"foo\", 12)");
54
+ assert_error_message("\"foo\" is not a number for `hsl'", "hsl(10, 10, \"foo\")");
55
+ end
56
+
51
57
  def test_percentage
52
58
  assert_equal("50%", evaluate("percentage(.5)"))
53
59
  assert_equal("100%", evaluate("percentage(1)"))
54
60
  assert_equal("25%", evaluate("percentage(25px / 100px)"))
61
+ end
62
+
63
+ def test_percentage_checks_types
55
64
  assert_error_message("25px is not a unitless number for `percentage'", "percentage(25px)")
56
65
  assert_error_message("#cccccc is not a unitless number for `percentage'", "percentage(#ccc)")
57
- assert_error_message("string is not a unitless number for `percentage'", %Q{percentage("string")})
66
+ assert_error_message("\"string\" is not a unitless number for `percentage'", %Q{percentage("string")})
58
67
  end
59
68
 
60
69
  def test_round
@@ -69,14 +78,14 @@ class SassFunctionTest < Test::Unit::TestCase
69
78
  assert_equal("4", evaluate("floor(4.8)"))
70
79
  assert_equal("4px", evaluate("floor(4.8px)"))
71
80
 
72
- assert_error_message("foo is not a number for `floor'", "floor(\"foo\")")
81
+ assert_error_message("\"foo\" is not a number for `floor'", "floor(\"foo\")")
73
82
  end
74
83
 
75
84
  def test_ceil
76
85
  assert_equal("5", evaluate("ceil(4.1)"))
77
86
  assert_equal("5px", evaluate("ceil(4.8px)"))
78
87
 
79
- assert_error_message("a is not a number for `ceil'", "ceil(\"a\")")
88
+ assert_error_message("\"a\" is not a number for `ceil'", "ceil(\"a\")")
80
89
  end
81
90
 
82
91
  def test_abs
@@ -92,7 +101,16 @@ class SassFunctionTest < Test::Unit::TestCase
92
101
  assert_equal("#123456", evaluate("rgb(18, 52, 86)"))
93
102
  assert_equal("#beaded", evaluate("rgb(190, 173, 237)"))
94
103
  assert_equal("#00ff7f", evaluate("rgb(0, 255, 127)"))
104
+ end
95
105
 
106
+ def test_rgb_percent
107
+ assert_equal("#123456", evaluate("rgb(7.1%, 20.4%, 34%)"))
108
+ assert_equal("#beaded", evaluate("rgb(74.7%, 173, 93%)"))
109
+ assert_equal("#beaded", evaluate("rgb(190, 68%, 237)"))
110
+ assert_equal("#00ff7f", evaluate("rgb(0%, 100%, 50%)"))
111
+ end
112
+
113
+ def test_rgb_tests_bounds
96
114
  assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgb'",
97
115
  "rgb(256, 1, 1)")
98
116
  assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgb'",
@@ -105,11 +123,26 @@ class SassFunctionTest < Test::Unit::TestCase
105
123
  "rgb(-1, 1, 1)")
106
124
  end
107
125
 
126
+ def test_rgb_test_percent_bounds
127
+ assert_error_message("Color value 100.1% must be between 0% and 100% inclusive for `rgb'",
128
+ "rgb(100.1%, 0, 0)")
129
+ assert_error_message("Color value -0.1% must be between 0% and 100% inclusive for `rgb'",
130
+ "rgb(0, -0.1%, 0)")
131
+ assert_error_message("Color value 101% must be between 0% and 100% inclusive for `rgb'",
132
+ "rgb(0, 0, 101%)")
133
+ end
134
+
135
+ def test_rgb_tests_types
136
+ assert_error_message("\"foo\" is not a number for `rgb'", "rgb(\"foo\", 10, 12)");
137
+ assert_error_message("\"foo\" is not a number for `rgb'", "rgb(10, \"foo\", 12)");
138
+ assert_error_message("\"foo\" is not a number for `rgb'", "rgb(10, 10, \"foo\")");
139
+ end
140
+
108
141
  private
109
142
 
110
143
  def assert_rgb_hsl(rgb, hsl)
111
144
  hsl = hsl.map {|v| Sass::Script::Parser.parse v, 0, 0 }
112
- assert_equal(rgb, Sass::Script::Functions::EvaluationContext.new({}).hsl(*hsl).value)
145
+ assert_equal(rgb, Sass::Script::Functions::EvaluationContext.new({}).hsl(*hsl).rgb)
113
146
  end
114
147
 
115
148
  def evaluate(value)
@@ -225,6 +225,12 @@ WARN
225
225
  assert_equal "true", resolve("1.1cm == 11mm")
226
226
  end
227
227
 
228
+ # Regression tests
229
+
230
+ def test_interpolation_after_hash
231
+ assert_equal "#2", resolve('"##{1 + 1}"')
232
+ end
233
+
228
234
  private
229
235
 
230
236
  def resolve(str, opts = {}, environment = env)
@@ -29,10 +29,7 @@ class Test::Unit::TestCase
29
29
  $stderr = the_real_stderr
30
30
  end
31
31
 
32
- def silence_warnings
33
- the_real_stderr, $stderr = $stderr, StringIO.new
34
- yield
35
- ensure
36
- $stderr = the_real_stderr
32
+ def silence_warnings(&block)
33
+ Haml::Util.silence_warnings(&block)
37
34
  end
38
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.13
4
+ version: 2.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-11-09 00:00:00 -08:00
13
+ date: 2009-11-22 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -43,200 +43,201 @@ executables:
43
43
  extensions: []
44
44
 
45
45
  extra_rdoc_files:
46
- - VERSION_NAME
47
- - CONTRIBUTING
48
- - README.md
49
- - MIT-LICENSE
50
46
  - VERSION
47
+ - MIT-LICENSE
48
+ - README.md
49
+ - VERSION_NAME
51
50
  - REVISION
51
+ - CONTRIBUTING
52
52
  files:
53
53
  - rails/init.rb
54
54
  - lib/sass.rb
55
- - lib/sass/css.rb
56
- - lib/sass/script/node.rb
57
- - lib/sass/script/number.rb
58
- - lib/sass/script/operation.rb
59
- - lib/sass/script/literal.rb
60
- - lib/sass/script/functions.rb
61
- - lib/sass/script/bool.rb
62
- - lib/sass/script/color.rb
63
- - lib/sass/script/lexer.rb
64
- - lib/sass/script/parser.rb
65
- - lib/sass/script/variable.rb
66
- - lib/sass/script/string.rb
67
- - lib/sass/script/funcall.rb
68
- - lib/sass/script/unary_operation.rb
55
+ - lib/sass/plugin/rails.rb
56
+ - lib/sass/plugin/rack.rb
57
+ - lib/sass/plugin/merb.rb
69
58
  - lib/sass/script.rb
70
59
  - lib/sass/error.rb
71
- - lib/sass/repl.rb
72
- - lib/sass/tree/comment_node.rb
73
- - lib/sass/tree/node.rb
74
60
  - lib/sass/tree/for_node.rb
75
- - lib/sass/tree/debug_node.rb
76
- - lib/sass/tree/import_node.rb
77
- - lib/sass/tree/while_node.rb
78
- - lib/sass/tree/mixin_def_node.rb
79
- - lib/sass/tree/if_node.rb
80
61
  - lib/sass/tree/mixin_node.rb
81
- - lib/sass/tree/directive_node.rb
82
- - lib/sass/tree/rule_node.rb
62
+ - lib/sass/tree/if_node.rb
83
63
  - lib/sass/tree/prop_node.rb
64
+ - lib/sass/tree/mixin_def_node.rb
84
65
  - lib/sass/tree/variable_node.rb
85
- - lib/sass/plugin/rails.rb
86
- - lib/sass/plugin/merb.rb
87
- - lib/sass/environment.rb
66
+ - lib/sass/tree/debug_node.rb
67
+ - lib/sass/tree/directive_node.rb
68
+ - lib/sass/tree/node.rb
69
+ - lib/sass/tree/comment_node.rb
70
+ - lib/sass/tree/rule_node.rb
71
+ - lib/sass/tree/import_node.rb
72
+ - lib/sass/tree/while_node.rb
88
73
  - lib/sass/files.rb
89
- - lib/sass/engine.rb
90
74
  - lib/sass/plugin.rb
91
- - lib/haml/filters.rb
75
+ - lib/sass/script/parser.rb
76
+ - lib/sass/script/color.rb
77
+ - lib/sass/script/string.rb
78
+ - lib/sass/script/unary_operation.rb
79
+ - lib/sass/script/number.rb
80
+ - lib/sass/script/funcall.rb
81
+ - lib/sass/script/variable.rb
82
+ - lib/sass/script/functions.rb
83
+ - lib/sass/script/bool.rb
84
+ - lib/sass/script/lexer.rb
85
+ - lib/sass/script/operation.rb
86
+ - lib/sass/script/node.rb
87
+ - lib/sass/script/literal.rb
88
+ - lib/sass/css.rb
89
+ - lib/sass/engine.rb
90
+ - lib/sass/repl.rb
91
+ - lib/sass/environment.rb
92
+ - lib/haml/util.rb
92
93
  - lib/haml/exec.rb
94
+ - lib/haml/html.rb
93
95
  - lib/haml/error.rb
96
+ - lib/haml/buffer.rb
94
97
  - lib/haml/template.rb
95
- - lib/haml/shared.rb
96
- - lib/haml/engine.rb
97
- - lib/haml/version.rb
98
- - lib/haml/template/patch.rb
99
98
  - lib/haml/template/plugin.rb
99
+ - lib/haml/template/patch.rb
100
100
  - lib/haml/helpers.rb
101
- - lib/haml/buffer.rb
102
- - lib/haml/html.rb
101
+ - lib/haml/version.rb
102
+ - lib/haml/filters.rb
103
+ - lib/haml/engine.rb
103
104
  - lib/haml/precompiler.rb
104
- - lib/haml/util.rb
105
+ - lib/haml/shared.rb
106
+ - lib/haml/helpers/action_view_extensions.rb
105
107
  - lib/haml/helpers/action_view_mods.rb
106
108
  - lib/haml/helpers/xss_mods.rb
107
- - lib/haml/helpers/action_view_extensions.rb
108
109
  - lib/haml.rb
109
- - bin/sass
110
110
  - bin/css2sass
111
- - bin/html2haml
111
+ - bin/sass
112
112
  - bin/haml
113
- - test/linked_rails.rb
114
- - test/benchmark.rb
113
+ - bin/html2haml
115
114
  - test/sass/script_test.rb
116
- - test/sass/css2sass_test.rb
117
- - test/sass/results/units.css
118
- - test/sass/results/parent_ref.css
119
- - test/sass/results/compressed.css
120
- - test/sass/results/complex.css
121
- - test/sass/results/compact.css
122
- - test/sass/results/mixins.css
123
- - test/sass/results/line_numbers.css
124
- - test/sass/results/alt.css
125
- - test/sass/results/subdir/subdir.css
126
- - test/sass/results/subdir/nested_subdir/nested_subdir.css
127
- - test/sass/results/nested.css
128
- - test/sass/results/import.css
129
- - test/sass/results/multiline.css
130
- - test/sass/results/script.css
131
- - test/sass/results/basic.css
132
- - test/sass/results/expanded.css
133
- - test/sass/more_results/more_import.css
134
115
  - test/sass/more_results/more1_with_line_comments.css
135
116
  - test/sass/more_results/more1.css
136
- - test/sass/templates/basic.sass
137
- - test/sass/templates/bork.sass
117
+ - test/sass/more_results/more_import.css
118
+ - test/sass/templates/bork2.sass
138
119
  - test/sass/templates/compressed.sass
139
- - test/sass/templates/import.sass
140
- - test/sass/templates/script.sass
141
120
  - test/sass/templates/expanded.sass
142
- - test/sass/templates/nested.sass
121
+ - test/sass/templates/import.sass
122
+ - test/sass/templates/subdir/subdir.sass
123
+ - test/sass/templates/subdir/nested_subdir/_nested_partial.sass
124
+ - test/sass/templates/subdir/nested_subdir/nested_subdir.sass
125
+ - test/sass/templates/basic.sass
143
126
  - test/sass/templates/_partial.sass
127
+ - test/sass/templates/units.sass
128
+ - test/sass/templates/mixins.sass
129
+ - test/sass/templates/multiline.sass
144
130
  - test/sass/templates/line_numbers.sass
131
+ - test/sass/templates/nested.sass
145
132
  - test/sass/templates/compact.sass
146
- - test/sass/templates/subdir/subdir.sass
147
- - test/sass/templates/subdir/nested_subdir/nested_subdir.sass
148
- - test/sass/templates/subdir/nested_subdir/_nested_partial.sass
149
- - test/sass/templates/parent_ref.sass
150
133
  - test/sass/templates/alt.sass
134
+ - test/sass/templates/script.sass
151
135
  - test/sass/templates/importee.sass
152
- - test/sass/templates/mixins.sass
153
- - test/sass/templates/multiline.sass
154
- - test/sass/templates/units.sass
136
+ - test/sass/templates/parent_ref.sass
137
+ - test/sass/templates/bork.sass
155
138
  - test/sass/templates/complex.sass
156
- - test/sass/templates/bork2.sass
157
- - test/sass/more_templates/_more_partial.sass
139
+ - test/sass/css2sass_test.rb
140
+ - test/sass/plugin_test.rb
158
141
  - test/sass/more_templates/more1.sass
159
142
  - test/sass/more_templates/more_import.sass
143
+ - test/sass/more_templates/_more_partial.sass
160
144
  - test/sass/functions_test.rb
145
+ - test/sass/results/nested.css
146
+ - test/sass/results/units.css
147
+ - test/sass/results/script.css
148
+ - test/sass/results/subdir/nested_subdir/nested_subdir.css
149
+ - test/sass/results/subdir/subdir.css
150
+ - test/sass/results/import.css
151
+ - test/sass/results/compact.css
152
+ - test/sass/results/expanded.css
153
+ - test/sass/results/alt.css
154
+ - test/sass/results/mixins.css
155
+ - test/sass/results/complex.css
156
+ - test/sass/results/compressed.css
157
+ - test/sass/results/parent_ref.css
158
+ - test/sass/results/line_numbers.css
159
+ - test/sass/results/multiline.css
160
+ - test/sass/results/basic.css
161
161
  - test/sass/engine_test.rb
162
- - test/sass/plugin_test.rb
163
162
  - test/haml/mocks/article.rb
164
- - test/haml/rhtml/_av_partial_2.rhtml
165
- - test/haml/rhtml/standard.rhtml
166
- - test/haml/rhtml/_av_partial_1.rhtml
167
- - test/haml/rhtml/action_view.rhtml
168
163
  - test/haml/util_test.rb
169
- - test/haml/spec/ruby_haml_test.rb
170
- - test/haml/spec/README.md
171
- - test/haml/spec/lua_haml_spec.lua
172
- - test/haml/spec/tests.json
173
- - test/haml/html2haml_test.rb
174
164
  - test/haml/template_test.rb
165
+ - test/haml/html2haml_test.rb
166
+ - test/haml/rhtml/_av_partial_1.rhtml
167
+ - test/haml/rhtml/standard.rhtml
168
+ - test/haml/rhtml/action_view.rhtml
169
+ - test/haml/rhtml/_av_partial_2.rhtml
175
170
  - test/haml/helper_test.rb
176
- - test/haml/results/tag_parsing.xhtml
177
- - test/haml/results/content_for_layout.xhtml
178
- - test/haml/results/helpers.xhtml
179
- - test/haml/results/original_engine.xhtml
180
- - test/haml/results/very_basic.xhtml
181
- - test/haml/results/helpful.xhtml
182
- - test/haml/results/list.xhtml
183
- - test/haml/results/partials.xhtml
184
- - test/haml/results/eval_suppressed.xhtml
185
- - test/haml/results/nuke_inner_whitespace.xhtml
186
- - test/haml/results/whitespace_handling.xhtml
187
- - test/haml/results/render_layout.xhtml
188
- - test/haml/results/silent_script.xhtml
189
- - test/haml/results/standard.xhtml
190
- - test/haml/results/just_stuff.xhtml
191
- - test/haml/results/partial_layout.xhtml
192
- - test/haml/results/filters.xhtml
193
- - test/haml/results/nuke_outer_whitespace.xhtml
194
- - test/haml/markaby/standard.mab
195
- - test/haml/templates/tag_parsing.haml
196
- - test/haml/templates/nuke_inner_whitespace.haml
171
+ - test/haml/templates/action_view_ugly.haml
172
+ - test/haml/templates/list.haml
173
+ - test/haml/templates/_text_area.haml
174
+ - test/haml/templates/_partial.haml
175
+ - test/haml/templates/nuke_outer_whitespace.haml
176
+ - test/haml/templates/render_layout.haml
177
+ - test/haml/templates/_av_partial_2.haml
197
178
  - test/haml/templates/partial_layout.haml
198
- - test/haml/templates/_av_partial_2_ugly.haml
179
+ - test/haml/templates/helpful.haml
180
+ - test/haml/templates/_av_partial_1_ugly.haml
181
+ - test/haml/templates/just_stuff.haml
182
+ - test/haml/templates/standard_ugly.haml
183
+ - test/haml/templates/silent_script.haml
184
+ - test/haml/templates/very_basic.haml
185
+ - test/haml/templates/nuke_inner_whitespace.haml
186
+ - test/haml/templates/eval_suppressed.haml
187
+ - test/haml/templates/tag_parsing.haml
188
+ - test/haml/templates/whitespace_handling.haml
199
189
  - test/haml/templates/partials.haml
190
+ - test/haml/templates/standard.haml
191
+ - test/haml/templates/partialize.haml
200
192
  - test/haml/templates/_layout_for_partial.haml
201
- - test/haml/templates/original_engine.haml
202
- - test/haml/templates/helpers.haml
193
+ - test/haml/templates/_av_partial_1.haml
194
+ - test/haml/templates/filters.haml
203
195
  - test/haml/templates/_layout.erb
204
- - test/haml/templates/action_view_ugly.haml
205
196
  - test/haml/templates/content_for_layout.haml
206
- - test/haml/templates/silent_script.haml
207
- - test/haml/templates/very_basic.haml
208
- - test/haml/templates/render_layout.haml
209
- - test/haml/templates/filters.haml
210
- - test/haml/templates/_av_partial_1.haml
211
- - test/haml/templates/standard_ugly.haml
212
- - test/haml/templates/_partial.haml
213
- - test/haml/templates/nuke_outer_whitespace.haml
197
+ - test/haml/templates/_av_partial_2_ugly.haml
198
+ - test/haml/templates/helpers.haml
199
+ - test/haml/templates/original_engine.haml
214
200
  - test/haml/templates/breakage.haml
215
- - test/haml/templates/list.haml
216
- - test/haml/templates/standard.haml
217
- - test/haml/templates/whitespace_handling.haml
218
- - test/haml/templates/eval_suppressed.haml
219
201
  - test/haml/templates/action_view.haml
220
- - test/haml/templates/_av_partial_2.haml
221
- - test/haml/templates/partialize.haml
222
- - test/haml/templates/just_stuff.haml
223
- - test/haml/templates/helpful.haml
224
- - test/haml/templates/_av_partial_1_ugly.haml
225
- - test/haml/templates/_text_area.haml
202
+ - test/haml/spec/tests.json
203
+ - test/haml/spec/lua_haml_spec.lua
204
+ - test/haml/spec/ruby_haml_test.rb
205
+ - test/haml/spec/README.md
206
+ - test/haml/results/content_for_layout.xhtml
207
+ - test/haml/results/just_stuff.xhtml
208
+ - test/haml/results/whitespace_handling.xhtml
209
+ - test/haml/results/nuke_outer_whitespace.xhtml
210
+ - test/haml/results/silent_script.xhtml
211
+ - test/haml/results/filters.xhtml
212
+ - test/haml/results/standard.xhtml
213
+ - test/haml/results/nuke_inner_whitespace.xhtml
214
+ - test/haml/results/helpful.xhtml
215
+ - test/haml/results/very_basic.xhtml
216
+ - test/haml/results/eval_suppressed.xhtml
217
+ - test/haml/results/partials.xhtml
218
+ - test/haml/results/render_layout.xhtml
219
+ - test/haml/results/original_engine.xhtml
220
+ - test/haml/results/helpers.xhtml
221
+ - test/haml/results/list.xhtml
222
+ - test/haml/results/partial_layout.xhtml
223
+ - test/haml/results/tag_parsing.xhtml
224
+ - test/haml/markaby/standard.mab
226
225
  - test/haml/engine_test.rb
226
+ - test/linked_rails.rb
227
+ - test/benchmark.rb
227
228
  - test/test_helper.rb
228
- - extra/haml-mode.el
229
229
  - extra/sass-mode.el
230
+ - extra/haml-mode.el
230
231
  - extra/update_watch.rb
231
232
  - Rakefile
232
233
  - init.rb
233
234
  - .yardopts
234
- - VERSION_NAME
235
- - CONTRIBUTING
236
- - README.md
237
- - MIT-LICENSE
238
235
  - VERSION
236
+ - MIT-LICENSE
237
+ - README.md
238
+ - VERSION_NAME
239
239
  - REVISION
240
+ - CONTRIBUTING
240
241
  has_rdoc: true
241
242
  homepage: http://haml.hamptoncatlin.com/
242
243
  licenses: []
@@ -268,19 +269,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
269
  requirements: []
269
270
 
270
271
  rubyforge_project: haml
271
- rubygems_version: 1.3.4
272
+ rubygems_version: 1.3.5
272
273
  signing_key:
273
274
  specification_version: 3
274
275
  summary: An elegant, structured XHTML/XML templating engine. Comes with Sass, a similar CSS templating engine.
275
276
  test_files:
276
277
  - test/sass/script_test.rb
277
278
  - test/sass/css2sass_test.rb
279
+ - test/sass/plugin_test.rb
278
280
  - test/sass/functions_test.rb
279
281
  - test/sass/engine_test.rb
280
- - test/sass/plugin_test.rb
281
282
  - test/haml/util_test.rb
282
- - test/haml/spec/ruby_haml_test.rb
283
- - test/haml/html2haml_test.rb
284
283
  - test/haml/template_test.rb
284
+ - test/haml/html2haml_test.rb
285
285
  - test/haml/helper_test.rb
286
+ - test/haml/spec/ruby_haml_test.rb
286
287
  - test/haml/engine_test.rb