haml 4.0.7 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +42 -4
  4. data/FAQ.md +4 -14
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +85 -42
  7. data/REFERENCE.md +108 -57
  8. data/Rakefile +46 -54
  9. data/lib/haml/attribute_builder.rb +163 -0
  10. data/lib/haml/attribute_compiler.rb +215 -0
  11. data/lib/haml/attribute_parser.rb +144 -0
  12. data/lib/haml/buffer.rb +22 -132
  13. data/lib/haml/compiler.rb +87 -295
  14. data/lib/haml/engine.rb +25 -41
  15. data/lib/haml/error.rb +3 -0
  16. data/lib/haml/escapable.rb +49 -0
  17. data/lib/haml/exec.rb +33 -19
  18. data/lib/haml/filters.rb +18 -24
  19. data/lib/haml/generator.rb +41 -0
  20. data/lib/haml/helpers/action_view_extensions.rb +3 -2
  21. data/lib/haml/helpers/action_view_mods.rb +36 -58
  22. data/lib/haml/helpers/action_view_xss_mods.rb +1 -0
  23. data/lib/haml/helpers/safe_erubi_template.rb +27 -0
  24. data/lib/haml/helpers/safe_erubis_template.rb +4 -1
  25. data/lib/haml/helpers/xss_mods.rb +18 -12
  26. data/lib/haml/helpers.rb +133 -90
  27. data/lib/haml/options.rb +38 -47
  28. data/lib/haml/parser.rb +278 -216
  29. data/lib/haml/{template/plugin.rb → plugin.rb} +8 -15
  30. data/lib/haml/railtie.rb +21 -12
  31. data/lib/haml/sass_rails_filter.rb +17 -4
  32. data/lib/haml/template/options.rb +12 -2
  33. data/lib/haml/template.rb +12 -6
  34. data/lib/haml/temple_engine.rb +120 -0
  35. data/lib/haml/temple_line_counter.rb +29 -0
  36. data/lib/haml/util.rb +80 -199
  37. data/lib/haml/version.rb +2 -1
  38. data/lib/haml.rb +1 -0
  39. data/test/attribute_parser_test.rb +101 -0
  40. data/test/engine_test.rb +287 -176
  41. data/test/filters_test.rb +32 -19
  42. data/test/gemfiles/Gemfile.rails-4.0.x +9 -3
  43. data/test/gemfiles/Gemfile.rails-4.0.x.lock +87 -0
  44. data/test/gemfiles/Gemfile.rails-4.1.x +5 -0
  45. data/test/gemfiles/Gemfile.rails-4.2.x +5 -0
  46. data/test/gemfiles/Gemfile.rails-5.0.x +4 -0
  47. data/test/helper_test.rb +224 -112
  48. data/test/options_test.rb +22 -0
  49. data/test/parser_test.rb +71 -4
  50. data/test/results/bemit.xhtml +4 -0
  51. data/test/results/eval_suppressed.xhtml +4 -4
  52. data/test/results/helpers.xhtml +43 -41
  53. data/test/results/helpful.xhtml +6 -3
  54. data/test/results/just_stuff.xhtml +21 -20
  55. data/test/results/list.xhtml +9 -9
  56. data/test/results/nuke_inner_whitespace.xhtml +22 -22
  57. data/test/results/nuke_outer_whitespace.xhtml +84 -92
  58. data/test/results/original_engine.xhtml +17 -17
  59. data/test/results/partial_layout.xhtml +4 -3
  60. data/test/results/partial_layout_erb.xhtml +4 -3
  61. data/test/results/partials.xhtml +11 -10
  62. data/test/results/silent_script.xhtml +63 -63
  63. data/test/results/standard.xhtml +156 -159
  64. data/test/results/tag_parsing.xhtml +19 -19
  65. data/test/results/very_basic.xhtml +2 -2
  66. data/test/results/whitespace_handling.xhtml +77 -76
  67. data/test/template_test.rb +24 -56
  68. data/test/template_test_helper.rb +38 -0
  69. data/test/templates/bemit.haml +3 -0
  70. data/test/templates/just_stuff.haml +1 -0
  71. data/test/templates/standard_ugly.haml +1 -0
  72. data/test/templates/with_bom.haml +1 -0
  73. data/test/temple_line_counter_test.rb +40 -0
  74. data/test/test_helper.rb +26 -8
  75. data/test/util_test.rb +6 -47
  76. metadata +53 -43
  77. data/test/gemfiles/Gemfile.rails-3.0.x +0 -5
  78. data/test/gemfiles/Gemfile.rails-3.1.x +0 -6
  79. data/test/gemfiles/Gemfile.rails-3.2.x +0 -5
  80. data/test/haml-spec/LICENSE +0 -14
  81. data/test/haml-spec/README.md +0 -106
  82. data/test/haml-spec/lua_haml_spec.lua +0 -38
  83. data/test/haml-spec/perl_haml_test.pl +0 -81
  84. data/test/haml-spec/ruby_haml_test.rb +0 -23
  85. data/test/haml-spec/tests.json +0 -660
  86. data/test/templates/_av_partial_1_ugly.haml +0 -9
  87. data/test/templates/_av_partial_2_ugly.haml +0 -5
  88. data/test/templates/action_view_ugly.haml +0 -47
  89. data/test/templates/standard_ugly.haml +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7a38de787ab9e47ac3221b040c9c38ecf4884df
