haml 5.2.2 → 6.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/test.yml +13 -9
  4. data/.gitignore +16 -16
  5. data/.yardopts +0 -3
  6. data/CHANGELOG.md +74 -3
  7. data/Gemfile +18 -11
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +17 -23
  10. data/REFERENCE.md +63 -138
  11. data/Rakefile +48 -81
  12. data/bin/bench +66 -0
  13. data/bin/console +11 -0
  14. data/bin/ruby +3 -0
  15. data/bin/setup +7 -0
  16. data/bin/stackprof +27 -0
  17. data/bin/test +24 -0
  18. data/exe/haml +6 -0
  19. data/ext/haml/extconf.rb +10 -0
  20. data/ext/haml/haml.c +537 -0
  21. data/ext/haml/hescape.c +108 -0
  22. data/ext/haml/hescape.h +20 -0
  23. data/haml.gemspec +39 -37
  24. data/lib/haml/ambles.rb +20 -0
  25. data/lib/haml/attribute_builder.rb +134 -179
  26. data/lib/haml/attribute_compiler.rb +85 -194
  27. data/lib/haml/attribute_parser.rb +92 -126
  28. data/lib/haml/cli.rb +154 -0
  29. data/lib/haml/compiler/children_compiler.rb +126 -0
  30. data/lib/haml/compiler/comment_compiler.rb +39 -0
  31. data/lib/haml/compiler/doctype_compiler.rb +46 -0
  32. data/lib/haml/compiler/script_compiler.rb +116 -0
  33. data/lib/haml/compiler/silent_script_compiler.rb +24 -0
  34. data/lib/haml/compiler/tag_compiler.rb +76 -0
  35. data/lib/haml/compiler.rb +63 -296
  36. data/lib/haml/dynamic_merger.rb +67 -0
  37. data/lib/haml/engine.rb +44 -227
  38. data/lib/haml/error.rb +5 -4
  39. data/lib/haml/escapable.rb +6 -70
  40. data/lib/haml/filters/base.rb +12 -0
  41. data/lib/haml/filters/cdata.rb +20 -0
  42. data/lib/haml/filters/coffee.rb +17 -0
  43. data/lib/haml/filters/css.rb +33 -0
  44. data/lib/haml/filters/erb.rb +10 -0
  45. data/lib/haml/filters/escaped.rb +22 -0
  46. data/lib/haml/filters/javascript.rb +33 -0
  47. data/lib/haml/filters/less.rb +20 -0
  48. data/lib/haml/filters/markdown.rb +11 -0
  49. data/lib/haml/filters/plain.rb +29 -0
  50. data/lib/haml/filters/preserve.rb +22 -0
  51. data/lib/haml/filters/ruby.rb +10 -0
  52. data/lib/haml/filters/sass.rb +15 -0
  53. data/lib/haml/filters/scss.rb +15 -0
  54. data/lib/haml/filters/text_base.rb +25 -0
  55. data/lib/haml/filters/tilt_base.rb +49 -0
  56. data/lib/haml/filters.rb +54 -378
  57. data/lib/haml/force_escapable.rb +29 -0
  58. data/lib/haml/helpers.rb +3 -697
  59. data/lib/haml/html.rb +22 -0
  60. data/lib/haml/identity.rb +13 -0
  61. data/lib/haml/object_ref.rb +35 -0
  62. data/lib/haml/parser.rb +157 -22
  63. data/lib/haml/rails_helpers.rb +53 -0
  64. data/lib/haml/rails_template.rb +55 -0
  65. data/lib/haml/railtie.rb +3 -46
  66. data/lib/haml/ruby_expression.rb +32 -0
  67. data/lib/haml/string_splitter.rb +140 -0
  68. data/lib/haml/template.rb +15 -34
  69. data/lib/haml/temple_line_counter.rb +2 -1
  70. data/lib/haml/util.rb +17 -15
  71. data/lib/haml/version.rb +1 -2
  72. data/lib/haml.rb +8 -20
  73. metadata +208 -54
  74. data/.gitmodules +0 -3
  75. data/TODO +0 -24
  76. data/benchmark.rb +0 -70
  77. data/bin/haml +0 -9
  78. data/lib/haml/.gitattributes +0 -1
  79. data/lib/haml/buffer.rb +0 -182
  80. data/lib/haml/exec.rb +0 -347
  81. data/lib/haml/generator.rb +0 -42
  82. data/lib/haml/helpers/action_view_extensions.rb +0 -60
  83. data/lib/haml/helpers/action_view_mods.rb +0 -132
  84. data/lib/haml/helpers/action_view_xss_mods.rb +0 -60
  85. data/lib/haml/helpers/safe_erubi_template.rb +0 -20
  86. data/lib/haml/helpers/safe_erubis_template.rb +0 -33
  87. data/lib/haml/helpers/xss_mods.rb +0 -114
  88. data/lib/haml/options.rb +0 -273
  89. data/lib/haml/plugin.rb +0 -54
  90. data/lib/haml/sass_rails_filter.rb +0 -47
  91. data/lib/haml/template/options.rb +0 -27
  92. data/lib/haml/temple_engine.rb +0 -124
  93. data/yard/default/.gitignore +0 -1
  94. data/yard/default/fulldoc/html/css/common.sass +0 -15
  95. data/yard/default/layout/html/footer.erb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec6cbb2e4023f397f1d7b6d84f06d78ab492a61e88c3f16496f39d0baeb47a83
