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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6db8c2e57e4132457faca789a5700112ee9a8e5
4
- data.tar.gz: c4f15045d582be5eeb7daecb3781c6102920beb9
3
+ metadata.gz: 056cc654414c29999474b5115839d33e5ebc9a20
4
+ data.tar.gz: e56a16b4d053d863af5e9a89200d413d7901f3f7
5
5
  SHA512:
6
- metadata.gz: 3fabebdd299e3cea1516c42d40b6d63c96dbcf073434d11794403933b7b6fb233e0460908317256abbb07b7281da3b3582ac1b26676725cdc6462cbd31234d00
7
- data.tar.gz: 3eff7188b9d214cf4face1dc8078c598c45369cb70a4caad27d74fc53d29ab7de5748ff7997a24b6dc807c4ee926c72bf6373885bc517ba525b541fe8bdf5ee9
6
+ metadata.gz: 7dbf54da5889f0477f6122eb5178310a1e0167f0aaed5f6b495efc6de108183a228bda85ae5a10c46862443e10d30836351d826bdda86d4ebede4b5221ed6b19
7
+ data.tar.gz: 5d77752a502ab13aaac1e1af68876ff9084913d4a82491c0e790ae851d8975931a478fd59779d5acb92587ebfbff93de4d33411945e0c3a726e5d7fd68902732
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"
@@ -1,9 +1,9 @@
1
1
  # Haml Changelog
2
2
 
3
- ## 4.1.0 (Unreleased)
3
+ ## 5.0.0 (Unreleased)
4
4
 