4
- data.tar.gz: 29497caf8377f40940a0e094d1477ea2403f380f
3
+ metadata.gz: 7fa1e64aca629e46493a148b6159feb77763ba0d
4
+ data.tar.gz: 912f3565b782829c0651604333a0d5fd823c45a1
5
5
  SHA512:
6
- metadata.gz: 3c71810f7359be3c7536eea848acefb06d09859443d6b80a31908ea07b6c109dc082a7ad8a7e95f1305b08aefeabbe46dd48cc186dff66eb4fe46bdd258956e1
7
- data.tar.gz: 0d85d5e2164cef71dab787d7967ab4a3e7ecd1dd0b5e212188032bd94faa6d4923cdb39cd5fdffcdaed6da13b6f637d1d5d5c8171ca878fa017ac64c345d589f
6
+ metadata.gz: d8e860a0fc047d158a7a1d08f349a5555ae9a0afd578327c16cca624c3c0425a323e40cc3185f8ba8fede3ed79d24babb44f634969a69707a46f27d92b925b15
7
+ data.tar.gz: f3e66b26cf401ac0081721f44322a4fe39c0b0c486d6b4b0dd7e665e483be86f6f1769a0c94ed00b2646e3d76fb7be0ebe2e40c75943c0a5774e38cb3f17a4e2
data/.yardopts CHANGED
@@ -1,7 +1,7 @@
1
1
  --charset utf-8
2
2
  --readme README.md
3
3
  --markup markdown
4
- --markup-provider maruku
4
+ --markup-provider kramdown
5
5
  --template-path yard
6
6
  --default-return ""
7
7
  --title "Haml Documentation"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 5.0.0