4
- data.tar.gz: 004c2dd34697cb61a8c12854bf4b99abb3cab5195f28922b813ee299225e7663
3
+ metadata.gz: ec341f61274ad9cac37bc7df1c3ca31cfd7cfcb5d049ab9d2d2b505d7d314de9
4
+ data.tar.gz: 0a3e2dc6d6e03f586d51980e7db967b9626a1ec4563352d195e472756327b734
5
5
  SHA512:
6
- metadata.gz: a7430b4e42cf809f847448a9e04623b4b58878e44facedef5e43714820e8068f0bb853772564d5545936cdad8346f0c33abfc11642a3737d91c9a1f6242b3e41
7
- data.tar.gz: 8a91df0cb185014512ee473a21755ba41edb06e835b29740e8e46c76287a81405b2706d8a10ea148893a9429de306c67584ac1c286637c0812a5562cf149431b
6
+ metadata.gz: 529e8c001b4dae92210e8d74f3027367ad826b1f963dec92f6680378ed1b85ddd7285de0dc99e188f6557b1e439fb4157120578af68ef00292aa5a8de11e1e4f
7
+ data.tar.gz: a1871dcc07d3b0bbd45e30aaab1f0b7d043af90e276fbf163a1645ac72c7891f9d163a928857d2333f23e36955bde20aa1f1b90f373ba0d1ee6e6b285cca33f9
@@ -0,0 +1 @@
1
+ github: haml
@@ -8,15 +8,21 @@ on:
8
8
  - opened
9
9
  - synchronize
10
10
  - reopened
11
+ schedule:
12
+ - cron: "00 15 * * *"
11
13
  jobs:
12
14
  test:
13
- name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}'
14
15
  runs-on: ubuntu-latest
15
16
  strategy:
16
- fail-fast: false
17
17
  matrix:
18
- ruby: [2.6, 2.7, 3.0, jruby-9.2]
19
- rails: [5.2.x, 6.0.x, 6.1.x, rails-edge]
18
+ ruby:
19
+ - '2.5'
20
+ - '2.6'
21
+ - '2.7'
22
+ - '3.0'
23
+ - '3.1'
24
+ - jruby
25
+ - truffleruby-head
20
26
  steps:
21
27
  - uses: actions/checkout@v2
22
28
  - name: Set up Ruby
@@ -28,9 +34,7 @@ jobs:
28
34
  path: vendor/bundle
29
35
  key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
30
36
  restore-keys: ${{ runner.os }}-gems-
