haml 4.1.0.beta.1 → 5.0.0.beta.2

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.

Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +36 -6
  4. data/FAQ.md +4 -14
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +81 -48
  7. data/REFERENCE.md +86 -50
  8. data/Rakefile +28 -41
  9. data/lib/haml/attribute_builder.rb +163 -0
  10. data/lib/haml/attribute_compiler.rb +214 -0
  11. data/lib/haml/attribute_parser.rb +112 -0
  12. data/lib/haml/buffer.rb +24 -126
  13. data/lib/haml/compiler.rb +62 -281
  14. data/lib/haml/engine.rb +16 -23
  15. data/lib/haml/error.rb +2 -0
  16. data/lib/haml/escapable.rb +48 -0
  17. data/lib/haml/exec.rb +23 -12
  18. data/lib/haml/filters.rb +3 -4
  19. data/lib/haml/generator.rb +36 -0
  20. data/lib/haml/helpers.rb +61 -48
  21. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  22. data/lib/haml/helpers/action_view_mods.rb +32 -50
  23. data/lib/haml/helpers/safe_erubi_template.rb +26 -0
  24. data/lib/haml/helpers/safe_erubis_template.rb +2 -0
  25. data/lib/haml/helpers/xss_mods.rb +17 -12
  26. data/lib/haml/options.rb +32 -36
  27. data/lib/haml/parser.rb +61 -38
  28. data/lib/haml/{template/plugin.rb → plugin.rb} +5 -2
  29. data/lib/haml/railtie.rb +14 -6
  30. data/lib/haml/template.rb +11 -6
  31. data/lib/haml/temple_engine.rb +119 -0
  32. data/lib/haml/temple_line_counter.rb +28 -0
  33. data/lib/haml/util.rb +17 -112
  34. data/lib/haml/version.rb +1 -1
  35. data/test/attribute_parser_test.rb +105 -0
  36. data/test/engine_test.rb +202 -106
  37. data/test/filters_test.rb +32 -19
  38. data/test/gemfiles/Gemfile.rails-4.0.x +7 -1
  39. data/test/gemfiles/Gemfile.rails-4.0.x.lock +57 -71
  40. data/test/gemfiles/Gemfile.rails-4.1.x +5 -0
  41. data/test/gemfiles/Gemfile.rails-4.2.x +5 -0
  42. data/test/gemfiles/Gemfile.rails-5.0.x +4 -0
  43. data/test/helper_test.rb +156 -109
  44. data/test/options_test.rb +21 -0
  45. data/test/parser_test.rb +49 -4
  46. data/test/results/eval_suppressed.xhtml +4 -4
  47. data/test/results/helpers.xhtml +43 -41
  48. data/test/results/helpful.xhtml +6 -3
  49. data/test/results/just_stuff.xhtml +21 -20
  50. data/test/results/list.xhtml +9 -9
  51. data/test/results/nuke_inner_whitespace.xhtml +22 -22
  52. data/test/results/nuke_outer_whitespace.xhtml +84 -92
  53. data/test/results/original_engine.xhtml +17 -17
  54. data/test/results/partial_layout.xhtml +4 -3
  55. data/test/results/partial_layout_erb.xhtml +4 -3
  56. data/test/results/partials.xhtml +11 -10
  57. data/test/results/silent_script.xhtml +63 -63
  58. data/test/results/standard.xhtml +156 -159
  59. data/test/results/tag_parsing.xhtml +19 -19
  60. data/test/results/very_basic.xhtml +2 -2
  61. data/test/results/whitespace_handling.xhtml +77 -76
  62. data/test/template_test.rb +21 -48
  63. data/test/template_test_helper.rb +38 -0
  64. data/test/templates/just_stuff.haml +1 -0
  65. data/test/templates/standard_ugly.haml +1 -0
  66. data/test/temple_line_counter_test.rb +40 -0
  67. data/test/test_helper.rb +10 -10
  68. data/test/util_test.rb +1 -48
  69. metadata +49 -35
  70. data/lib/haml/temple.rb +0 -85
  71. data/test/gemfiles/Gemfile.rails-3.2.x +0 -4
  72. data/test/templates/_av_partial_1_ugly.haml +0 -9
  73. data/test/templates/_av_partial_2_ugly.haml +0 -5
  74. data/test/templates/action_view_ugly.haml +0 -47
  75. data/test/templates/standard_ugly.haml +0 -43
@@ -1,20 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
- class UtilTest < MiniTest::Unit::TestCase
3
+ class UtilTest < Haml::TestCase
4
4
  include Haml::Util