5
- * Haml now requires Ruby 1.9.2 or above.
6
- * Rails 3.0 and 3.1 are no longer supported, matching the official
5
+ * Haml now requires Ruby 2.0.0 or above.
6
+ * Rails 3 is no longer supported, matching the official
7
7
  [Maintenance Policy for Ruby on Rails](http://weblog.rubyonrails.org/2013/2/24/maintenance-policy-for-ruby-on-rails/).
8
8
  (Tee Parham)
9
9
  * Fix for attribute merging. When an attribute method (or literal nested hash)
@@ -14,6 +14,37 @@
14
14
  * Make escape_once respect hexadecimal references. (Matt Wildig)
15
15
  * General performance and memory usage improvements. (Akira Matsuda)
16
16
  * Don't treat the 'data' attribute specially when merging attribute hashes. (Matt Wildig and Norman Clarke)
17
+ * Add a tracing option. When enabled, Haml will output a data-trace attribute on each tag showing the path
18
+ to the source Haml file from which it was generated. Thanks [Alex Babkin](https://github.com/ababkin).
19
+ * Fix #@foo and #$foo style interpolation that was not working in html_safe mode. (Akira Matsuda)
20
+ * Add `haml_tag_if` to render a block, conditionally wrapped in another element (Matt Wildig)
21
+ * The `haml` command's debug option (`-d`) no longer executes the Haml code, but
22
+ rather checks the generated Ruby syntax for errors.
23
+ * Support Rails 5.1 Erubi template handler.
24
+ * Raise `Haml::InvalidAttributeNameError` when attribute name includes invalid characters. (Takashi Kokubun)
25
+ * Drop dynamic quotes support and always escape `'` for `escape_html`/`escape_attrs` instead.
26
+ Also, escaped results are slightly changed and always unified to the same characters. (Takashi Kokubun)
27
+ * Don't preserve newlines in attributes. (Takashi Kokubun)
28
+ * Add temple gem as dependency and create `Haml::TempleEngine` class.
29
+ Some methods in `Haml::Compiler` are migrated to `Haml::TempleEngine`. (Takashi Kokubun)
30
+ * Drop parser/compiler accessor from `Haml::Engine`. Modify `Haml::Engine#initialize` options
31
+ or `Haml::Template.options` instead. (Takashi Kokubun)
32
+ * Don't ignore unexpected exceptions on initializing `ActionView::OutputBuffer`. (Takashi Kokubun)
33
+ * Analyze attribute values by Ripper and render static attributes beforehand. (Takashi Kokubun)
34
+ * Optimize attribute rendering about 3x faster. (Takashi Kokubun)
35
+
36
+ ## 4.0.7
37
+
38
+ Released on August 10, 2015
39
+ ([diff](https://github.com/haml/haml/compare/4.0.6...4.0.7)).
40
+
41
+ * Significantly improve performance of regexp used to fix whitespace handling in textareas (thanks [Stan Hu](https://github.com/stanhu)).
42
+
43
+ ## 4.0.6
44
+
45
+ Released on Dec 1, 2014 ([diff](https://github.com/haml/haml/compare/4.0.5...4.0.6)).
46
+
47
+ * Fix warning on Ruby 1.8.7 "regexp has invalid interval" (thanks [Elia Schito](https://github.com/elia)).
17
48
 
18
49
  ## 4.0.5
19
50
 
@@ -77,7 +108,7 @@ Released March 21, 2013 ([diff](https://github.com/haml/haml/compare/4.0.0...4.0
77
108
 
78
109
  ## 4.0.0
79
110
 
80
- * The Haml exectutable now accepts an `--autoclose` option. You can now
111
+ * The Haml executable now accepts an `--autoclose` option. You can now
81
112
  specify a list of tags that should be autoclosed
82
113
 
83
114
  * The `:ruby` filter no longer redirects $stdout to the Haml document, as this
@@ -114,7 +145,7 @@ Released March 21, 2013 ([diff](https://github.com/haml/haml/compare/4.0.0...4.0
114
145
 
115
146
  * All Hash attribute values are now treated as HTML5 data, regardless of key.
116
147
  Previously only the "data" key was treated this way. Allowing arbitrary keys
117
- means you can now easily use this feauture for Aria attributes, among other
148
+ means you can now easily use this feature for Aria attributes, among other
118
149
  uses.
119
150
  (thanks to [Elvin Efendi](https://github.com/ElvinEfendi))
120
151
 
@@ -533,7 +564,6 @@ The {file:HAML_REFERENCE.md#ugly-option `:ugly` option} is now on by default
533
564
  in the testing environment in Rails to help tests run faster.
534
565
 
535
566
  ## 3.0.0
536
- {#3-0-0}
537
567
 
538
568
  [Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.0).
539
569
 
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;
@@ -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,8 +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)
4
- [![Code Climate](https://codeclimate.com/github/haml/haml.png)](https://codeclimate.com/github/haml/haml)
5
- [![Coverage Status](https://coveralls.io/repos/haml/haml/badge.png)](https://coveralls.io/r/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)
6
8
 
7
9
  Haml is a templating engine for HTML. It's designed to make it both easier and
8
10
  more pleasant to write HTML documents, by eliminating redundancy, reflecting the
@@ -14,29 +16,37 @@ that's both powerful and easy to understand.
14
16
  Haml can be used from the command line or as part of a Ruby web framework. The
15
17
  first step is to install the gem:
16
18
 
17
- gem install haml
19
+ ~~~sh
20
+ gem install haml
21
+ ~~~
18
22
 
19
23
  After you write some Haml, you can run
20
24
 
21
- haml document.haml
25
+ ~~~sh
26
+ haml document.haml
27
+ ~~~
22
28
 
23
29
  to compile it to HTML. For more information on these commands, check out
24
30
 
25
- haml --help
31
+ ~~~sh
32
+ haml --help
33
+ ~~~
26
34
 
27
- To use Haml programatically, check out the [YARD
28
- documentation](http://haml.info/docs/yardoc/).
35
+ To use Haml programatically, check out the [YARD documentation](http://haml.info/docs/yardoc/).
29
36
 
30
37
  ## Using Haml with Rails
31
38
 
32
39
  To use Haml with Rails, simply add Haml to your Gemfile and run `bundle`.
33
40
 
34
- gem 'haml'
41
+ ~~~ruby
42
+ gem 'haml'
43
+ ~~~
35
44
 
36
- Haml 4.1 requires an actively maintained version of Rails (version 3.2 or later).
37
- If you are using Rails 3.0 or 3.1, you should use Haml version 4.0.x:
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:
38
46
 
39
- gem 'haml', '~> 4.0.4'
47
+ ~~~ruby
48
+ gem 'haml', '~> 4.0.5'
49
+ ~~~
40
50
 
41
51
  If you'd like to replace Rails's Erb-based generators with Haml, add
42
52
  [haml-rails](https://github.com/indirect/haml-rails) to your Gemfile as well.
@@ -45,58 +55,76 @@ If you'd like to replace Rails's Erb-based generators with Haml, add
45
55
 
46
56
  The most basic element of Haml is a shorthand for creating HTML:
47
57
 
48
- %tagname{:attr1 => 'value1', :attr2 => 'value2'} Contents
58
+ ~~~haml
59
+ %tagname{:attr1 => 'value1', :attr2 => 'value2'} Contents
60
+ ~~~
49
61
 
50
62
  No end-tag is needed; Haml handles that automatically. If you prefer HTML-style
51
63
  attributes, you can also use:
52
64
 
53
- %tagname(attr1='value1' attr2='value2') Contents
65
+ ~~~haml
66
+ %tagname(attr1='value1' attr2='value2') Contents
67
+ ~~~
54
68
 
55
69
  Adding `class` and `id` attributes is even easier. Haml uses the same syntax as
56
70
  the CSS that styles the document:
57
71
 
58
- %tagname#id.class
72
+ ~~~haml
73
+ %tagname#id.class
74
+ ~~~
59
75
 
60
76
  In fact, when you're using the `<div>` tag, it becomes _even easier_. Because
61
77
  `<div>` is such a common element, a tag without a name defaults to a div. So
62
78
 
63
- #foo Hello!
79
+ ~~~haml
80
+ #foo Hello!
81
+ ~~~
64
82
 
65
83
  becomes
66
84
 
67
- <div id='foo'>Hello!</div>
85
+ ~~~html
86
+ <div id='foo'>Hello!</div>
87
+ ~~~
68
88
 
69
89
  Haml uses indentation to bring the individual elements to represent the HTML
70
90
  structure. A tag's children are indented beneath than the parent tag. Again, a
71
91
  closing tag is automatically added. For example:
72
92
 
73
- %ul
74
- %li Salt
75
- %li Pepper
93
+ ~~~haml
94
+ %ul
95
+ %li Salt
96
+ %li Pepper
97
+ ~~~
76
98
 
77
99
  becomes:
78
100
 
79
- <ul>
80
- <li>Salt</li>
81
- <li>Pepper</li>
82
- </ul>
101
+ ~~~html
102
+ <ul>
103
+ <li>Salt</li>
104
+ <li>Pepper</li>
105
+ </ul>
106
+ ~~~
83
107
 
84
108
  You can also put plain text as a child of an element:
85
109
 
86
- %p
87
- Hello,
88
- World!
110
+ ~~~haml
111
+ %p
112
+ Hello,
113
+ World!
114
+ ~~~
89
115
 
90
116
  It's also possible to embed Ruby code into Haml documents. An equals sign, `=`,
91
117
  will output the result of the code. A hyphen, `-`, will run the code but not
92
118
  output the result. You can even use control statements like `if` and `while`:
93
119
 
94
- %p
95
- Date/Time:
96
- - now = DateTime.now
97
- %strong= now
98
- - if now > DateTime.parse("December 31, 2006")
99
- = "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
+ ~~~
100
128
 
101
129
  Haml provides far more tools than those presented here. Check out the [reference
102
130
  documentation](http://haml.info/docs/yardoc/file.REFERENCE.html)
@@ -114,18 +142,22 @@ Contributions are welcomed, but before you get started please read the
114
142
  [guidelines](http://haml.info/development.html#contributing).
115
143
 
116
144
  After forking and then cloning the repo locally, install Bundler and then use it
117
- to install the development gem dependecies:
118
-
119
- gem install bundler
120
- bundle install
145
+ to install the development gem dependencies:
146
+ ~~~sh
147
+ gem install bundler
148
+ bundle install
149
+ ~~~
121
150
 
122
151
  Once this is complete, you should be able to run the test suite:
123
-
124
- rake
152
+ ~~~sh
153
+ rake
154
+ ~~~
125
155
 
126
156
  You'll get a warning that you need to install haml-spec, so run this:
127
157
 
128
- git submodule update --init
158
+ ~~~sh
159
+ git submodule update --init
160
+ ~~~
129
161
 
130
162
  At this point `rake` should run without error or warning and you are ready to
131
163
  start working on your patch!
@@ -133,18 +165,18 @@ start working on your patch!
133
165
  Note that you can also run just one test out of the test suite if you're working
134
166
  on a specific area:
135
167
 
136
- ruby -Itest test/helper_test.rb -n test_buffer_access
168
+ ~~~sh
169
+ ruby -Itest test/helper_test.rb -n test_buffer_access
170
+ ~~~
137
171
 
138
- Haml supports Ruby 1.9.2 and higher, so please make sure your changes run on
139
- both 1.9 and 2.0.
172
+ Haml currently supports Ruby 2.0.0 and higher, so please make sure your changes run on 2.0+.
140
173
 
141
174
  ## Team
142
175
 
143
176
  ### Current Maintainers
144
177
 
145
- * [Norman Clarke](http://github.com/norman)
146
- * [Matt Wildig](http://github.com/mattwildig)
147
178
  * [Akira Matsuda](https://github.com/amatsuda)
179
+ * [Matt Wildig](https://github.com/mattwildig)
148
180
  * [Tee Parham](https://github.com/teeparham)
149
181
 
150
182
  ### Alumni
@@ -153,17 +185,18 @@ Haml was created by [Hampton Catlin](http://hamptoncatlin.com), the author of
153
185
  the original implementation. Hampton is no longer involved in day-to-day coding,
154
186
  but still consults on language issues.
155
187
 
156
- [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
157
189
  and architect of the "modern" Ruby implementation of Haml.
158
190
 
191
+ [Norman Clarke](http://github.com/norman) was the primary maintainer of Haml from 2012 to 2016.
159
192
 
160
193
  ## License
161
194
 
162
- 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.
163
196
 
164
197
  Beyond that, the implementation is licensed under the MIT License.
165
198
 
166
- 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
167
200
 
168
201
  Permission is hereby granted, free of charge, to any person obtaining a copy of
169
202
  this software and associated documentation files (the "Software"), to deal in
@@ -233,8 +233,7 @@ is compiled to:
233
233
 
234
234
  <script src='javascripts/script_9' type='text/javascript'></script>
235
235
 
236
- #### `:class` and `:id` Attributes
237
- {#class-and-id-attributes}
236
+ #### `:class` and `:id` Attributes {#class-and-id-attributes}
238
237
 
239
238
  The `:class` and `:id` attributes can also be specified as a Ruby array whose
240
239
  elements will be joined together. A `:class` array is joined with `" "` and an
@@ -329,7 +328,7 @@ This is compiled to:
329
328
  </html>
330
329
 
331
330
  You can use as many such attribute methods as you want by separating them with
332
- commas, like a Ruby argument list. All the hashes will me merged together, from
331
+ commas, like a Ruby argument list. All the hashes will be merged together, from
333
332
  left to right. For example, if you defined
334
333
 
335
334
  def hash1
@@ -389,27 +388,49 @@ or using `true` and `false`:
389
388
 
390
389
  %input(selected=true)
391
390
 
392
- #### HTML5 Custom Data Attributes
391
+ <!-- The title to the next section (Prefixed Attributes) has changed. This
392
+ <a> tag is so old links to here still work. -->
393
+ <a id="html5_custom_data_attributes" style="border:0;"></a>
393
394
 
394
- HTML5 allows for adding [custom non-visible data
395
- attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#embedding-custom-non-visible-data)
396
- to elements using attribute names beginning with `data-`. Custom data attributes
397
- can be used in Haml by using the key `:data` with a Hash value in an attribute
398
- hash. Each of the key/value pairs in the Hash will be transformed into a custom
399
- data attribute. For example:
395
+ #### Prefixed Attributes
400
396
 
401
- %a{:href=>"/posts", :data => {:author_id => 123}} Posts By Author
397
+ HTML5 allows for adding
398
+ [custom non-visible data attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
399
+ to elements using attribute names beginning with `data-`. The
400
+ [Accessible Rich Internet Applications](http://www.w3.org/WAI/intro/aria)
401
+ specification makes use of attributes beginning with `aria-`. There are also
402
+ frameworks that use non-standard attributes with a common prefix.
403
+
404
+ Haml can help generate collections of attributes that share a prefix like
405
+ these. Any entry in an attribute hash that has a Hash as its value is expanded
406
+ into a series of attributes, one for each key/value pair in the hash, with the
407
+ attribute name formed by joining the “parent” key name to the key name with a
408
+ hyphen.
409
+
410
+ For example:
411
+
412
+ %a{:href=>"/posts", :data => {:author_id => 123, :category => 7}} Posts By Author
402
413
 
403
414
  will render as:
404
415
 
405
- <a data-author-id='123' href='/posts'>Posts By Author</a>
416
+ <a data-author-id='123' data-category='7' href='/posts'>Posts By Author</a>
406
417
 
407
418
  Notice that the underscore in `author_id` was replaced by a hyphen. If you wish
408
419
  to suppress this behavior, you can set Haml's
409
420
  {Haml::Options#hyphenate_data_attrs `:hyphenate_data_attrs` option} to `false`,
410
421
  and the output will be rendered as:
411
422
 
412
- <a data-author_id='123' href='/posts'>Posts By Author</a>
423
+ <a data-author_id='123' data-category='7' href='/posts'>Posts By Author</a>
424
+
425
+ This expansion of hashes is recursive – any value of the child hash that is
426
+ itself a hash will create an attribute for each entry, with the attribute name
427
+ prefixed with all ancestor keys. For example:
428
+
429
+ .book-info{:data => {:book => {:id => 123, :genre => 'programming'}, :category => 7}}
430
+
431
+ will render as:
432
+
433
+ <div class='book-info' data-book-genre='programming' data-book-id='123' data-category='7'></div>
413
434
 
414
435
  ### Class and ID: `.` and `#`
415
436
 
@@ -1000,6 +1021,21 @@ might compile to:
1000
1021
  //]]>
1001
1022
  </script>
1002
1023
 
1024
+ #### Gotchas
1025
+
1026
+ Haml uses an overly simplistic regular expression to identify string
1027
+ interpolation rather than a full-blown Ruby parser. This is fast and works for
1028
+ most code but you may have errors with code like the following:
1029
+
1030
+ %span #{'{'}
1031
+
1032
+ This code will generate a syntax error, complaining about unbalanced brackets.
1033
+ In cases like this, the recommended workaround is output the code as a Ruby
1034
+ string to force Haml to parse the code with Ruby.
1035
+
1036
+ %span= "#{'{'}"
1037
+
1038
+
1003
1039
  ### Escaping HTML: `&=` {#escaping_html}
1004
1040
 
1005
1041
  An ampersand followed by one or two equals characters evaluates Ruby code just
@@ -1102,53 +1138,53 @@ more info.
1102
1138
 
1103
1139
  Haml comes with the following filters defined:
1104
1140
 
1105
- {#cdata-filter}
1106
- ### `:cdata`
1141
+ ### `:cdata` {#cdata-filter}
1142
+
1107
1143
  Surrounds the filtered text with CDATA tags.
1108
1144
 
1109
- {#coffee-filter}
1110
- ### `:coffee`
1145
+ ### `:coffee` {#coffee-filter}
1146
+
1111
1147
  Compiles the filtered text to Javascript using Coffeescript. You can also
1112
1148
  reference this filter as `:coffeescript`. This filter is implemented using
1113
1149
  Tilt.
1114
1150
 
1115
- {#css-filter}
1116
- ### `:css`
1151
+ ### `:css` {#css-filter}
1152
+
1117
1153
  Surrounds the filtered text with `<style>` and (optionally) CDATA tags. Useful
1118
1154
  for including inline CSS. Use the {Haml::Options#cdata `:cdata` option} to
1119
1155
  control when CDATA tags are added.
1120
1156
 
1121
- {#erb-filter}
1122
- ### `:erb`
1123
- Parses the filtered text with ERb, like an RHTML template. Not available if the
1157
+ ### `:erb` {#erb-filter}
1158
+
1159
+ Parses the filtered text with ERB, like an RHTML template. Not available if the
1124
1160
  {Haml::Options#suppress_eval `:suppress_eval`} option is set to true. Embedded
1125
1161
  Ruby code is evaluated in the same context as the Haml template. This filter is
1126
1162
  implemented using Tilt.
1127
1163
 
1128
- {#escaped-filter}
1129
- ### `:escaped`
1164
+ ### `:escaped` {#escaped-filter}
1165
+
1130
1166
  Works the same as plain, but HTML-escapes the text
1131
1167
  before placing it in the document.
1132
1168
 
1133
- {#javascript-filter}
1134
- ### `:javascript`
1169
+ ### `:javascript` {#javascript-filter}
1170
+
1135
1171
  Surrounds the filtered text with `<script>` and (optionally) CDATA tags.
1136
1172
  Useful for including inline Javascript. Use the {Haml::Options#cdata `:cdata`
1137
1173
  option} to control when CDATA tags are added.
1138
1174
 
1139
- {#less-filter}
1140
- ### `:less`
1175
+ ### `:less` {#less-filter}
1176
+
1141
1177
  Parses the filtered text with [Less](http://lesscss.org/) to produce CSS output.
1142
1178
  This filter is implemented using Tilt.
1143
1179
 
1144
- {#markdown-filter}
1145
- ### `:markdown`
1180
+ ### `:markdown` {#markdown-filter}
1181
+
1146
1182
  Parses the filtered text with
1147
1183
  [Markdown](http://daringfireball.net/projects/markdown). This filter is
1148
1184
  implemented using Tilt.
1149
1185
 
1150
- {#maruku-filter}
1151
- ### `:maruku`
1186
+ ### `:maruku` {#maruku-filter}
1187
+
1152
1188
  Parses the filtered text with [Maruku](https://github.com/nex3/maruku), which
1153
1189
  has some non-standard extensions to Markdown.
1154
1190
 
@@ -1157,39 +1193,39 @@ contrib](https://github.com/haml/haml-contrib) but is loaded automatically for
1157
1193
  historical reasons. In future versions of Haml it will likely not be loaded by
1158
1194
  default. This filter is implemented using Tilt.
1159
1195
 
1160
- {#plain-filter}
1161
- ### `:plain`
1196
+ ### `:plain` {#plain-filter}
1197
+
1162
1198
  Does not parse the filtered text. This is useful for large blocks of text
1163
1199
  without HTML tags, when you don't want lines starting with `.` or `-` to be
1164
1200
  parsed.
1165
1201
 
1166
- {#preserve-filter}
1167
- ### `:preserve`
1202
+ ### `:preserve` {#preserve-filter}
1203
+
1168
1204
  Inserts the filtered text into the template with whitespace preserved.
1169
1205
  `preserve`d blocks of text aren't indented, and newlines are replaced with the
1170
1206
  HTML escape code for newlines, to preserve nice-looking output. See also
1171
1207
  [Whitespace Preservation](#whitespace_preservation).
1172
1208
 
1173
- {#ruby-filter}
1174
- ### `:ruby`
1209
+ ### `:ruby` {#ruby-filter}
1210
+
1175
1211
  Parses the filtered text with the normal Ruby interpreter. Creates an `IO`
1176
1212
  object named `haml_io`, anything written to it is output into the Haml document.
1177
1213
  Not available if the {Haml::Options#suppress_eval `:suppress_eval`} option is
1178
1214
  set to true. The Ruby code is evaluated in the same context as the Haml
1179
1215
  template.
1180
1216
 
1181
- {#sass-filter}
1182
- ### `:sass`
1217
+ ### `:sass` {#sass-filter}
1218
+
1183
1219
  Parses the filtered text with [Sass](http://sass-lang.com/) to produce CSS
1184
1220
  output. This filter is implemented using Tilt.
1185
1221
 
1186
- {#scss-filter}
1187
- ### `:scss`
1222
+ ### `:scss` {#scss-filter}
1223
+
1188
1224
  Parses the filtered text with Sass like the `:sass` filter, but uses the newer
1189
1225
  SCSS syntax to produce CSS output. This filter is implemented using Tilt.
1190
1226
 
1191
- {#textile-filter}
1192
- ### `:textile`
1227
+ ### `:textile` {#textile-filter}
1228
+
1193
1229
  Parses the filtered text with [Textile](http://www.textism.com/tools/textile).
1194
1230
  Only works if [RedCloth](http://redcloth.org) is installed.
1195
1231
 
@@ -1209,8 +1245,8 @@ the whitespace removal methods allow. There are a few helper methods that are
1209
1245
  useful when dealing with inline content. All these methods take a Haml block to
1210
1246
  modify.
1211
1247
 
1212
- {#surround}
1213
- ### surround
1248
+ ### surround {#surround}
1249
+
1214
1250
  Surrounds a Haml block with text. Expects 1 or 2 string arguments used to
1215
1251
  surround the Haml block. If a second argument is not provided, the first
1216
1252
  argument is used as the second.
@@ -1218,15 +1254,15 @@ argument is used as the second.
1218
1254
  = surround "(", ")" do
1219
1255
  = link_to "learn more", "#"
1220
1256
 
1221
- {#precede}
1222
- ### precede
1257
+ ### precede {#precede}
1258
+
1223
1259
  Prepends a Haml block with text. Expects 1 argument.
1224
1260
 
1225
1261
  = precede "*" do
1226
1262
  %span Required
1227
1263
 
1228
- {#succeed}
1229
- ### succeed
1264
+ ### succeed {#succeed}
1265
+
1230
1266
  Appends a Haml block with text. Expects 1 argument.
1231
1267
 
1232
1268
  Begin by