haml 4.0.6 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +19 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +72 -0
  5. data/.yardopts +2 -3
  6. data/CHANGELOG.md +138 -4
  7. data/FAQ.md +4 -14
  8. data/Gemfile +16 -0
  9. data/MIT-LICENSE +2 -2
  10. data/README.md +79 -42
  11. data/REFERENCE.md +142 -67
  12. data/Rakefile +44 -63
  13. data/TODO +24 -0
  14. data/benchmark.rb +70 -0
  15. data/haml.gemspec +45 -0
  16. data/lib/haml.rb +2 -0
  17. data/lib/haml/.gitattributes +1 -0
  18. data/lib/haml/attribute_builder.rb +164 -0
  19. data/lib/haml/attribute_compiler.rb +235 -0
  20. data/lib/haml/attribute_parser.rb +150 -0
  21. data/lib/haml/buffer.rb +29 -136
  22. data/lib/haml/compiler.rb +110 -320
  23. data/lib/haml/engine.rb +34 -41
  24. data/lib/haml/error.rb +28 -24
  25. data/lib/haml/escapable.rb +77 -0
  26. data/lib/haml/exec.rb +38 -20
  27. data/lib/haml/filters.rb +22 -27
  28. data/lib/haml/generator.rb +42 -0
  29. data/lib/haml/helpers.rb +134 -89
  30. data/lib/haml/helpers/action_view_extensions.rb +4 -2
  31. data/lib/haml/helpers/action_view_mods.rb +45 -60
  32. data/lib/haml/helpers/action_view_xss_mods.rb +2 -0
  33. data/lib/haml/helpers/safe_erubi_template.rb +20 -0
  34. data/lib/haml/helpers/safe_erubis_template.rb +5 -1
  35. data/lib/haml/helpers/xss_mods.rb +23 -13
  36. data/lib/haml/options.rb +63 -69
  37. data/lib/haml/parser.rb +292 -228
  38. data/lib/haml/plugin.rb +37 -0
  39. data/lib/haml/railtie.rb +38 -12
  40. data/lib/haml/sass_rails_filter.rb +18 -4
  41. data/lib/haml/template.rb +13 -6
  42. data/lib/haml/template/options.rb +13 -2
  43. data/lib/haml/temple_engine.rb +123 -0
  44. data/lib/haml/temple_line_counter.rb +30 -0
  45. data/lib/haml/util.rb +83 -202
  46. data/lib/haml/version.rb +3 -1
  47. data/yard/default/.gitignore +1 -0
  48. data/yard/default/fulldoc/html/css/common.sass +15 -0
  49. data/yard/default/layout/html/footer.erb +12 -0
  50. metadata +73 -108
  51. data/lib/haml/template/plugin.rb +0 -41
  52. data/test/engine_test.rb +0 -2013
  53. data/test/erb/_av_partial_1.erb +0 -12
  54. data/test/erb/_av_partial_2.erb +0 -8
  55. data/test/erb/action_view.erb +0 -62
  56. data/test/erb/standard.erb +0 -55
  57. data/test/filters_test.rb +0 -254
  58. data/test/gemfiles/Gemfile.rails-3.0.x +0 -5
  59. data/test/gemfiles/Gemfile.rails-3.1.x +0 -6
  60. data/test/gemfiles/Gemfile.rails-3.2.x +0 -5
  61. data/test/gemfiles/Gemfile.rails-4.0.x +0 -5
  62. data/test/helper_test.rb +0 -583
  63. data/test/markaby/standard.mab +0 -52
  64. data/test/mocks/article.rb +0 -6
  65. data/test/parser_test.rb +0 -105
  66. data/test/results/content_for_layout.xhtml +0 -12
  67. data/test/results/eval_suppressed.xhtml +0 -9
  68. data/test/results/helpers.xhtml +0 -70
  69. data/test/results/helpful.xhtml +0 -10
  70. data/test/results/just_stuff.xhtml +0 -70
  71. data/test/results/list.xhtml +0 -12
  72. data/test/results/nuke_inner_whitespace.xhtml +0 -40
  73. data/test/results/nuke_outer_whitespace.xhtml +0 -148
  74. data/test/results/original_engine.xhtml +0 -20
  75. data/test/results/partial_layout.xhtml +0 -5
  76. data/test/results/partial_layout_erb.xhtml +0 -5
  77. data/test/results/partials.xhtml +0 -21
  78. data/test/results/render_layout.xhtml +0 -3
  79. data/test/results/silent_script.xhtml +0 -74
  80. data/test/results/standard.xhtml +0 -162
  81. data/test/results/tag_parsing.xhtml +0 -23
  82. data/test/results/very_basic.xhtml +0 -5
  83. data/test/results/whitespace_handling.xhtml +0 -90
  84. data/test/template_test.rb +0 -354
  85. data/test/templates/_av_partial_1.haml +0 -9
  86. data/test/templates/_av_partial_1_ugly.haml +0 -9
  87. data/test/templates/_av_partial_2.haml +0 -5
  88. data/test/templates/_av_partial_2_ugly.haml +0 -5
  89. data/test/templates/_layout.erb +0 -3
  90. data/test/templates/_layout_for_partial.haml +0 -3
  91. data/test/templates/_partial.haml +0 -8
  92. data/test/templates/_text_area.haml +0 -3
  93. data/test/templates/_text_area_helper.html.haml +0 -4
  94. data/test/templates/action_view.haml +0 -47
  95. data/test/templates/action_view_ugly.haml +0 -47
  96. data/test/templates/breakage.haml +0 -8
  97. data/test/templates/content_for_layout.haml +0 -8
  98. data/test/templates/eval_suppressed.haml +0 -11
  99. data/test/templates/helpers.haml +0 -55
  100. data/test/templates/helpful.haml +0 -11
  101. data/test/templates/just_stuff.haml +0 -85
  102. data/test/templates/list.haml +0 -12
  103. data/test/templates/nuke_inner_whitespace.haml +0 -32
  104. data/test/templates/nuke_outer_whitespace.haml +0 -144
  105. data/test/templates/original_engine.haml +0 -17
  106. data/test/templates/partial_layout.haml +0 -3
  107. data/test/templates/partial_layout_erb.erb +0 -4
  108. data/test/templates/partialize.haml +0 -1
  109. data/test/templates/partials.haml +0 -12
  110. data/test/templates/render_layout.haml +0 -2
  111. data/test/templates/silent_script.haml +0 -45
  112. data/test/templates/standard.haml +0 -43
  113. data/test/templates/standard_ugly.haml +0 -43
  114. data/test/templates/tag_parsing.haml +0 -21
  115. data/test/templates/very_basic.haml +0 -4
  116. data/test/templates/whitespace_handling.haml +0 -87
  117. data/test/test_helper.rb +0 -81
  118. data/test/util_test.rb +0 -63
