haml 3.2.0.rc.2 → 3.2.0.rc.3
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/CHANGELOG.md +10 -0
- data/Rakefile +1 -1
- data/lib/haml/compiler.rb +3 -2
- data/lib/haml/filters.rb +26 -7
- data/lib/haml/helpers.rb +13 -3
- data/lib/haml/helpers/action_view_mods.rb +3 -1
- data/lib/haml/railtie.rb +10 -0
- data/lib/haml/sass_rails_filter.rb +33 -0
- data/lib/haml/version.rb +1 -1
- data/test/engine_test.rb +2 -2
- data/test/filters_test.rb +25 -9
- data/test/helper_test.rb +37 -1
- data/test/util_test.rb +0 -13
- metadata +16 -12
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## 3.2.0 (Unreleased)
|
4
4
|
|
5
|
+
* The Haml exectutable now accepts an `--autoclose` option. You can now
|
6
|
+
specify a list of tags that should be autoclosed
|
7
|
+
|
8
|
+
* The `:ruby` filter no longer redirects $stdout to the Haml document, as this
|
9
|
+
is not thread safe. Instead it provides a `haml_io` local variable, which is
|
10
|
+
an IO object that writes to the document.
|
11
|
+
|
5
12
|
* HTML5 is now the default output format rather than XHTML. This was already
|
6
13
|
the default on Rails 3+, so many users will notice no difference.
|
7
14
|
|
@@ -97,6 +104,9 @@
|
|
97
104
|
|
98
105
|
* Add command-line option to suppress script evaluation.
|
99
106
|
|
107
|
+
* It's now possible to use Rails's asset helpers inside the Sass and SCSS
|
108
|
+
filters.
|
109
|
+
|
100
110
|
## 3.1.6
|
101
111
|
|
102
112
|
* In indented mode, don't reindent buffers that contain preserved tags, and
|
data/Rakefile
CHANGED
@@ -94,7 +94,7 @@ def gemfiles
|
|
94
94
|
@gemfiles ||= begin
|
95
95
|
Dir[File.dirname(__FILE__) + '/test/gemfiles/Gemfile.*'].
|
96
96
|
reject {|f| f =~ /\.lock$/}.
|
97
|
-
reject {|f| RUBY_VERSION
|
97
|
+
reject {|f| RUBY_VERSION < '1.9.3' && f =~ /master/}
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
data/lib/haml/compiler.rb
CHANGED
@@ -314,8 +314,9 @@ END
|
|
314
314
|
def push_silent(text, can_suppress = false)
|
315
315
|
flush_merged_text
|
316
316
|
return if can_suppress && @options.suppress_eval?
|
317
|
-
|
318
|
-
@
|
317
|
+
newline = (text == "end") ? ";" : "\n"
|
318
|
+
@precompiled << "#{resolve_newlines}#{text}#{newline}"
|
319
|
+
@output_line += (text + newline).count("\n")
|
319
320
|
end
|
320
321
|
|
321
322
|
# Adds `text` to `@buffer` with appropriate tabulation
|
data/lib/haml/filters.rb
CHANGED
@@ -58,6 +58,19 @@ module Haml
|
|
58
58
|
filter
|
59
59
|
end
|
60
60
|
|
61
|
+
# Removes a filter from Haml. If the filter was removed, it returns
|
62
|
+
# the that was remove Module upon success, or nil on failure. If you try
|
63
|
+
# to redefine a filter, Haml will raise an error. Use this method first to
|
64
|
+
# explicitly remove the filter before redefining it.
|
65
|
+
# @return Module The filter module that has been removed
|
66
|
+
# @since 3.2.0
|
67
|
+
def remove_filter(name)
|
68
|
+
defined.delete name.downcase
|
69
|
+
if constants.map(&:to_s).include?(name.to_s)
|
70
|
+
remove_const name.to_sym
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
61
74
|
# The base module for Haml filters.
|
62
75
|
# User-defined filters should be modules including this module.
|
63
76
|
# The name of the filter is taken by downcasing the module name.
|
@@ -258,9 +271,13 @@ RUBY
|
|
258
271
|
end
|
259
272
|
end
|
260
273
|
|
261
|
-
# Parses the filtered text with the normal Ruby interpreter.
|
262
|
-
#
|
263
|
-
#
|
274
|
+
# Parses the filtered text with the normal Ruby interpreter. Creates an IO
|
275
|
+
# object named `haml_io`, anything written to it is output into the Haml
|
276
|
+
# document. In previous version this filter redirected any output to `$stdout`
|
277
|
+
# to the Haml document, this was not threadsafe and has been removed, you
|
278
|
+
# should use `haml_io` instead.
|
279
|
+
#
|
280
|
+
# Not available if the {file:REFERENCE.md#suppress_eval-option `:suppress_eval`}
|
264
281
|
# option is set to true. The Ruby code is evaluated in the same context as
|
265
282
|
# the Haml template.
|
266
283
|
module Ruby
|
@@ -272,11 +289,13 @@ RUBY
|
|
272
289
|
return if compiler.options[:suppress_eval]
|
273
290
|
compiler.instance_eval do
|
274
291
|
push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
|
275
|
-
|
276
|
-
|
292
|
+
begin
|
293
|
+
haml_io = StringIO.new(_hamlout.buffer, 'a')
|
277
294
|
FIRST
|
278
|
-
|
279
|
-
|
295
|
+
ensure
|
296
|
+
haml_io.close
|
297
|
+
haml_io = nil
|
298
|
+
end
|
280
299
|
LAST
|
281
300
|
end
|
282
301
|
end
|
data/lib/haml/helpers.rb
CHANGED
@@ -537,7 +537,13 @@ MESSAGE
|
|
537
537
|
# @param text [String] The string to sanitize
|
538
538
|
# @return [String] The sanitized string
|
539
539
|
def html_escape(text)
|
540
|
-
|
540
|
+
pattern = '[\"><&]'
|
541
|
+
regex = if RUBY_VERSION >= '1.9'
|
542
|
+
Regexp.new(pattern.force_encoding(text.encoding), Regexp::FIXEDENCODING)
|
543
|
+
else
|
544
|
+
Regexp.new(pattern)
|
545
|
+
end
|
546
|
+
text.to_s.gsub(regex) {|s| HTML_ESCAPE[s]}
|
541
547
|
end
|
542
548
|
|
543
549
|
# Escapes HTML entities in `text`, but without escaping an ampersand
|
@@ -546,9 +552,13 @@ MESSAGE
|
|
546
552
|
# @param text [String] The string to sanitize
|
547
553
|
# @return [String] The sanitized string
|
548
554
|
def escape_once(text)
|
549
|
-
|
550
|
-
|
555
|
+
pattern = '[\"><]|&(?!(?:[a-zA-Z]+|(#\d+));)'
|
556
|
+
regex = if RUBY_VERSION >= '1.9'
|
557
|
+
Regexp.new(pattern.force_encoding(text.encoding), Regexp::FIXEDENCODING)
|
558
|
+
else
|
559
|
+
Regexp.new(pattern)
|
551
560
|
end
|
561
|
+
text.to_s.gsub(regex) {|s| HTML_ESCAPE[s]}
|
552
562
|
end
|
553
563
|
|
554
564
|
# Returns whether or not the current template is a Haml template.
|
@@ -142,4 +142,6 @@ module ActionView
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
|
145
|
+
if (ActionPack::VERSION::MAJOR == 3) && (ActionPack::VERSION::MINOR >= 2) && (ActionPack::VERSION::TINY >= 3)
|
146
|
+
require "haml/helpers/rails_323_textarea_fix"
|
147
|
+
end
|
data/lib/haml/railtie.rb
CHANGED
@@ -7,5 +7,15 @@ if defined?(ActiveSupport)
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
module Haml
|
11
|
+
class Railtie < ::Rails::Railtie
|
12
|
+
initializer :haml do |app|
|
13
|
+
if defined?(::Sass::Rails) && app.config.assets.enabled
|
14
|
+
require "haml/sass_rails_filter"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
require "haml/helpers/safe_erubis_template"
|
11
21
|
Haml::Filters::Erb.template_class = Haml::SafeErubisTemplate
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Haml
|
2
|
+
module Filters
|
3
|
+
# This is an extension of Sass::Rails's SassTemplate class that allows
|
4
|
+
# Rails's asset helpers to be used inside Haml Sass filter.
|
5
|
+
class SassRailsTemplate < ::Sass::Rails::SassTemplate
|
6
|
+
def render(scope=Object.new, locals={}, &block)
|
7
|
+
scope = ::Rails.application.assets.context_class.new(::Rails.application.assets, "/", "/")
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def sass_options(scope)
|
12
|
+
options = super
|
13
|
+
options[:custom][:resolver] = ::ActionView::Base.new
|
14
|
+
options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# This is an extension of Sass::Rails's SassTemplate class that allows
|
19
|
+
# Rails's asset helpers to be used inside a Haml SCSS filter.
|
20
|
+
class ScssRailsTemplate < SassRailsTemplate
|
21
|
+
self.default_mime_type = 'text/css'
|
22
|
+
|
23
|
+
def syntax
|
24
|
+
:scss
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
remove_filter :Sass
|
29
|
+
remove_filter :Scss
|
30
|
+
register_tilt_filter "Sass", :extend => "Css", :template_class => SassRailsTemplate
|
31
|
+
register_tilt_filter "Scss", :extend => "Css", :template_class => ScssRailsTemplate
|
32
|
+
end
|
33
|
+
end
|
data/lib/haml/version.rb
CHANGED
data/test/engine_test.rb
CHANGED
@@ -1894,7 +1894,7 @@ HAML
|
|
1894
1894
|
assert(false, "Expected exception")
|
1895
1895
|
rescue Haml::Error => e
|
1896
1896
|
assert_equal(3, e.line)
|
1897
|
-
|
1897
|
+
assert_match(/Invalid .* character/, e.message)
|
1898
1898
|
end
|
1899
1899
|
|
1900
1900
|
def test_ascii_incompatible_encoding_error
|
@@ -1904,7 +1904,7 @@ HAML
|
|
1904
1904
|
assert(false, "Expected exception")
|
1905
1905
|
rescue Haml::Error => e
|
1906
1906
|
assert_equal(3, e.line)
|
1907
|
-
|
1907
|
+
assert_match(/Invalid .* character/, e.message)
|
1908
1908
|
end
|
1909
1909
|
|
1910
1910
|
def test_same_coding_comment_as_encoding
|
data/test/filters_test.rb
CHANGED
@@ -7,7 +7,7 @@ class FiltersTest < MiniTest::Unit::TestCase
|
|
7
7
|
Module.new {def self.name; "Foo::Bar"; end; include Haml::Filters::Base}
|
8
8
|
assert Haml::Filters.defined.has_key? "bar"
|
9
9
|
ensure
|
10
|
-
Haml::Filters.
|
10
|
+
Haml::Filters.remove_filter "Bar"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -19,8 +19,7 @@ class FiltersTest < MiniTest::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
ensure
|
22
|
-
Haml::Filters.
|
23
|
-
Haml::Filters.send :remove_const, :Foo
|
22
|
+
Haml::Filters.remove_filter "Foo"
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -31,8 +30,7 @@ class FiltersTest < MiniTest::Unit::TestCase
|
|
31
30
|
Haml::Filters.defined["textile"].template_class
|
32
31
|
end
|
33
32
|
ensure
|
34
|
-
Haml::Filters.
|
35
|
-
Haml::Filters.send :remove_const, :Textile
|
33
|
+
Haml::Filters.remove_filter "Textile"
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
@@ -43,8 +41,7 @@ class FiltersTest < MiniTest::Unit::TestCase
|
|
43
41
|
Haml::Filters.defined["maruku"].template_class
|
44
42
|
end
|
45
43
|
ensure
|
46
|
-
Haml::Filters.
|
47
|
-
Haml::Filters.send :remove_const, :Maruku
|
44
|
+
Haml::Filters.remove_filter "Maruku"
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
@@ -108,8 +105,7 @@ class FiltersTest < MiniTest::Unit::TestCase
|
|
108
105
|
haml = ":foo"
|
109
106
|
assert_equal "foobar\n", render(haml)
|
110
107
|
ensure
|
111
|
-
Haml::Filters.
|
112
|
-
Haml::Filters.send :remove_const, :Foo
|
108
|
+
Haml::Filters.remove_filter "Foo"
|
113
109
|
end
|
114
110
|
end
|
115
111
|
|
@@ -235,4 +231,24 @@ class EscapedFilterTest < MiniTest::Unit::TestCase
|
|
235
231
|
haml = ":escaped\n &"
|
236
232
|
assert_equal(html, render(haml))
|
237
233
|
end
|
234
|
+
end
|
235
|
+
|
236
|
+
class RubyFilterTest < MiniTest::Unit::TestCase
|
237
|
+
test "can write to haml_io" do
|
238
|
+
haml = ":ruby\n haml_io.puts 'hello'\n"
|
239
|
+
html = "hello\n"
|
240
|
+
assert_equal(html, render(haml))
|
241
|
+
end
|
242
|
+
|
243
|
+
test "haml_io appends to output" do
|
244
|
+
haml = "hello\n:ruby\n haml_io.puts 'hello'\n"
|
245
|
+
html = "hello\nhello\n"
|
246
|
+
assert_equal(html, render(haml))
|
247
|
+
end
|
248
|
+
|
249
|
+
test "can create local variables" do
|
250
|
+
haml = ":ruby\n a = 7\n=a"
|
251
|
+
html = "7\n"
|
252
|
+
assert_equal(html, render(haml))
|
253
|
+
end
|
238
254
|
end
|
data/test/helper_test.rb
CHANGED
@@ -132,7 +132,7 @@ HTML
|
|
132
132
|
HAML
|
133
133
|
end
|
134
134
|
|
135
|
-
if
|
135
|
+
if (ActionPack::VERSION::MAJOR == 3) && (ActionPack::VERSION::MINOR >= 2) && (ActionPack::VERSION::TINY >= 3)
|
136
136
|
def test_text_area
|
137
137
|
assert_equal(%(<textarea id="body" name="body">\nFoo
Bar
 Baz
 Boom</textarea>\n),
|
138
138
|
render('= text_area_tag "body", "Foo\nBar\n Baz\n Boom"', :action_view))
|
@@ -458,5 +458,41 @@ HAML
|
|
458
458
|
%div> hi there!
|
459
459
|
HAML
|
460
460
|
end
|
461
|
+
|
462
|
+
def test_html_escape
|
463
|
+
assert_equal ""><&", Haml::Helpers.html_escape('"><&')
|
464
|
+
end
|
465
|
+
|
466
|
+
def test_html_escape_encoding
|
467
|
+
old_stderr, $stderr = $stderr, StringIO.new
|
468
|
+
string = "\"><&\u00e9" # if you're curious, u00e9 is "LATIN SMALL LETTER E WITH ACUTE"
|
469
|
+
assert_equal ""><&\u00e9", Haml::Helpers.html_escape(string)
|
470
|
+
assert $stderr.string == "", "html_escape shouldn't generate warnings with UTF-8 strings: #{$stderr.string}"
|
471
|
+
ensure
|
472
|
+
$stderr = old_stderr
|
473
|
+
end
|
474
|
+
|
475
|
+
def test_escape_once
|
476
|
+
assert_equal ""><&", Haml::Helpers.escape_once('"><&')
|
477
|
+
end
|
478
|
+
|
479
|
+
def test_escape_once_leaves_entity_references
|
480
|
+
assert_equal ""><& ", Haml::Helpers.escape_once('"><& ')
|
481
|
+
end
|
482
|
+
|
483
|
+
def test_escape_once_leaves_numeric_references
|
484
|
+
assert_equal ""><&  ", Haml::Helpers.escape_once('"><&  ') #decimal
|
485
|
+
#assert_equal ""><&  ", Haml::Helpers.escape_once('"><&  ') #hexadecimal
|
486
|
+
end
|
487
|
+
|
488
|
+
def test_escape_once_encoding
|
489
|
+
old_stderr, $stderr = $stderr, StringIO.new
|
490
|
+
string = "\"><&\u00e9 "
|
491
|
+
assert_equal ""><&\u00e9 ", Haml::Helpers.escape_once(string)
|
492
|
+
assert $stderr.string == "", "html_escape shouldn't generate warnings with UTF-8 strings: #{$stderr.string}"
|
493
|
+
ensure
|
494
|
+
$stderr = old_stderr
|
495
|
+
end
|
496
|
+
|
461
497
|
end
|
462
498
|
|
data/test/util_test.rb
CHANGED
@@ -3,19 +3,6 @@ require 'test_helper'
|
|
3
3
|
class UtilTest < MiniTest::Unit::TestCase
|
4
4
|
include Haml::Util
|
5
5
|
|
6
|
-
class Dumpable
|
7
|
-
attr_reader :arr
|
8
|
-
def initialize; @arr = []; end
|
9
|
-
def _before_dump; @arr << :before; end
|
10
|
-
def _after_dump; @arr << :after; end
|
11
|
-
def _around_dump
|
12
|
-
@arr << :around_before
|
13
|
-
yield
|
14
|
-
@arr << :around_after
|
15
|
-
end
|
16
|
-
def _after_load; @arr << :loaded; end
|
17
|
-
end
|
18
|
-
|
19
6
|
def test_powerset
|
20
7
|
return unless Set[Set[]] == Set[Set[]] # There's a bug in Ruby 1.8.6 that breaks nested set equality
|
21
8
|
assert_equal([[].to_set].to_set,
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.0.rc.2
|
5
4
|
prerelease: 6
|
5
|
+
version: 3.2.0.rc.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nathan Weizenbaum
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: tilt
|
@@ -21,14 +21,14 @@ dependencies:
|
|
21
21
|
- - ! '>='
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '0'
|
24
|
-
type: :runtime
|
25
|
-
prerelease: false
|
26
24
|
version_requirements: !ruby/object:Gem::Requirement
|
27
25
|
none: false
|
28
26
|
requirements:
|
29
27
|
- - ! '>='
|
30
28
|
- !ruby/object:Gem::Version
|
31
29
|
version: '0'
|
30
|
+
prerelease: false
|
31
|
+
type: :runtime
|
32
32
|
- !ruby/object:Gem::Dependency
|
33
33
|
name: rails
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
@@ -37,14 +37,14 @@ dependencies:
|
|
37
37
|
- - ! '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: 3.0.0
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
40
|
version_requirements: !ruby/object:Gem::Requirement
|
43
41
|
none: false
|
44
42
|
requirements:
|
45
43
|
- - ! '>='
|
46
44
|
- !ruby/object:Gem::Version
|
47
45
|
version: 3.0.0
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rbench
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,14 +53,14 @@ dependencies:
|
|
53
53
|
- - ! '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
-
type: :development
|
57
|
-
prerelease: false
|
58
56
|
version_requirements: !ruby/object:Gem::Requirement
|
59
57
|
none: false
|
60
58
|
requirements:
|
61
59
|
- - ! '>='
|
62
60
|
- !ruby/object:Gem::Version
|
63
61
|
version: '0'
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: minitest
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,14 +69,14 @@ dependencies:
|
|
69
69
|
- - ! '>='
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
|
-
type: :development
|
73
|
-
prerelease: false
|
74
72
|
version_requirements: !ruby/object:Gem::Requirement
|
75
73
|
none: false
|
76
74
|
requirements:
|
77
75
|
- - ! '>='
|
78
76
|
- !ruby/object:Gem::Version
|
79
77
|
version: '0'
|
78
|
+
prerelease: false
|
79
|
+
type: :development
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: nokogiri
|
82
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,14 +85,14 @@ dependencies:
|
|
85
85
|
- - ! '>='
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
|
-
type: :development
|
89
|
-
prerelease: false
|
90
88
|
version_requirements: !ruby/object:Gem::Requirement
|
91
89
|
none: false
|
92
90
|
requirements:
|
93
91
|
- - ! '>='
|
94
92
|
- !ruby/object:Gem::Version
|
95
93
|
version: '0'
|
94
|
+
prerelease: false
|
95
|
+
type: :development
|
96
96
|
description: ! 'Haml (HTML Abstraction Markup Language) is a layer on top of HTML
|
97
97
|
or XML that''s
|
98
98
|
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/haml/options.rb
|
129
129
|
- lib/haml/parser.rb
|
130
130
|
- lib/haml/railtie.rb
|
131
|
+
- lib/haml/sass_rails_filter.rb
|
131
132
|
- lib/haml/template/options.rb
|
132
133
|
- lib/haml/template/plugin.rb
|
133
134
|
- lib/haml/template.rb
|
@@ -245,6 +246,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
245
246
|
requirements:
|
246
247
|
- - ! '>='
|
247
248
|
- !ruby/object:Gem::Version
|
249
|
+
segments:
|
250
|
+
- 0
|
251
|
+
hash: 2518859033120832815
|
248
252
|
version: '0'
|
249
253
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
254
|
none: false
|