5
5
 
6
- def test_powerset
7
- assert_equal([[].to_set].to_set,
8
- powerset([]))
9
- assert_equal([[].to_set, [1].to_set].to_set,
10
- powerset([1]))
11
- assert_equal([[].to_set, [1].to_set, [2].to_set, [1, 2].to_set].to_set,
12
- powerset([1, 2]))
13
- assert_equal([[].to_set, [1].to_set, [2].to_set, [3].to_set,
14
- [1, 2].to_set, [2, 3].to_set, [1, 3].to_set, [1, 2, 3].to_set].to_set,
15
- powerset([1, 2, 3]))
16
- end
17
-
18
6
  def test_silence_warnings
19
7
  old_stderr, $stderr = $stderr, StringIO.new
20
8
  warn "Out"
@@ -25,41 +13,6 @@ class UtilTest < MiniTest::Unit::TestCase
25
13
  $stderr = old_stderr
26
14
  end
27
15
 
28
- def test_caller_info
29
- assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle'"))
30
- assert_equal(["/tmp/foo.rb", 12, nil], caller_info("/tmp/foo.rb:12"))
31
- assert_equal(["(haml)", 12, "blah"], caller_info("(haml):12: in `blah'"))
32
- assert_equal(["", 12, "boop"], caller_info(":12: in `boop'"))
33
- assert_equal(["/tmp/foo.rb", -12, "fizzle"], caller_info("/tmp/foo.rb:-12: in `fizzle'"))
34
- assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle {}'"))
35
- end
36
-
37
- def test_def_static_method
38
- klass = Class.new
39
- def_static_method(klass, :static_method, [:arg1, :arg2],
40
- :sarg1, :sarg2, <<RUBY)
41
- s = "Always " + arg1
42
- s << " <% if sarg1 %>and<% else %>but never<% end %> " << arg2
43
-
44
- <% if sarg2 %>
45
- s << "."
46
- <% end %>
47
- RUBY
48
- c = klass.new
49
- assert_equal("Always brush your teeth and comb your hair.",
50
- c.send(static_method_name(:static_method, true, true),
51
- "brush your teeth", "comb your hair"))
52
- assert_equal("Always brush your teeth and comb your hair",
53
- c.send(static_method_name(:static_method, true, false),
54
- "brush your teeth", "comb your hair"))
55
- assert_equal("Always brush your teeth but never play with fire.",
56
- c.send(static_method_name(:static_method, false, true),
57
- "brush your teeth", "play with fire"))
58
- assert_equal("Always brush your teeth but never play with fire",
59
- c.send(static_method_name(:static_method, false, false),
60
- "brush your teeth", "play with fire"))
61
- end
62
-
63
16
  def test_check_encoding_does_not_destoy_the_given_string
64
17
  string_with_bom = File.read(File.dirname(__FILE__) + '/templates/with_bom.haml', :encoding => Encoding::UTF_8)
65
18
  original = string_with_bom.dup
metadata CHANGED
@@ -1,17 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0.beta.1
4
+ version: 5.0.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
- - Nathan Weizenbaum
7
+ - Natalie Weizenbaum
8
8
  - Hampton Catlin
9
9
  - Norman Clarke
10
+ - Akira Matsuda
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2014-01-07 00:00:00.000000000 Z
14
+ date: 2017-02-26 00:00:00.000000000 Z
14
15
  dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: temple
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.0
15
30
  - !ruby/object:Gem::Dependency
16
31
  name: tilt
17
32
  requirement: !ruby/object:Gem::Requirement
@@ -32,14 +47,14 @@ dependencies:
32
47
  requirements:
33
48
  - - ">="
34
49
  - !ruby/object:Gem::Version
35
- version: 3.2.0
50
+ version: 4.0.0
36
51
  type: :development
37
52
  prerelease: false
38
53
  version_requirements: !ruby/object:Gem::Requirement
39
54
  requirements:
40
55
  - - ">="
41
56
  - !ruby/object:Gem::Version
42
- version: 3.2.0
57
+ version: 4.0.0
43
58
  - !ruby/object:Gem::Dependency
44
59
  name: rbench
45
60
  requirement: !ruby/object:Gem::Requirement
@@ -58,30 +73,30 @@ dependencies:
58
73
  name: minitest
59
74
  requirement: !ruby/object:Gem::Requirement
60
75
  requirements:
61
- - - "~>"
76
+ - - ">="
62
77
  - !ruby/object:Gem::Version
63
78
  version: '4.0'