@@ -1,17 +0,0 @@
1
- !!!
2
- %html
3
- %head
4
- %title Stop. haml time
5
- #content
6
- %h1 This is a title!
7
- %p Lorem ipsum dolor sit amet, consectetur adipisicing elit
8
- %p{:class => 'foo'} Cigarettes!
9
- %h2 Man alive!
10
- %ul.things
11
- %li Slippers
12
- %li Shoes
13
- %li Bathrobe
14
- %li Coffee
15
- %pre
16
- This is some text that's in a pre block!
17
- Let's see what happens when it's rendered! What about now, since we're on a new line?
@@ -1,3 +0,0 @@
1
- %h1 Partial layout used with for block:
2
- = render :layout => 'layout_for_partial' do
3
- %p Some content within a layout
@@ -1,4 +0,0 @@
1
- <h1>Partial layout used with for block:</h1>
2
- <%= render :layout => 'layout_for_partial' do -%>
3
- Some content within a layout
4
- <% end %>
@@ -1 +0,0 @@
1
- = render :file => "#{name}.haml"
@@ -1,12 +0,0 @@
1
- - @foo = 'value one'
2
- %p
3
- @foo =
4
- = @foo
5
- - @foo = 'value two'
6
- %p
7
- @foo =
8
- = @foo
9
- = test_partial "partial"
10
- %p
11
- @foo =
12
- = @foo
@@ -1,2 +0,0 @@
1
- = render :layout => 'layout' do
2
- During
@@ -1,45 +0,0 @@
1
- %div
2
- %h1 I can count!
3
- - (1..20).each do |i|
4
- = i
5
- %h1 I know my ABCs!
6
- %ul
7
- - ('a'..'z').each do |i|
8
- %li= i
9
- %h1 I can catch errors!
10
- - begin
11
- - raise "foo"
12
- - rescue RuntimeError => e
13
- = "Oh no! \"#{e}\" happened!"
14
- %p
15
- "false" is:
16
- - if false
17
- = "true"
18
- - else
19
- = "false"
20
- - if true
21
- - 5.times do |i|
22
- - if i % 2 == 1
23
- Odd!
24
- - else
25
- Even!
26
- - unless true
27
- Testing else indent
28
- - case 1
29
- - when 2
30
- Also testing else indent
31
- - else
32
- = "This can't happen!"
33
- - 13 |
34
- .foo
35
- %strong foobar
36
- - 5.times |
37
- do |
38
- |a| |
39
- %strong= a
40
- .test
41
- - "foo |
42
- bar |
43
- baz" |
44
-
45
- %p boom
@@ -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"
@@ -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"
@@ -1,21 +0,0 @@
1
- %div.tags
2
- %foo 1
3
- %FOO 2
4
- %fooBAR 3
5
- %fooBar 4
6
- %foo_bar 5
7
- %foo-bar 6
8
- %foo:bar 7
9
- %foo.bar 8
10
- %fooBAr_baz:boom_bar 9
11
- %foo13 10
12
- %foo2u 11
13
- %div.classes
14
- %p.foo.bar#baz#boom
15
- .fooBar a
16
- .foo-bar b
17
- .foo_bar c
18
- .FOOBAR d
19
- .foo16 e
20
- .123 f
21
- .foo2u g
@@ -1,4 +0,0 @@
1
- !!!
2
- %html
3
- %head
4
- %body
@@ -1,87 +0,0 @@
1
- #whitespace_test
2
- = test_partial "text_area", :value => "Oneline"
3
- = test_partial "text_area", :value => "Two\nlines"
4
- ~ test_partial "text_area", :value => "Oneline"
5
- ~ test_partial "text_area", :value => "Two\nlines"
6
- #flattened~ test_partial "text_area", :value => "Two\nlines"
7
- .hithere
8
- ~ "Foo bar"
9
- ~ "<pre>foo bar</pre>"
10
- ~ "<pre>foo\nbar</pre>"
11
- %p~ "<pre>foo\nbar</pre>"
12
- %p~ "foo\nbar"
13
- .foo
14
- ~ 13
15
- ~ "<textarea>\na\n</textarea>".each_line do |l|
16
- - haml_concat l.strip
17
- #whitespace_test
18
- = test_partial "text_area", :value => "Oneline"
19
- = test_partial "text_area", :value => "Two\nlines"
20
- = find_and_preserve test_partial("text_area", :value => "Oneline")
21
- = find_and_preserve test_partial("text_area", :value => "Two\nlines")
22
- #flattened= find_and_preserve test_partial("text_area", :value => "Two\nlines")
23
- .hithere
24
- = find_and_preserve("Foo bar")
25
- = find_and_preserve("<pre>foo bar</pre>")
26
- = find_and_preserve("<pre>foo\nbar</pre>")
27
- %p= find_and_preserve("<pre>foo\nbar</pre>")
28
- %p= find_and_preserve("foo\nbar")
29
- %pre
30
- :preserve
31
- ___
32
- ,o88888
33
- ,o8888888'
34
- ,:o:o:oooo. ,8O88Pd8888"
35
- ,.::.::o:ooooOoOoO. ,oO8O8Pd888'"
36
- ,.:.::o:ooOoOoOO8O8OOo.8OOPd8O8O"
37
- , ..:.::o:ooOoOOOO8OOOOo.FdO8O8"
38
- , ..:.::o:ooOoOO8O888O8O,COCOO"
39
- , . ..:.::o:ooOoOOOO8OOOOCOCO"
40
- . ..:.::o:ooOoOoOO8O8OCCCC"o
41
- . ..:.::o:ooooOoCoCCC"o:o
42
- . ..:.::o:o:,cooooCo"oo:o:
43
- ` . . ..:.:cocoooo"'o:o:::'
44
- .` . ..::ccccoc"'o:o:o:::'
45
- :.:. ,c:cccc"':.:.:.:.:.'
46
- ..:.:"'`::::c:"'..:.:.:.:.:.' http://www.chris.com/ASCII/
47
- ...:.'.:.::::"' . . . . .'
48
- .. . ....:."' ` . . . ''
49
- . . . ...."'
50
- .. . ."' -hrr-
51
- .
52
-
53
-
54
- It's a planet!
55
- %strong This shouldn't be bold!
56
- %strong This should!
57
- %textarea
58
- :preserve
59
- ___ ___ ___ ___
60
- /\__\ /\ \ /\__\ /\__\
61
- /:/ / /::\ \ /::| | /:/ /
62
- /:/__/ /:/\:\ \ /:|:| | /:/ /
63
- /::\ \ ___ /::\~\:\ \ /:/|:|__|__ /:/ /
64
- /:/\:\ /\__\ /:/\:\ \:\__\ /:/ |::::\__\ /:/__/
65
- \/__\:\/:/ / \/__\:\/:/ / \/__/~~/:/ / \:\ \
66
- \::/ / \::/ / /:/ / \:\ \
67
- /:/ / /:/ / /:/ / \:\ \
68
- /:/ / /:/ / /:/ / \:\__\
69
- \/__/ \/__/ \/__/ \/__/
70
-
71
- Many
72
- thanks
73
- to
74
- http://www.network-science.de/ascii/
75
- %strong indeed!
76
- .foo
77
- = find_and_preserve(13)
78
- %pre
79
- :preserve
80
- __ ______ __ ______
81
- .----.| |--.|__ |.----.| |--..--------.| __ |
82
- | __|| ||__ || __|| < | || __ |
83
- |____||__|__||______||____||__|__||__|__|__||______|
84
- %pre
85
- :preserve
86
- foo
87
- bar
@@ -1,81 +0,0 @@
1
- if ENV["COVERAGE"]
2
- require "simplecov"
3
- SimpleCov.start
4
- end
5
-
6
- require 'rubygems'
7
- gem "minitest"
8
- require 'bundler/setup'
9
- require 'minitest/autorun'
10
- require 'action_pack'
11
- require 'action_controller'
12
- require 'action_view'
13
- require 'nokogiri'
14
-
15
- require 'rails'
16
- class TestApp < Rails::Application
17
- config.root = ""
18
- end
19
- Rails.application = TestApp
20
-
21
- ActionController::Base.logger = Logger.new(nil)
22
-
23
- require 'fileutils'
24
-
25
- $VERBOSE = true
26
-
27
- require 'haml'
28
- require 'haml/template'
29
-
30
- Haml::Template.options[:ugly] = false
31
- Haml::Template.options[:format] = :xhtml
32
-
33
- module Declarative
34
- def test(name, &block)
35
- define_method("test #{name}", &block)
36
- end
37
- end
38
-
39
- class MiniTest::Unit::TestCase
40
-
41
- extend Declarative
42
-
43
- def render(text, options = {}, base = nil, &block)
44
- scope = options.delete(:scope) || Object.new
45
- locals = options.delete(:locals) || {}
46
- engine = Haml::Engine.new(text, options)
47
- return engine.to_html(base) if base
48
- engine.to_html(scope, locals, &block)
49
- end
50
-
51
- def assert_warning(message)
52
- the_real_stderr, $stderr = $stderr, StringIO.new
53
- yield
54
-
55
- if message.is_a?(Regexp)
56
- assert_match message, $stderr.string.strip
57
- else
58
- assert_equal message.strip, $stderr.string.strip
59
- end
60
- ensure
61
- $stderr = the_real_stderr
62
- end
63
-
64
- def silence_warnings(&block)
65
- Haml::Util.silence_warnings(&block)
66
- end
67
-
68
- def assert_raises_message(klass, message)
69
- yield
70
- rescue Exception => e
71
- assert_instance_of(klass, e)
72
- assert_equal(message, e.message)
73
- else
74
- flunk "Expected exception #{klass}, none raised"
75
- end
76
-
77
- def self.error(*args)
78
- Haml::Error.message(*args)
79
- end
80
-
81
- end
@@ -1,63 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UtilTest < MiniTest::Unit::TestCase
4
- include Haml::Util
5
-
6
- def test_powerset
7
- return unless Set[Set[]] == Set[Set[]] # There's a bug in Ruby 1.8.6 that breaks nested set equality
8
- assert_equal([[].to_set].to_set,
9
- powerset([]))
10
- assert_equal([[].to_set, [1].to_set].to_set,
11
- powerset([1]))
12
- assert_equal([[].to_set, [1].to_set, [2].to_set, [1, 2].to_set].to_set,
13
- powerset([1, 2]))
14
- assert_equal([[].to_set, [1].to_set, [2].to_set, [3].to_set,
15
- [1, 2].to_set, [2, 3].to_set, [1, 3].to_set, [1, 2, 3].to_set].to_set,
16
- powerset([1, 2, 3]))
17
- end
18
-
19
- def test_silence_warnings
20
- old_stderr, $stderr = $stderr, StringIO.new
21
- warn "Out"
22
- assert_equal("Out\n", $stderr.string)
23
- silence_warnings {warn "In"}
24
- assert_equal("Out\n", $stderr.string)
25
- ensure
26
- $stderr = old_stderr
27
- end
28
-
29
- def test_caller_info
30
- assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle'"))
31
- assert_equal(["/tmp/foo.rb", 12, nil], caller_info("/tmp/foo.rb:12"))
32
- assert_equal(["(haml)", 12, "blah"], caller_info("(haml):12: in `blah'"))
33
- assert_equal(["", 12, "boop"], caller_info(":12: in `boop'"))
34
- assert_equal(["/tmp/foo.rb", -12, "fizzle"], caller_info("/tmp/foo.rb:-12: in `fizzle'"))
35
- assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle {}'"))
36
- end
37
-
38
- def test_def_static_method
39
- klass = Class.new
40
- def_static_method(klass, :static_method, [:arg1, :arg2],
41
- :sarg1, :sarg2, <<RUBY)
42
- s = "Always " + arg1
43
- s << " <% if sarg1 %>and<% else %>but never<% end %> " << arg2
44
-
45
- <% if sarg2 %>
46
- s << "."
47
- <% end %>
48
- RUBY
49
- c = klass.new
50
- assert_equal("Always brush your teeth and comb your hair.",
51
- c.send(static_method_name(:static_method, true, true),
52
- "brush your teeth", "comb your hair"))
53
- assert_equal("Always brush your teeth and comb your hair",
54
- c.send(static_method_name(:static_method, true, false),
55
- "brush your teeth", "comb your hair"))
56
- assert_equal("Always brush your teeth but never play with fire.",
57
- c.send(static_method_name(:static_method, false, true),
58
- "brush your teeth", "play with fire"))
59
- assert_equal("Always brush your teeth but never play with fire",
60
- c.send(static_method_name(:static_method, false, false),
61
- "brush your teeth", "play with fire"))
62
- end
63
- end