4
+
5
+ Released on April 26, 2017
6
+ ([diff](https://github.com/haml/haml/compare/4.0.7...5.0.0)).
7
+
8
+ * Haml now requires Ruby 2.0.0 or above.
9
+ * Rails 3 is no longer supported, matching the official
10
+ [Maintenance Policy for Ruby on Rails](http://weblog.rubyonrails.org/2013/2/24/maintenance-policy-for-ruby-on-rails/).
11
+ (Tee Parham)
12
+ * Fix for attribute merging. When an attribute method (or literal nested hash)
13
+ was used in an old style attribute hash and there is also a (non-static) new
14
+ style hash there is an error. The fix can result in different behavior in
15
+ some circumstances. See the [commit message](https://github.com/haml/haml/tree/e475b015d3171fb4c4f140db304f7970c787d6e3)
16
+ for detailed info. (Matt Wildig)
17
+ * Make escape_once respect hexadecimal references. (Matt Wildig)
18
+ * General performance and memory usage improvements. (Akira Matsuda)
19
+ * Don't treat the 'data' attribute specially when merging attribute hashes. (Matt Wildig and Norman Clarke)
20
+ * Add a tracing option. When enabled, Haml will output a data-trace attribute on each tag showing the path
21
+ to the source Haml file from which it was generated. Thanks [Alex Babkin](https://github.com/ababkin).
22
+ * Fix #@foo and #$foo style interpolation that was not working in html_safe mode. (Akira Matsuda)
23
+ * Add `haml_tag_if` to render a block, conditionally wrapped in another element (Matt Wildig)
24
+ * Escape Ruby script interpolated in filters. (Matt Wildig)
25
+ * The `haml` command's debug option (`-d`) no longer executes the Haml code, but
26
+ rather checks the generated Ruby syntax for errors.
27
+ * Support Rails 5.1 Erubi template handler.
28
+ * Support Sprockets 3. Thanks [Sam Davies](https://github.com/samphilipd) and [Jeremy Venezia](https://github.com/jvenezia).
29
+ * Allow `@` as tag's class name. Thanks [Joe Bartlett](https://github.com/redoPop).
30
+ * Raise `Haml::InvalidAttributeNameError` when attribute name includes invalid characters. (Takashi Kokubun)
31
+ * Drop dynamic quotes support and always escape `'` for `escape_html`/`escape_attrs` instead.
32
+ Also, escaped results are slightly changed and always unified to the same characters. (Takashi Kokubun)
33
+ * Don't preserve newlines in attributes. (Takashi Kokubun)
34
+ * Add temple gem as dependency and create `Haml::TempleEngine` class.
35
+ Some methods in `Haml::Compiler` are migrated to `Haml::TempleEngine`. (Takashi Kokubun)
36
+ * Drop parser/compiler accessor from `Haml::Engine`. Modify `Haml::Engine#initialize` options
37
+ or `Haml::Template.options` instead. (Takashi Kokubun)
38
+ * Don't ignore unexpected exceptions on initializing `ActionView::OutputBuffer`. (Takashi Kokubun)
39
+ * Analyze attribute values by Ripper and render static attributes beforehand. (Takashi Kokubun)
40
+ * Optimize attribute rendering about 3x faster. (Takashi Kokubun)
41
+
3
42
  ## 4.0.7
4
43
 
5
44
  Released on August 10, 2015
@@ -11,7 +50,6 @@ Released on August 10, 2015
11
50
 
12
51
  Released on Dec 1, 2014 ([diff](https://github.com/haml/haml/compare/4.0.5...4.0.6)).
13
52
 
14
-
15
53
  * Fix warning on Ruby 1.8.7 "regexp has invalid interval" (thanks [Elia Schito](https://github.com/elia)).
16
54
 
17
55
  ## 4.0.5
@@ -76,7 +114,7 @@ Released March 21, 2013 ([diff](https://github.com/haml/haml/compare/4.0.0...4.0
76
114
 
77
115
  ## 4.0.0
78
116
 
79
- * The Haml exectutable now accepts an `--autoclose` option. You can now
117
+ * The Haml executable now accepts an `--autoclose` option. You can now
80
118
  specify a list of tags that should be autoclosed
81
119
 
82
120
  * The `:ruby` filter no longer redirects $stdout to the Haml document, as this
@@ -113,7 +151,7 @@ Released March 21, 2013 ([diff](https://github.com/haml/haml/compare/4.0.0...4.0
113
151
 
114
152
  * All Hash attribute values are now treated as HTML5 data, regardless of key.
115
153
  Previously only the "data" key was treated this way. Allowing arbitrary keys
116
- means you can now easily use this feauture for Aria attributes, among other
154
+ means you can now easily use this feature for Aria attributes, among other
117
155
  uses.
118
156
  (thanks to [Elvin Efendi](https://github.com/ElvinEfendi))
119
157
 
@@ -532,7 +570,6 @@ The {file:HAML_REFERENCE.md#ugly-option `:ugly` option} is now on by default
532
570
  in the testing environment in Rails to help tests run faster.
533
571
 
534
572
  ## 3.0.0
535
- {#3-0-0}
536
573
 
537
574
  [Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.0).
538
575
 
@@ -1361,3 +1398,4 @@ has been moved to [YARD](http://yard.soen.ca).
1361
1398
  YARD is an excellent documentation system,
1362
1399
  and allows us to write our documentation in [Maruku](http://maruku.rubyforge.org),
1363
1400
  which is also excellent.
1401
+ >>>>>>> External Changes
data/FAQ.md CHANGED
@@ -2,14 +2,7 @@
2
2
 
3
3
  ## Haml
4
4
 
5
- ### Why is my markup indented properly in development mode, but not in production?
6
- {#q-indentation-in-production}
7
-
8
- To improve performance, Haml defaults to {Haml::Options#ugly "ugly" mode} in
9
- Rails apps running in production.
10
-
11
- ### How do I put a punctuation mark after an element, like "`I like <strong>cake</strong>!`"?
12
- {#q-punctuation}
5
+ ### How do I put a punctuation mark after an element, like "`I like <strong>cake</strong>!`"? {#q-punctuation}
13
6
 
14
7
  Expressing the structure of a document
15
8
  and expressing inline formatting are two very different problems.
@@ -37,8 +30,7 @@ then it's even easier:
37
30
 
38
31
  %p== I like #{link_to 'chocolate', 'http://franschocolates.com'}!
39
32
 
40
- ### How do I stop Haml from indenting the contents of my `pre` and `textarea` tags?
41
- {#q-preserve}
33
+ ### How do I stop Haml from indenting the contents of my `pre` and `textarea` tags? {#q-preserve}
42
34
 
43
35
  Because Haml automatically indents the HTML source code,
44
36
  the contents of whitespace-sensitive tags like `pre` and `textarea`
@@ -78,8 +70,7 @@ and renders
78
70
 
79
71
  <p><textarea>Foo&#x000A;Bar</textarea></p>
80
72
 
81
- ### How do I make my long lines of Ruby code look nicer in my Haml document?
82
- {#q-multiline}
73
+ ### How do I make my long lines of Ruby code look nicer in my Haml document? {#q-multiline}
83
74
 
84
75
  Put them in a helper or your model.
85
76
 
@@ -125,8 +116,7 @@ in Haml, you have to do
125
116
  - form_for stuff do
126
117
  ...
127
118
 
128
- ### I have Haml installed. Why is Rails (only looking for `.html.erb` files | rendering Haml files as plain text | rendering Haml files as blank pages)?
129
- {#q-blank-page}
119
+ ### I have Haml installed. Why is Rails (only looking for `.html.erb` files | rendering Haml files as plain text | rendering Haml files as blank pages)? {#q-blank-page}
130
120
 
131
121
  There are several reasons these things might be happening.
132
122
  First of all, make sure that Haml really is installed;
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2009 Hampton Catlin and Nathan Weizenbaum
1
+ Copyright (c) 2006-2009 Hampton Catlin and Natalie Weizenbaum
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Haml
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/haml/haml.png?branch=master)](http://travis-ci.org/haml/haml)
3
+ [![Gem Version](https://badge.fury.io/rb/haml.svg)](http://rubygems.org/gems/haml)
4
+ [![Build Status](https://travis-ci.org/haml/haml.svg?branch=master)](http://travis-ci.org/haml/haml)
5
+ [![Code Climate](http://img.shields.io/codeclimate/github/haml/haml.svg)](https://codeclimate.com/github/haml/haml)
6
+ [![Coverage Status](http://img.shields.io/coveralls/haml/haml.svg)](https://coveralls.io/r/haml/haml)
7
+ [![Inline docs](http://inch-ci.org/github/haml/haml.png)](http://inch-ci.org/github/haml/haml)
4
8
 
5
9
  Haml is a templating engine for HTML. It's designed to make it both easier and
6
10
  more pleasant to write HTML documents, by eliminating redundancy, reflecting the
@@ -12,23 +16,38 @@ that's both powerful and easy to understand.
12
16
  Haml can be used from the command line or as part of a Ruby web framework. The
13
17
  first step is to install the gem:
14
18
 
15
- gem install haml
19
+ ~~~sh
20
+ gem install haml
21
+ ~~~
16
22
 
17
23
  After you write some Haml, you can run
18
24
 
19
- haml document.haml
25
+ ~~~sh
26
+ haml document.haml
27
+ ~~~
20
28
 
21
29
  to compile it to HTML. For more information on these commands, check out
22
30
 
23
- haml --help
31
+ ~~~sh
32
+ haml --help
33
+ ~~~
24
34
 
25
- To use Haml programatically, check out the [YARD
26
- documentation](http://haml.info/docs/yardoc/).
35
+ To use Haml programatically, check out the [YARD documentation](http://haml.info/docs/yardoc/).
27
36
 
28
37
  ## Using Haml with Rails
29
38
 
30
39
  To use Haml with Rails, simply add Haml to your Gemfile and run `bundle`.
31
40
 
41
+ ~~~ruby
42
+ gem 'haml'
43
+ ~~~
44
+
45
+ Haml 5 will require Rails version 4.0 or later. If you are using Rails 3.x, you should use Haml version 4.0.x:
46
+
47
+ ~~~ruby
48
+ gem 'haml', '~> 4.0.5'
49
+ ~~~
50
+
32
51
  If you'd like to replace Rails's Erb-based generators with Haml, add
33
52
  [haml-rails](https://github.com/indirect/haml-rails) to your Gemfile as well.
34
53
 
@@ -36,58 +55,76 @@ If you'd like to replace Rails's Erb-based generators with Haml, add
36
55
 
37
56
  The most basic element of Haml is a shorthand for creating HTML:
38
57
 
39
- %tagname{:attr1 => 'value1', :attr2 => 'value2'} Contents
58
+ ~~~haml
59
+ %tagname{:attr1 => 'value1', :attr2 => 'value2'} Contents
60
+ ~~~
40
61
 
41
62
  No end-tag is needed; Haml handles that automatically. If you prefer HTML-style
42
63
  attributes, you can also use:
43
64
 
44
- %tagname(attr1='value1' attr2='value2') Contents
65
+ ~~~haml
66
+ %tagname(attr1='value1' attr2='value2') Contents
67
+ ~~~
45
68
 
46
69
  Adding `class` and `id` attributes is even easier. Haml uses the same syntax as
47
70
  the CSS that styles the document:
48
71
 
49
- %tagname#id.class
72
+ ~~~haml
73
+ %tagname#id.class
74
+ ~~~
50
75
 
51
76
  In fact, when you're using the `<div>` tag, it becomes _even easier_. Because
52
77
  `<div>` is such a common element, a tag without a name defaults to a div. So
53
78
 
54
- #foo Hello!
79
+ ~~~haml
80
+ #foo Hello!
81
+ ~~~
55
82
 
56
83
  becomes
57
84
 
58
- <div id='foo'>Hello!</div>
85
+ ~~~html
86
+ <div id='foo'>Hello!</div>
87
+ ~~~
59
88
 
60
89
  Haml uses indentation to bring the individual elements to represent the HTML
61
90
  structure. A tag's children are indented beneath than the parent tag. Again, a
62
91
  closing tag is automatically added. For example:
63
92
 
64
- %ul
65
- %li Salt
66
- %li Pepper
93
+ ~~~haml
94
+ %ul
95
+ %li Salt
96
+ %li Pepper
97
+ ~~~
67
98
 
68
99
  becomes:
69
100
 
70
- <ul>
71
- <li>Salt</li>
72
- <li>Pepper</li>
73
- </ul>
101
+ ~~~html
102
+ <ul>
103
+ <li>Salt</li>
104
+ <li>Pepper</li>
105
+ </ul>
106
+ ~~~
74
107
 
75
108
  You can also put plain text as a child of an element:
76
109
 
77
- %p
78
- Hello,
79
- World!
110
+ ~~~haml
111
+ %p
112
+ Hello,
113
+ World!
114
+ ~~~
80
115
 
81
116
  It's also possible to embed Ruby code into Haml documents. An equals sign, `=`,
82
117
  will output the result of the code. A hyphen, `-`, will run the code but not
83
118
  output the result. You can even use control statements like `if` and `while`:
84
119
 
85
- %p
86
- Date/Time:
87
- - now = DateTime.now
88
- %strong= now
89
- - if now > DateTime.parse("December 31, 2006")
90
- = "Happy new " + "year!"
120
+ ~~~haml
121
+ %p
122
+ Date/Time:
123
+ - now = DateTime.now
124
+ %strong= now
125
+ - if now > DateTime.parse("December 31, 2006")
126
+ = "Happy new " + "year!"
127
+ ~~~
91
128
 
92
129
  Haml provides far more tools than those presented here. Check out the [reference
93
130
  documentation](http://haml.info/docs/yardoc/file.REFERENCE.html)
@@ -105,18 +142,22 @@ Contributions are welcomed, but before you get started please read the
105
142
  [guidelines](http://haml.info/development.html#contributing).
106
143
 
107
144
  After forking and then cloning the repo locally, install Bundler and then use it
108
- to install the development gem dependecies:
109
-
110
- gem install bundler
111
- bundle install
145
+ to install the development gem dependencies:
146
+ ~~~sh
147
+ gem install bundler
148
+ bundle install
149
+ ~~~
112
150
 
113
151
  Once this is complete, you should be able to run the test suite:
114
-
115
- rake
152
+ ~~~sh
153
+ rake
154
+ ~~~
116
155
 
117
156
  You'll get a warning that you need to install haml-spec, so run this:
118
157
 
119
- git submodule update --init
158
+ ~~~sh
159
+ git submodule update --init
160
+ ~~~
120
161
 
121
162
  At this point `rake` should run without error or warning and you are ready to
122
163
  start working on your patch!
@@ -124,18 +165,19 @@ start working on your patch!
124
165
  Note that you can also run just one test out of the test suite if you're working
125
166
  on a specific area:
126
167
 
127
- ruby -Itest test/helper_test.rb -n test_buffer_access
168
+ ~~~sh
169
+ ruby -Itest test/helper_test.rb -n test_buffer_access
170
+ ~~~
128
171
 
129
- Haml supports Ruby 1.8.7 and higher, so please make sure your changes run on
130
- both 1.9 and 1.8.
172
+ Haml currently supports Ruby 2.0.0 and higher, so please make sure your changes run on 2.0+.
131
173
 
132
174
  ## Team
133
175
 
134
176
  ### Current Maintainers
135
177
 
136
- * [Norman Clarke](http://github.com/norman)
137
- * [Matt Wildig](http://github.com/mattwildig)
138
178
  * [Akira Matsuda](https://github.com/amatsuda)
179
+ * [Matt Wildig](https://github.com/mattwildig)
180
+ * [Tee Parham](https://github.com/teeparham)
139
181
 
140
182
  ### Alumni
141
183
 
@@ -143,17 +185,18 @@ Haml was created by [Hampton Catlin](http://hamptoncatlin.com), the author of
143
185
  the original implementation. Hampton is no longer involved in day-to-day coding,
144
186
  but still consults on language issues.
145
187
 
146
- [Nathan Weizenbaum](http://nex-3.com) was for many years the primary developer
188
+ [Natalie Weizenbaum](http://nex-3.com) was for many years the primary developer
147
189
  and architect of the "modern" Ruby implementation of Haml.
148
190
 
191
+ [Norman Clarke](http://github.com/norman) was the primary maintainer of Haml from 2012 to 2016.
149
192
 
150
193
  ## License
151
194
 
152
- Some of Nathan's work on Haml was supported by Unspace Interactive.
195
+ Some of Natalie's work on Haml was supported by Unspace Interactive.
153
196
 
154
197
  Beyond that, the implementation is licensed under the MIT License.
155
198
 
156
- Copyright (c) 2006-2013 Hampton Catlin, Nathan Weizenbaum and the Haml team
199
+ Copyright (c) 2006-2013 Hampton Catlin, Natalie Weizenbaum and the Haml team
157
200
 
158
201
  Permission is hereby granted, free of charge, to any person obtaining a copy of
159
202
  this software and associated documentation files (the "Software"), to deal in