64
79
  type: :development
65
80
  prerelease: false
66
81
  version_requirements: !ruby/object:Gem::Requirement
67
82
  requirements:
68
- - - "~>"
83
+ - - ">="
69
84
  - !ruby/object:Gem::Version
70
85
  version: '4.0'
71
86
  - !ruby/object:Gem::Dependency
72
87
  name: nokogiri
73
88
  requirement: !ruby/object:Gem::Requirement
74
89
  requirements:
75
- - - "~>"
90
+ - - ">="
76
91
  - !ruby/object:Gem::Version
77
- version: 1.6.0
92
+ version: '0'
78
93
  type: :development
79
94
  prerelease: false
80
95
  version_requirements: !ruby/object:Gem::Requirement
81
96
  requirements:
82
- - - "~>"
97
+ - - ">="
83
98
  - !ruby/object:Gem::Version
84
- version: 1.6.0
99
+ version: '0'
85
100
  description: |
86
101
  Haml (HTML Abstraction Markup Language) is a layer on top of HTML or XML that's
87
102
  designed to express the structure of documents in a non-repetitive, elegant, and
@@ -105,40 +120,51 @@ files:
105
120
  - Rakefile
106
121
  - bin/haml
107
122
  - lib/haml.rb
123
+ - lib/haml/attribute_builder.rb
124
+ - lib/haml/attribute_compiler.rb
125
+ - lib/haml/attribute_parser.rb
108
126
  - lib/haml/buffer.rb
109
127
  - lib/haml/compiler.rb
110
128
  - lib/haml/engine.rb
111
129
  - lib/haml/error.rb
130
+ - lib/haml/escapable.rb
112
131
  - lib/haml/exec.rb
113
132
  - lib/haml/filters.rb
133
+ - lib/haml/generator.rb
114
134
  - lib/haml/helpers.rb
115
135
  - lib/haml/helpers/action_view_extensions.rb
116
136
  - lib/haml/helpers/action_view_mods.rb
117
137
  - lib/haml/helpers/action_view_xss_mods.rb
138
+ - lib/haml/helpers/safe_erubi_template.rb
118
139
  - lib/haml/helpers/safe_erubis_template.rb
119
140
  - lib/haml/helpers/xss_mods.rb
120
141
  - lib/haml/options.rb
121
142
  - lib/haml/parser.rb
143
+ - lib/haml/plugin.rb
122
144
  - lib/haml/railtie.rb
123
145
  - lib/haml/sass_rails_filter.rb
124
146
  - lib/haml/template.rb
125
147
  - lib/haml/template/options.rb
126
- - lib/haml/template/plugin.rb
127
- - lib/haml/temple.rb
148
+ - lib/haml/temple_engine.rb
149
+ - lib/haml/temple_line_counter.rb
128
150
  - lib/haml/util.rb
129
151
  - lib/haml/version.rb
152
+ - test/attribute_parser_test.rb
130
153
  - test/engine_test.rb
131
154
  - test/erb/_av_partial_1.erb
132
155
  - test/erb/_av_partial_2.erb
133
156
  - test/erb/action_view.erb
134
157
  - test/erb/standard.erb
135
158
  - test/filters_test.rb
136
- - test/gemfiles/Gemfile.rails-3.2.x
137
159
  - test/gemfiles/Gemfile.rails-4.0.x
138
160
  - test/gemfiles/Gemfile.rails-4.0.x.lock
161
+ - test/gemfiles/Gemfile.rails-4.1.x
162
+ - test/gemfiles/Gemfile.rails-4.2.x
163
+ - test/gemfiles/Gemfile.rails-5.0.x
139
164
  - test/helper_test.rb
140
165
  - test/markaby/standard.mab
141
166
  - test/mocks/article.rb
167
+ - test/options_test.rb
142
168
  - test/parser_test.rb
143
169
  - test/results/content_for_layout.xhtml
144
170
  - test/results/eval_suppressed.xhtml
@@ -159,17 +185,15 @@ files:
159
185
  - test/results/very_basic.xhtml
160
186
  - test/results/whitespace_handling.xhtml
161
187
  - test/template_test.rb
188
+ - test/template_test_helper.rb
162
189
  - test/templates/_av_partial_1.haml
163
- - test/templates/_av_partial_1_ugly.haml
164
190
  - test/templates/_av_partial_2.haml
165
- - test/templates/_av_partial_2_ugly.haml
166
191
  - test/templates/_layout.erb
167
192
  - test/templates/_layout_for_partial.haml
