haml 5.2.2 → 6.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/test.yml +13 -9
- data/.gitignore +16 -16
- data/.yardopts +0 -3
- data/CHANGELOG.md +63 -3
- data/Gemfile +18 -11
- data/MIT-LICENSE +1 -1
- data/README.md +17 -23
- data/REFERENCE.md +32 -145
- data/Rakefile +48 -81
- data/bin/bench +66 -0
- data/bin/console +11 -0
- data/bin/ruby +3 -0
- data/bin/setup +7 -0
- data/bin/stackprof +27 -0
- data/bin/test +24 -0
- data/exe/haml +6 -0
- data/ext/haml/extconf.rb +10 -0
- data/ext/haml/haml.c +537 -0
- data/ext/haml/hescape.c +108 -0
- data/ext/haml/hescape.h +20 -0
- data/haml.gemspec +39 -37
- data/lib/haml/ambles.rb +20 -0
- data/lib/haml/attribute_builder.rb +134 -179
- data/lib/haml/attribute_compiler.rb +85 -194
- data/lib/haml/attribute_parser.rb +92 -126
- data/lib/haml/cli.rb +154 -0
- data/lib/haml/compiler/children_compiler.rb +126 -0
- data/lib/haml/compiler/comment_compiler.rb +39 -0
- data/lib/haml/compiler/doctype_compiler.rb +46 -0
- data/lib/haml/compiler/script_compiler.rb +116 -0
- data/lib/haml/compiler/silent_script_compiler.rb +24 -0
- data/lib/haml/compiler/tag_compiler.rb +76 -0
- data/lib/haml/compiler.rb +63 -296
- data/lib/haml/dynamic_merger.rb +67 -0
- data/lib/haml/engine.rb +44 -227
- data/lib/haml/error.rb +5 -4
- data/lib/haml/escapable.rb +6 -70
- data/lib/haml/filters/base.rb +12 -0
- data/lib/haml/filters/cdata.rb +20 -0
- data/lib/haml/filters/coffee.rb +17 -0
- data/lib/haml/filters/css.rb +33 -0
- data/lib/haml/filters/erb.rb +10 -0
- data/lib/haml/filters/escaped.rb +22 -0
- data/lib/haml/filters/javascript.rb +33 -0
- data/lib/haml/filters/less.rb +20 -0
- data/lib/haml/filters/markdown.rb +11 -0
- data/lib/haml/filters/plain.rb +29 -0
- data/lib/haml/filters/preserve.rb +22 -0
- data/lib/haml/filters/ruby.rb +10 -0
- data/lib/haml/filters/sass.rb +15 -0
- data/lib/haml/filters/scss.rb +15 -0
- data/lib/haml/filters/text_base.rb +25 -0
- data/lib/haml/filters/tilt_base.rb +49 -0
- data/lib/haml/filters.rb +54 -378
- data/lib/haml/force_escapable.rb +29 -0
- data/lib/haml/helpers.rb +3 -697
- data/lib/haml/html.rb +22 -0
- data/lib/haml/identity.rb +13 -0
- data/lib/haml/object_ref.rb +35 -0
- data/lib/haml/parser.rb +157 -22
- data/lib/haml/rails_helpers.rb +53 -0
- data/lib/haml/rails_template.rb +55 -0
- data/lib/haml/railtie.rb +3 -46
- data/lib/haml/ruby_expression.rb +32 -0
- data/lib/haml/string_splitter.rb +140 -0
- data/lib/haml/template.rb +15 -34
- data/lib/haml/temple_line_counter.rb +2 -1
- data/lib/haml/util.rb +17 -15
- data/lib/haml/version.rb +1 -2
- data/lib/haml.rb +8 -20
- metadata +208 -54
- data/.gitmodules +0 -3
- data/TODO +0 -24
- data/benchmark.rb +0 -70
- data/bin/haml +0 -9
- data/lib/haml/.gitattributes +0 -1
- data/lib/haml/buffer.rb +0 -182
- data/lib/haml/exec.rb +0 -347
- data/lib/haml/generator.rb +0 -42
- data/lib/haml/helpers/action_view_extensions.rb +0 -60
- data/lib/haml/helpers/action_view_mods.rb +0 -132
- data/lib/haml/helpers/action_view_xss_mods.rb +0 -60
- data/lib/haml/helpers/safe_erubi_template.rb +0 -20
- data/lib/haml/helpers/safe_erubis_template.rb +0 -33
- data/lib/haml/helpers/xss_mods.rb +0 -114
- data/lib/haml/options.rb +0 -273
- data/lib/haml/plugin.rb +0 -54
- data/lib/haml/sass_rails_filter.rb +0 -47
- data/lib/haml/template/options.rb +0 -27
- data/lib/haml/temple_engine.rb +0 -124
- data/yard/default/.gitignore +0 -1
- data/yard/default/fulldoc/html/css/common.sass +0 -15
- data/yard/default/layout/html/footer.erb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9efb6d42c07f38f08e6406c470be766f751439a63c0b151aca4040d5ea583d8
|
4
|
+
data.tar.gz: 8bcc4b22a87eb105e380990aa1fcfee19c9cf1ae61467e9bb9c3130f81977279
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07ebd7d512eac2b19e8d8d2d2611064a4742ead90ad9e6570e7612dd45535797d4479aa169371105a37f9f9ba32e6066337ef4a772b7430c7d2ac3a519d34ebb
|
7
|
+
data.tar.gz: 2fae2a68a205536580450fdd0c1ee1ab2c7f14268a01cc65b225f2115a1b3ee529865c2c184fc9b18e7a2141f6cb08d7a2254f14e0a7d5f61bde477387a114f9
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: haml
|
data/.github/workflows/test.yml
CHANGED
@@ -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:
|
19
|
-
|
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
|
-
-
|
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
|
-
-
|
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
|
-
/.
|
1
|
+
/.bundle/
|
2
2
|
/.yardoc
|
3
|
-
/
|
4
|
-
/
|
5
|
-
|
6
|
-
/
|
7
|
-
/
|
8
|
-
/
|
9
|
-
|
10
|
-
/
|
11
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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,72 @@
|
|
1
1
|
# Haml Changelog
|
2
2
|
|
3
|
+
## 6.0.5
|
4
|
+
|
5
|
+
* Resurrect `#haml_object_ref` support in an object reference [#1097](https://github.com/haml/haml/issues/1097)
|
6
|
+
* This was removed in 6.0.0, and added back in this version.
|
7
|
+
* Stop warning `remove_whitespace: true` option.
|
8
|
+
|
9
|
+
## 6.0.4
|
10
|
+
|
11
|
+
Released on October 2, 2022
|
12
|
+
([diff](https://github.com/haml/haml/compare/v6.0.3...v6.0.4)).
|
13
|
+
|
14
|
+
* Fix a parse failure of `%` in attributes [#1096](https://github.com/haml/haml/issues/1096)
|
15
|
+
* Add another fallback from C to Ruby for Wasm.
|
16
|
+
|
17
|
+
## 6.0.3
|
18
|
+
|
19
|
+
Released on September 28, 2022
|
20
|
+
([diff](https://github.com/haml/haml/compare/v6.0.2...v6.0.3)).
|
21
|
+
|
22
|
+
* For Wasm, fallback to Ruby when C extension is not available.
|
23
|
+
|
24
|
+
## 6.0.2
|
25
|
+
|
26
|
+
Released on September 28, 2022
|
27
|
+
([diff](https://github.com/haml/haml/compare/v6.0.1...v6.0.2)).
|
28
|
+
|
29
|
+
* Unescape HTML-safe arguments for `surround`, `succeed`, and `precede` on Rails
|
30
|
+
[#1088](https://github.com/haml/haml/issues/1088)
|
31
|
+
|
32
|
+
## 6.0.1
|
33
|
+
|
34
|
+
Released on September 23, 2022
|
35
|
+
([diff](https://github.com/haml/haml/compare/v6.0.0...v6.0.1)).
|
36
|
+
|
37
|
+
* Unescape HTML-safe interpolation on Rails [#1084](https://github.com/haml/haml/issues/1084)
|
38
|
+
* Resurrect Haml 5's `AttributeParser.available?` for syntax\_tree-haml [#1085](https://github.com/haml/haml/issues/1085)
|
39
|
+
|
40
|
+
## 6.0.0
|
41
|
+
|
42
|
+
Released on September 21, 2022
|
43
|
+
([diff](https://github.com/haml/haml/compare/v5.2.2...v6.0.0)).
|
44
|
+
|
45
|
+
* Replace the implementation with Hamlit
|
46
|
+
* Haml 6 is about 1.7x faster than Haml 5 in [this benchmark](benchmark/slim/run-benchmarks.rb).
|
47
|
+
* The parser is kept as is, but everything else is replaced.
|
48
|
+
* The `haml` CLI interface was also replaced.
|
49
|
+
* The interface of `Haml::Engine` is changed. `Haml::Template` is most likely what you need now.
|
50
|
+
* Most Haml helpers are removed.
|
51
|
+
* Rails:
|
52
|
+
* Kept: `find_and_reserve`, `preserve`, `surround`, `precede`, `succeed`, `capture_haml`
|
53
|
+
* Removed: `block_is_haml?`, `flatten`, `haml_concat`, `haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`,
|
54
|
+
`html_escape`, `init_haml_helpers`, `is_haml?`, `list_of`, `non_haml`, `tab_down`, `tab_up`, `with_tabs`
|
55
|
+
* Tilt:
|
56
|
+
* Kept: `preserve`
|
57
|
+
* Removed: `block_is_haml?`, `capture_haml`, `escape_once`, `find_and_preserve`, `flatten`, `haml_concat`,
|
58
|
+
`haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`, `html_escape`, `init_haml_helpers`, `is_haml?`,
|
59
|
+
`list_of`, `non_haml`, `precede`, `succeed`, `surround`, `tab_down`, `tab_up`, `with_tabs`
|
60
|
+
* Only the attributes in [`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb)
|
61
|
+
are handled as boolean attributes.
|
62
|
+
* Some legacy Rails integration is removed.
|
63
|
+
|
3
64
|
## 5.2.2
|
65
|
+
|
4
66
|
Released on July 27, 2021
|
5
67
|
([diff](https://github.com/haml/haml/compare/v5.2.1...v5.2.2)).
|
6
68
|
|
7
|
-
* Support
|
8
|
-
* Expanded test matrix to include Ruby 3.0 and Rails 6.1
|
9
|
-
* Only testing Ruby 2.7+ and Rails 5.2+
|
69
|
+
* Support `config.action_view.annotate_rendered_view_with_filenames = true` of Rails 6.1
|
10
70
|
|
11
71
|
## 5.2.1
|
12
72
|
|
data/Gemfile
CHANGED
@@ -1,16 +1,23 @@
|
|
1
|
-
source
|
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
|
5
|
-
gem
|
6
|
-
gem
|
11
|
+
gem 'benchmark-ips', '2.3.0'
|
12
|
+
gem 'maxitest'
|
13
|
+
gem 'pry'
|
7
14
|
|
8
|
-
|
9
|
-
gem
|
10
|
-
|
11
|
-
gem
|
12
|
-
end
|
15
|
+
if /java/ === RUBY_PLATFORM # JRuby
|
16
|
+
gem 'pandoc-ruby'
|
17
|
+
else
|
18
|
+
gem 'redcarpet'
|
13
19
|
|
14
|
-
|
15
|
-
|
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-
|
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
|
-
[![
|
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
|
52
|
-
[haml-rails](https://github.com/
|
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.
|
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](
|
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
|
-
|
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
|
-
|
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
|
97
|
-
{Haml::
|
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::
|
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
|
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::
|
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::
|
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:
|
104
|
+
set :haml, { escape_html: false }
|
128
105
|
```
|
129
106
|
|
130
|
-
Finally, you can also set them by passing an options hash to
|
131
|
-
|
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
|
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,10 @@ default. This filter is implemented using Tilt.
|
|
1271
1198
|
|
1272
1199
|
### Custom Filters
|
1273
1200
|
|
1274
|
-
You can also define your own filters.
|
1275
|
-
|
1276
|
-
|
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.
|
1282
|
-
|
1283
|
-
### surround {#surround}
|
1284
|
-
|
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}
|
1293
|
-
|
1294
|
-
Prepends a Haml block with text. Expects 1 argument.
|
1295
|
-
|
1296
|
-
= precede "*" do
|
1297
|
-
%span Required
|
1298
|
-
|
1299
|
-
### succeed {#succeed}
|
1300
|
-
|
1301
|
-
Appends a Haml block with text. Expects 1 argument.
|
1302
|
-
|
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", "#"
|
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).
|
1204
|
+
See {Haml::Filters} for examples.
|
1311
1205
|
|
1312
1206
|
## Multiline: `|` {#multiline}
|
1313
1207
|
|
@@ -1367,14 +1261,7 @@ Haml won't try to re-format the indentation.
|
|
1367
1261
|
Literal `textarea` and `pre` tags automatically preserve content given through
|
1368
1262
|
`=`. Dynamically-generated `textarea`s and `pre`s can't be preserved
|
1369
1263
|
automatically, and so should be passed through
|
1370
|
-
{Haml::Helpers
|
1264
|
+
{Haml::Helpers.preserve} or the [`~` command](#tilde), which has the
|
1371
1265
|
same effect.
|
1372
1266
|
|
1373
1267
|
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.
|