31
- - name: bundle install --gemfile=test/gemfiles/Gemfile.rails-${{matrix.rails}}.x
37
+ - run: sudo apt-get update && sudo apt-get install -y nodejs libxslt-dev # nodejs for execjs, libxslt for TruffleRuby nokogiri
38
+ - name: bundle install
32
39
  run: bundle config path vendor/bundle && bundle install -j$(nproc) --retry 3
33
- - name: rake test
34
- run: bundle exec rake test submodules
35
- env:
36
- RUBYOPT: "--enable-frozen-string-literal"
40
+ - run: bundle exec rake test
data/.gitignore CHANGED
@@ -1,19 +1,19 @@
1
- /.idea
1
+ /.bundle/
2
2
  /.yardoc
3
- /coverage
4
- /doc
5
- /log
6
- /pkg
7
- /test/rails
8
- /test/gemfiles/*.lock
9
- /.haml
10
- /site
11
- *.rbc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /.idea
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ /haml/
12
12
  .sass-cache
13
- .rbenv-version
14
- .rbx
15
13
  .ruby-version
16
- .rvmrc
17
- Gemfile.lock
18
- tmp
19
- .bundle/
14
+ *.bundle
15
+ *.so
16
+ *.su
17
+ *.a
18
+ *.o
19
+ *.swp
data/.yardopts CHANGED
@@ -7,10 +7,7 @@
7
7
  --title "Haml Documentation"
8
8
  --query 'object.type != :classvariable'
9
9
  --query 'object.type != :constant || @api && @api.text == "public"'
10
- --exclude lib/haml/plugin.rb
11
10
  --exclude lib/haml/railtie.rb
12
- --exclude lib/haml/helpers/action_view_mods.rb
13
- --exclude lib/haml/helpers/xss_mods.rb
14
11
  --hide-void-return
15
12
  --protected
16
13
  --no-private
data/CHANGELOG.md CHANGED
@@ -1,12 +1,83 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 6.0.7
4
+
5
+ * `Haml::Engine` and `Haml::Template` use StringBuffer instead of ArrayBuffer
6
+ * It seems more performant in many cases with recent Ruby versions.
7
+ * `Haml::RailsTemplate` is not affected.
8
+
9
+ ## 6.0.6
10
+
11
+ * Prevent CRuby from accidentally using the Ruby implementation fallback
12
+ * Reversing what v6.0.3 and v6.0.4 did, but still supporting Wasm.
13
+
14
+ ## 6.0.5
15
+
16
+ * Resurrect `#haml_object_ref` support in an object reference [#1097](https://github.com/haml/haml/issues/1097)
17
+ * This was removed in 6.0.0, and added back in this version.
18
+ * Stop warning `remove_whitespace: true` option.
19
+
20
+ ## 6.0.4
21
+
22
+ Released on October 2, 2022
23
+ ([diff](https://github.com/haml/haml/compare/v6.0.3...v6.0.4)).
24
+
25
+ * Fix a parse failure of `%` in attributes [#1096](https://github.com/haml/haml/issues/1096)
26
+ * Add another fallback from C to Ruby for Wasm.
27
+
28
+ ## 6.0.3
29
+
30
+ Released on September 28, 2022
31
+ ([diff](https://github.com/haml/haml/compare/v6.0.2...v6.0.3)).
32
+
33
+ * For Wasm, fallback to Ruby when C extension is not available.
34
+
35
+ ## 6.0.2
36
+
37
+ Released on September 28, 2022
38
+ ([diff](https://github.com/haml/haml/compare/v6.0.1...v6.0.2)).
39
+
40
+ * Unescape HTML-safe arguments for `surround`, `succeed`, and `precede` on Rails
41
+ [#1088](https://github.com/haml/haml/issues/1088)
42
+
43
+ ## 6.0.1
44
+
45
+ Released on September 23, 2022
46
+ ([diff](https://github.com/haml/haml/compare/v6.0.0...v6.0.1)).
47
+
48
+ * Unescape HTML-safe interpolation on Rails [#1084](https://github.com/haml/haml/issues/1084)
49
+ * Resurrect Haml 5's `AttributeParser.available?` for syntax\_tree-haml [#1085](https://github.com/haml/haml/issues/1085)
50
+
51
+ ## 6.0.0
52
+
53
+ Released on September 21, 2022
54
+ ([diff](https://github.com/haml/haml/compare/v5.2.2...v6.0.0)).
55
+
56
+ * Replace the implementation with Hamlit
57
+ * Haml 6 is about 1.7x faster than Haml 5 in [this benchmark](benchmark/slim/run-benchmarks.rb).
58
+ * The parser is kept as is, but everything else is replaced.
59
+ * The `haml` CLI interface was also replaced.
60
+ * The interface of `Haml::Engine` is changed. `Haml::Template` is most likely what you need now.
61
+ * Most Haml helpers are removed.
62
+ * Rails:
63
+ * Kept: `find_and_reserve`, `preserve`, `surround`, `precede`, `succeed`, `capture_haml`
64
+ * Removed: `block_is_haml?`, `flatten`, `haml_concat`, `haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`,
65
+ `html_escape`, `init_haml_helpers`, `is_haml?`, `list_of`, `non_haml`, `tab_down`, `tab_up`, `with_tabs`
66
+ * Tilt:
67
+ * Kept: `preserve`
68
+ * Removed: `block_is_haml?`, `capture_haml`, `escape_once`, `find_and_preserve`, `flatten`, `haml_concat`,
69
+ `haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`, `html_escape`, `init_haml_helpers`, `is_haml?`,
70
+ `list_of`, `non_haml`, `precede`, `succeed`, `surround`, `tab_down`, `tab_up`, `with_tabs`
71
+ * Only the attributes in [`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb)
72
+ are handled as boolean attributes.
73
+ * Some legacy Rails integration is removed.
74
+
3
75
  ## 5.2.2
76
+
4
77
  Released on July 27, 2021
5
78
  ([diff](https://github.com/haml/haml/compare/v5.2.1...v5.2.2)).
6
79
 
7
- * Support for adding Annotations to Haml output (a Rails feature 6.1+)
8
- * Expanded test matrix to include Ruby 3.0 and Rails 6.1
9
- * Only testing Ruby 2.7+ and Rails 5.2+
80
+ * Support `config.action_view.annotate_rendered_view_with_filenames = true` of Rails 6.1
10
81
 
11
82
  ## 5.2.1
12
83
 
data/Gemfile CHANGED
@@ -1,16 +1,23 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+ # Specify your gem's dependencies in haml.gemspec
2
9
  gemspec
3
10
 
4
- gem "m"
5
- gem "pry"
6
- gem "simplecov"
11
+ gem 'benchmark-ips', '2.3.0'
12
+ gem 'maxitest'
13
+ gem 'pry'
7
14
 
8
- group :docs do
9
- gem "yard"
10
- gem "kramdown"
11
- gem "sass"
12
- end
15
+ if /java/ === RUBY_PLATFORM # JRuby
16
+ gem 'pandoc-ruby'
17
+ else
18
+ gem 'redcarpet'
13
19
 
14
- platform :mri do
15
- gem "ruby-prof"
20
+ if RUBY_PLATFORM !~ /mswin|mingw/ && RUBY_ENGINE != 'truffleruby'
21
+ gem 'stackprof'
22
+ end
16
23
  end
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2019 Hampton Catlin and Natalie Weizenbaum
1
+ Copyright (c) 2006-2021 Hampton Catlin, Natalie Weizenbaum and Takashi Kokubun
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,7 +1,7 @@
1
1
  # Haml
2
2
 
3
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=main)](http://travis-ci.org/haml/haml)
4
+ [![test](https://github.com/haml/haml/actions/workflows/test.yml/badge.svg)](https://github.com/haml/haml/actions/workflows/test.yml)
5
5
  [![Code Climate](https://codeclimate.com/github/haml/haml/badges/gpa.svg)](https://codeclimate.com/github/haml/haml)
6
6
  [![Inline docs](http://inch-ci.org/github/haml/haml.png)](http://inch-ci.org/github/haml/haml)
7
7
 
@@ -10,13 +10,6 @@ more pleasant to write HTML documents, by eliminating redundancy, reflecting the
10
10
  underlying structure that the document represents, and providing an elegant syntax
11
11
  that's both powerful and easy to understand.
12
12
 
13
- ### Supported Versions
14
-
15
- * Ruby 2.6+
16
- * Rails 5.1+
17
-
18
- Other versions may likely work, but we don't test against them.
19
-
20
13
  ## Basic Usage
21
14
 
22
15
  Haml can be used from the command line or as part of a Ruby web framework. The
@@ -29,7 +22,7 @@ gem install haml
29
22
  After you write some Haml, you can run
30
23
 
31
24
  ~~~sh
32
- haml document.haml
25
+ haml render document.haml
33
26
  ~~~
34
27
 
35
28
  to compile it to HTML. For more information on these commands, check out
@@ -48,8 +41,8 @@ To use Haml with Rails, simply add Haml to your Gemfile and run `bundle`.
48
41
  gem 'haml'
49
42
  ~~~
50
43
 
51
- If you'd like to replace Rails's Erb-based generators with Haml, add
52
- [haml-rails](https://github.com/indirect/haml-rails) to your Gemfile as well.
44
+ If you'd like to replace Rails's ERB-based generators with Haml, add
45
+ [haml-rails](https://github.com/haml/haml-rails) to your Gemfile as well.
53
46
 
54
47
  ## Formatting
55
48
 
@@ -169,34 +162,35 @@ on a specific area:
169
162
  ruby -Itest test/helper_test.rb -n test_buffer_access
170
163
  ~~~
171
164
 
172
- Haml currently supports Ruby 2.7.0 and higher, so please make sure your changes run on 2.7+.
165
+ Haml currently supports Ruby 2.0.0 and higher, so please make sure your changes run on 2.0+.
173
166
 
174
167
  ## Team
175
168
 
176
169
  ### Current Maintainers
177
170
 
178
- * [Hampton Catlin](https://github.com/hcatlin)
179
- * [Takashi Kokubun](https://github.com/k0kubun)
180
171
  * [Akira Matsuda](https://github.com/amatsuda)
172
+ * [Matt Wildig](https://github.com/mattwildig)
173
+ * [Tee Parham](https://github.com/teeparham)
174
+ * [Takashi Kokubun](https://github.com/k0kubun)
181
175
 
182
176
  ### Alumni
183
177
 
184
178
  Haml was created by [Hampton Catlin](http://hamptoncatlin.com), the author of
185
- the original implementation.
179
+ the original implementation. Hampton is no longer involved in day-to-day coding,
180
+ but still consults on language issues.
186
181
 
187
- [Natalie Weizenbaum](https://github.com/nex3) was for many years the primary developer
182
+ [Natalie Weizenbaum](http://nex-3.com) was for many years the primary developer
188
183
  and architect of the "modern" Ruby implementation of Haml.
189
184
 
190
- This project's been around for many years, and we have many amazing people who kept the project
191
- alive! as former maintainers like:
192
-
193
- [Norman Clarke](http://github.com/norman)
194
- [Matt Wildig](https://github.com/mattwildig)
195
- [Tee Parham](https://github.com/teeparham)
185
+ [Norman Clarke](http://github.com/norman) was the primary maintainer of Haml from 2012 to 2016.
196
186
 
197
187
  ## License
198
188
 
199
- Copyright (c) 2006-2021 Hampton Catlin, Natalie Weizenbaum and the Haml team
189
+ Some of Natalie's work on Haml was supported by Unspace Interactive.
190
+
191
+ Beyond that, the implementation is licensed under the MIT License.
192
+
193
+ Copyright (c) 2006-2019 Hampton Catlin, Natalie Weizenbaum and the Haml team
200
194
 
201
195
  Permission is hereby granted, free of charge, to any person obtaining a copy of
202
196
  this software and associated documentation files (the "Software"), to deal in
data/REFERENCE.md CHANGED
@@ -30,7 +30,7 @@ The first step for all of these is to install the Haml gem:
30
30
 
31
31
  To run Haml from the command line, just use
32
32
 
33
- haml input.haml output.html
33
+ haml render input.haml > output.html
34
34
 
35
35
  Use `haml --help` for full documentation.
36
36
 
@@ -68,24 +68,6 @@ may be compiled to:
68
68
  </div>
69
69
  </div>
70
70
 
71
- ### Rails XSS Protection
72
-
73
- Haml supports Rails' XSS protection scheme, which was introduced in Rails 2.3.5+
74
- and is enabled by default in 3.0.0+. If it's enabled, Haml's
75
- {Haml::Options#escape_html `:escape_html`} option is set to `true` by default -
76
- like in ERB, all strings printed to a Haml template are escaped by default. Also
77
- like ERB, strings marked as HTML safe are not escaped. Haml also has [its own
78
- syntax for printing a raw string to the template](#unescaping_html).
79
-
80
- If the `:escape_html` option is set to false when XSS protection is enabled,
81
- Haml doesn't escape Ruby strings by default. However, if a string marked
82
- HTML-safe is passed to [Haml's escaping syntax](#escaping_html), it won't be
83
- escaped.
84
-
85
- Finally, all the {Haml::Helpers Haml helpers} that return strings that are known
86
- to be HTML safe are marked as such. In addition, string input is escaped unless
87
- it's HTML safe.
88
-
89
71
  ### Ruby Module
90
72
 
91
73
  Haml can also be used completely separately from Rails and ActionView. To do
@@ -93,10 +75,10 @@ this, install the gem with RubyGems:
93
75
 
94
76
  gem install haml
95
77
 
96
- You can then use it by including the "haml" gem in Ruby code, and using
97
- {Haml::Engine} like so:
78
+ You can then use it by including the `haml` gem in Ruby code, and using
79
+ {Haml::Template} like so:
98
80
 
99
- engine = Haml::Engine.new("%p Haml code!")
81
+ engine = Haml::Template.new { "%p Haml code!" }
100
82
  engine.render #=> "<p>Haml code!</p>\n"
101
83
 
102
84
  ### Options
@@ -104,50 +86,26 @@ You can then use it by including the "haml" gem in Ruby code, and using
104
86
  Haml understands various configuration options that affect its performance and
105
87
  output.
106
88
 
107
- In Rails, options can be set by setting the {Haml::Template#options Haml::Template.options}
108
- hash in an initializer:
89
+ In Rails, options can be set by using `Haml::RailsTemplate.set_options` in an initializer:
109
90
 
110
91
  ```ruby
111
92
  # config/initializers/haml.rb
112
- Haml::Template.options[:format] = :html5
113
-
114
- # Avoid escaping attributes which are already escaped
115
- Haml::Template.options[:escape_attrs] = :once
93
+ Haml::RailsTemplate.set_options(escape_html: false)
116
94
  ```
117
95
 
118
- Outside Rails, you can set them by configuring them globally in
119
- Haml::Options.defaults:
96
+ Outside Rails, you can set them by configuring them globally in `Haml::Template.options`:
120
97
 
121
98
  ```ruby
122
- Haml::Options.defaults[:format] = :html5
99
+ Haml::Template.options[:escape_html] = false
123
100
  ```
124
101
 
125
102
  In sinatra specifically, you can set them in global config with:
126
103
  ```ruby
127
- set :haml, { escape_html: true }
104
+ set :haml, { escape_html: false }
128
105
  ```
129
106
 
130
- Finally, you can also set them by passing an options hash to
131
- {Haml::Engine#initialize}. For the complete list of available options, please
132
- see {Haml::Options}.
133
-
134
- ### Encodings
135
-
136
- Haml supports the same sorts of
137
- encoding-declaration comments that Ruby does. Although both Ruby and Haml
138
- support several different styles, the easiest it just to add `-# coding:
139
- encoding-name` at the beginning of the Haml template (it must come before all
140
- other lines). This will tell Haml that the template is encoded using the named
141
- encoding.
142
-
143
- By default, the HTML generated by Haml has the same encoding as the Haml
144
- template. However, if `Encoding.default_internal` is set, Haml will attempt to
145
- use that instead. In addition, the {Haml::Options#encoding `:encoding` option}
146
- can be used to specify an output encoding manually.
147
-
148
- Note that, like Ruby, Haml does not support templates encoded in UTF-16 or
149
- UTF-32, since these encodings are not compatible with ASCII. It is possible to
150
- use these as the output encoding, though.
107
+ Finally, you can also set them by passing an options hash to `Haml::Engine.new` or `Haml::Template.new`.
108
+ For the complete list of available options, please see `Haml::Engine`.
151
109
 
152
110
  ## Plain Text
153
111
 
@@ -325,49 +283,6 @@ Haml also supports Ruby's new hash syntax:
325
283
 
326
284
  %a{title: @title, href: href} Stuff
327
285
 
328
- #### Attribute Methods
329
-
330
- A Ruby method call that returns a hash can be substituted for the hash contents.
331
- For example, {Haml::Helpers} defines the following method:
332
-
333
- def html_attrs(lang = 'en-US')
334
- {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
335
- end
336
-
337
- This can then be used in Haml, like so:
338
-
339
- %html{html_attrs('fr-fr')}
340
-
341
- This is compiled to:
342
-
343
- <html lang='fr-fr' xml:lang='fr-fr' xmlns='http://www.w3.org/1999/xhtml'>
344
- </html>
345
-
346
- You can use as many such attribute methods as you want by separating them with
347
- commas, like a Ruby argument list. All the hashes will be merged together, from
348
- left to right. For example, if you defined
349
-
350
- def hash1
351
- {:bread => 'white', :filling => 'peanut butter and jelly'}
352
- end
353
-
354
- def hash2
355
- {:bread => 'whole wheat'}
356
- end
357
-
358
- then
359
-
360
- %sandwich{hash1, hash2, :delicious => 'true'}/
361
-
362
- would compile to:
363
-
364
- <sandwich bread='whole wheat' delicious='true' filling='peanut butter and jelly' />
365
-
366
- Note that the Haml attributes list has the same syntax as a Ruby method call.
367
- This means that any attribute methods must come before the hash literal.
368
-
369
- Attribute methods aren't supported for HTML-style attributes.
370
-
371
286
  #### Boolean Attributes
372
287
 
373
288
  Some attributes, such as "checked" for `input` tags or "selected" for `option`
@@ -404,6 +319,21 @@ or using `true` and `false`:
404
319
 
405
320
  %input(selected=true)
406
321
 
322
+ This feature works only for attributes that are included in
323
+ [`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb),
324
+ as well as `data-` and `aria-` attributes.
325
+
326
+ %input{'data-hidden' => false}
327
+ %input{'aria-hidden' => false}
328
+ %input{'xyz-hidden' => false}
329
+
330
+ will render as:
331
+
332
+ <input>
333
+ <input>
334
+ <input xyz-hidden='false'>
335
+
336
+
407
337
  <!-- The title to the next section (Prefixed Attributes) has changed. This
408
338
  <a> tag is so old links to here still work. -->
409
339
  <a id="html5_custom_data_attributes" style="border:0;"></a>
@@ -993,7 +923,7 @@ is compiled to:
993
923
 
994
924
  ### Whitespace Preservation: `~` {#tilde}
995
925
 
996
- `~` works just like `=`, except that it runs {Haml::Helpers#find\_and\_preserve}
926
+ `~` works just like `=`, except that it runs {Haml::Helpers.preserve}
997
927
  on its input. For example,
998
928
 
999
929
  ~ "Foo\n<pre>Bar\nBaz</pre>"
@@ -1154,9 +1084,6 @@ is compiled to
1154
1084
  <p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
1155
1085
  </div>
1156
1086
 
1157
- Note that `#{}` interpolation within filters is HTML-escaped if you specify true to
1158
- {Haml::Options#escape_filter_interpolations `:escape_filter_interpolations`} option.
1159
-
1160
1087
  The functionality of some filters such as Markdown can be provided by many
1161
1088
  different libraries. Usually you don't have to worry about this - you can just
1162
1089
  load the gem of your choice and Haml will automatically use it.
@@ -1271,43 +1198,48 @@ default. This filter is implemented using Tilt.
1271
1198
 
1272
1199
  ### Custom Filters
1273
1200
 
1274
- You can also define your own filters. See {Haml::Filters} for details.
1275
-
1276
- ## Helper Methods {#helper-methods}
1277
-
1278
- Sometimes you need to manipulate whitespace in a more precise fashion than what
1279
- the whitespace removal methods allow. There are a few helper methods that are
1280
- useful when dealing with inline content. All these methods take a Haml block to
1281
- modify.
1201
+ You can also define your own filters.
1202
+ `Haml::Filters::YourCustomFilter#compile` should return
1203
+ [a Temple expression](https://github.com/judofyr/temple/blob/master/EXPRESSIONS.md).
1282
1204
 
1283
- ### surround {#surround}
1205
+ The simplest example of a filter might be something like:
1284
1206
 
1285
- Surrounds a Haml block with text. Expects 1 or 2 string arguments used to
1286
- surround the Haml block. If a second argument is not provided, the first
1287
- argument is used as the second.
1288
-
1289
- = surround "(", ")" do
1290
- = link_to "learn more", "#"
1291
-
1292
- ### precede {#precede}
1207
+ ```ruby
1208
+ class HelloFilter < Haml::Filters::Base
1209
+ def compile(_node)
1210
+ [:static, "hello world"]
1211
+ end
1212
+ end
1293
1213
 
1294
- Prepends a Haml block with text. Expects 1 argument.
1214
+ Haml::Filters.registered[:hello] ||= HelloFilter
1215
+ ```
1295
1216
 
1296
- = precede "*" do
1297
- %span Required
1217
+ A more complex complex example
1298
1218
 
1299
- ### succeed {#succeed}
1219
+ ```ruby
1220
+ class BetterFilter < Haml::Filters::Base
1221
+ def compile(node)
1222
+ temple = [:multi]
1223
+ temple << [:static, "hello "]
1224
+ temple << compile_text(node.value[:text])
1225
+ temple << [:static, " world"]
1226
+ temple
1227
+ end
1228
+
1229
+ private
1230
+ def compile_text(text)
1231
+ if ::Haml::Util.contains_interpolation?(text)
1232
+ [:dynamic, ::Haml::Util.unescape_interpolation(text)]
1233
+ else
1234
+ [:static, text]
1235
+ end
1236
+ end
1237
+ end
1300
1238
 
1301
- Appends a Haml block with text. Expects 1 argument.
1239
+ Haml::Filters.registered[:better] ||= BetterFilter
1240
+ ```
1302
1241
 
1303
- Begin by
1304
- = succeed "," do
1305
- = link_to "filling out your profile", "#"
1306
- = succeed "," do
1307
- = link_to "adding a bio", "#"
1308
- and
1309
- = succeed "." do
1310
- = link_to "inviting friends", "#"
1242
+ See {Haml::Filters} for examples.
1311
1243
 
1312
1244
  ## Multiline: `|` {#multiline}
1313
1245
 
@@ -1367,14 +1299,7 @@ Haml won't try to re-format the indentation.
1367
1299
  Literal `textarea` and `pre` tags automatically preserve content given through
1368
1300
  `=`. Dynamically-generated `textarea`s and `pre`s can't be preserved
1369
1301
  automatically, and so should be passed through
1370
- {Haml::Helpers#find\_and\_preserve} or the [`~` command](#tilde), which has the
1302
+ {Haml::Helpers.preserve} or the [`~` command](#tilde), which has the
1371
1303
  same effect.
1372
1304
 
1373
1305
  Blocks of literal text can be preserved using the [`:preserve` filter](#preserve-filter).
1374
-
1375
- ## Helpers
1376
-
1377
- Haml offers a bunch of helpers that are useful for doing stuff like preserving
1378
- whitespace, creating nicely indented output for user-defined helpers, and other
1379
- useful things. The helpers are all documented in the {Haml::Helpers} and
1380
- {Haml::Helpers::ActionViewExtensions} modules.