168
193
  - test/templates/_partial.haml
169
194
  - test/templates/_text_area.haml
170
195
  - test/templates/_text_area_helper.html.haml
171
196
  - test/templates/action_view.haml
172
- - test/templates/action_view_ugly.haml
173
197
  - test/templates/breakage.haml
174
198
  - test/templates/content_for_layout.haml
175
199
  - test/templates/eval_suppressed.haml
@@ -192,28 +216,14 @@ files:
192
216
  - test/templates/very_basic.haml
193
217
  - test/templates/whitespace_handling.haml
194
218
  - test/templates/with_bom.haml
219
+ - test/temple_line_counter_test.rb
195
220
  - test/test_helper.rb
196
221
  - test/util_test.rb
197
222
  homepage: http://haml.info/
198
223
  licenses:
199
224
  - MIT
200
225
  metadata: {}
201
- post_install_message: |2+
202
-
203
- HEADS UP! Haml 4.0 has many improvements, but also has changes that may break
204
- your application:
205
-
206
- * Support for Ruby 1.8.6 dropped
207
- * Support for Rails 2 dropped
208
- * Sass filter now always outputs <style> tags
209
- * Data attributes are now hyphenated, not underscored
210
- * html2haml utility moved to the html2haml gem
211
- * Textile and Maruku filters moved to the haml-contrib gem
212
-
213
- For more info see:
214
-
215
- http://rubydoc.info/github/haml/haml/file/CHANGELOG.md
216
-
226
+ post_install_message:
217
227
  rdoc_options: []
218
228
  require_paths:
219
229
  - lib
@@ -221,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
231
  requirements:
222
232
  - - ">="
223
233
  - !ruby/object:Gem::Version
224
- version: 1.9.2
234
+ version: 2.0.0
225
235
  required_rubygems_version: !ruby/object:Gem::Requirement
226
236
  requirements:
227
237
  - - ">"
@@ -229,14 +239,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
239
  version: 1.3.1
230
240
  requirements: []
231
241
  rubyforge_project:
232
- rubygems_version: 2.2.0
242
+ rubygems_version: 2.6.10
233
243
  signing_key:
234
244
  specification_version: 4
235
245
  summary: An elegant, structured (X)HTML/XML templating engine.
236
246
  test_files:
247
+ - test/attribute_parser_test.rb
237
248
  - test/engine_test.rb
238
249
  - test/filters_test.rb
239
250
  - test/helper_test.rb
251
+ - test/options_test.rb
240
252
  - test/parser_test.rb
241
253
  - test/template_test.rb
254
+ - test/temple_line_counter_test.rb
242
255
  - test/util_test.rb
256
+ has_rdoc: false
@@ -1,85 +0,0 @@
1
- require 'haml'
2
- require 'temple'
3
-
4
- module Haml
5
-
6
- module Temple
7
-
8
- module Expressions
9
- def on_plain
10
- [:static, "\n" + value[:text]]
11
- end
12
-
13
- def on_root
14
- [:multi]
15
- end
16
-
17
- def on_doctype
18
- [:html, :doctype, value[:version] || 5]
19
- end
20
-
21
- def on_tag
22
- exp = [:html, :tag, value[:name], [:html, :attrs]]
23
- if value[:value] && value[:value] != ""
24
- if value[:parse]
25
- exp.push << [:dynamic, value[:value]]
26
- else
27
- exp.push << [:static, value[:value]]
28
- end
29
- end
30
-
31
- if attribs = value[:attributes]
32
- attribs.each do |key, value|
33
- exp.last << [:html, :attr, key, [:static, value]]
34
- end
35
- end
36
-
37
- exp
38
- end
39
- end
40
-
41
- class Parser
42
- def initialize(*args)
43
- @options = Options.new
44
- end
45
-
46
- def call(haml)
47
- parser = ::Haml::Parser.new(haml, @options)
48
- tree = parser.parse.tap {|x| p x; puts '-' * 10}
49
- compile(tree).tap {|x| p x; puts '-' * 10}
50
- end
51
-
52
- private
53
-
54
- def compile(node)
55
- exp = node.to_temple
56
- return exp if node.children.empty?
57
- if node.children.length == 1
58
- exp.push compile(node.children[0])
59
- else
60
- exp.push [:multi, *node.children.map {|c| compile(c)}]
61
- end
62
- exp
63
- end
64
- end
65
-
66
- class Engine < ::Temple::Engine
67
- use ::Haml::Temple::Parser
68
- html :Pretty
69
- filter :ControlFlow
70
- generator :ArrayBuffer
71
- end
72
- end
73
-
74
- class Parser::ParseNode
75
- include ::Haml::Temple::Expressions
76
-
77
- def to_temple
78
- begin
79
- send "on_#{type}"
80
- end
81
- end
82
- end
83
- end
84
-
85
- Haml::Temple::Template = Temple::Templates::Tilt(Haml::Temple::Engine, :register_as => :haml)
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'rails', '~> 3.2.0'
4
- gemspec :path => "../.."
@@ -1,9 +0,0 @@
1
- %h2 This is a pretty complicated partial
2
- .partial
3
- %p It has several nested partials,
4
- %ul
5
- - 5.times do
6
- %li
7
- %strong Partial:
8
- - @nesting = 5
9
- = render :partial => 'templates/av_partial_2_ugly'
@@ -1,5 +0,0 @@
1
- - @nesting -= 1
2
- .partial{:level => @nesting}
3
- %h3 This is a crazy deep-nested partial.
4
- %p== Nesting level #{@nesting}
5
- = render :partial => 'templates/av_partial_2_ugly' if @nesting > 0
@@ -1,47 +0,0 @@
1
- !!!
2
- %html{html_attrs}
3
- %head
4
- %title Hampton Catlin Is Totally Awesome
5
- %meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}
6
- %body
7
- %h1
8
- This is very much like the standard template,
9
- except that it has some ActionView-specific stuff.
10
- It's only used for benchmarking.
11
- .crazy_partials= render :partial => 'templates/av_partial_1_ugly'
12
- / You're In my house now!
13
- .header
14
- Yes, ladies and gentileman. He is just that egotistical.
15
- Fantastic! This should be multi-line output
16
- The question is if this would translate! Ahah!
17
- = 1 + 9 + 8 + 2 #numbers should work and this should be ignored
18
- #body= " Quotes should be loved! Just like people!"
19
- - 120.times do |number|
20
- - number
21
- Wow.|
22
- %p
23
- = "Holy cow " + |
24
- "multiline " + |
25
- "tags! " + |
26
- "A pipe (|) even!" |
27
- = [1, 2, 3].collect { |n| "PipesIgnored|" }
28
- = [1, 2, 3].collect { |n| |
29
- n.to_s |
30
- }.join("|") |
31
- %div.silent
32
- - foo = String.new
33
- - foo << "this"
34
- - foo << " shouldn't"
35
- - foo << " evaluate"
36
- = foo + " but now it should!"
37
- -# Woah crap a comment!
38
-
39
- -# That was a line that shouldn't close everything.
40
- %ul.really.cool
41
- - ('a'..'f').each do |a|
42
- %li= a
43
- #combo.of_divs_with_underscore= @should_eval = "with this text"
44
- = [ 104, 101, 108, 108, 111 ].map do |byte|
45
- - byte.chr
46
- .footer
47
- %strong.shout= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works"
@@ -1,43 +0,0 @@
1
- !!!
2
- %html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en-US", "lang" => "en-US"}
3
- %head
4
- %title Hampton Catlin Is Totally Awesome
5
- %meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}
6
- %body
7
- / You're In my house now!
8
- .header
9
- Yes, ladies and gentileman. He is just that egotistical.
10
- Fantastic! This should be multi-line output
11
- The question is if this would translate! Ahah!
12
- = 1 + 9 + 8 + 2 #numbers should work and this should be ignored
13
- #body= " Quotes should be loved! Just like people!"
14
- - 120.times do |number|
15
- = number
16
- Wow.|
17
- %p{:code => 1 + 2}
18
- = "Holy cow " + |
19
- "multiline " + |
20
- "tags! " + |
21
- "A pipe (|) even!" |
22
- = [1, 2, 3].collect { |n| "PipesIgnored|" }.join
23
- = [1, 2, 3].collect { |n| |
24
- n.to_s |
25
- }.join("|") |
26
- - bar = 17
27
- %div.silent{:foo => bar}
28
- - foo = String.new
29
- - foo << "this"
30
- - foo << " shouldn't"
31
- - foo << " evaluate"
32
- = foo + " but now it should!"
33
- -# Woah crap a comment!
34
-
35
- -# That was a line that shouldn't close everything.
36
- %ul.really.cool
37
- - ('a'..'f').each do |a|
38
- %li= a
39
- #combo.of_divs_with_underscore= @should_eval = "with this text"
40
- = "foo".each_line do |line|
41
- - nil
42
- .footer
43
- %strong.shout= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works"