haml 5.0.4 → 6.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 (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/test.yml +40 -0
  4. data/.gitignore +16 -15
  5. data/CHANGELOG.md +62 -1
  6. data/Gemfile +18 -14
  7. data/MIT-LICENSE +2 -2
  8. data/README.md +4 -5
  9. data/REFERENCE.md +46 -12
  10. data/Rakefile +93 -103
  11. data/bin/bench +66 -0
  12. data/bin/console +11 -0
  13. data/bin/ruby +3 -0
  14. data/bin/setup +7 -0
  15. data/bin/stackprof +27 -0
  16. data/bin/test +24 -0
  17. data/exe/haml +6 -0
  18. data/ext/haml/extconf.rb +10 -0
  19. data/ext/haml/haml.c +537 -0
  20. data/ext/haml/hescape.c +108 -0
  21. data/ext/haml/hescape.h +20 -0
  22. data/haml.gemspec +39 -30
  23. data/lib/haml/ambles.rb +20 -0
  24. data/lib/haml/attribute_builder.rb +140 -128
  25. data/lib/haml/attribute_compiler.rb +86 -181
  26. data/lib/haml/attribute_parser.rb +86 -124
  27. data/lib/haml/cli.rb +154 -0
  28. data/lib/haml/compiler/children_compiler.rb +126 -0
  29. data/lib/haml/compiler/comment_compiler.rb +39 -0
  30. data/lib/haml/compiler/doctype_compiler.rb +46 -0
  31. data/lib/haml/compiler/script_compiler.rb +116 -0
  32. data/lib/haml/compiler/silent_script_compiler.rb +24 -0
  33. data/lib/haml/compiler/tag_compiler.rb +76 -0
  34. data/lib/haml/compiler.rb +64 -298
  35. data/lib/haml/dynamic_merger.rb +67 -0
  36. data/lib/haml/engine.rb +43 -219
  37. data/lib/haml/error.rb +29 -27
  38. data/lib/haml/escapable.rb +6 -42
  39. data/lib/haml/filters/base.rb +12 -0
  40. data/lib/haml/filters/cdata.rb +20 -0
  41. data/lib/haml/filters/coffee.rb +17 -0
  42. data/lib/haml/filters/css.rb +33 -0
  43. data/lib/haml/filters/erb.rb +10 -0
  44. data/lib/haml/filters/escaped.rb +22 -0
  45. data/lib/haml/filters/javascript.rb +33 -0
  46. data/lib/haml/filters/less.rb +20 -0
  47. data/lib/haml/filters/markdown.rb +11 -0
  48. data/lib/haml/filters/plain.rb +29 -0
  49. data/lib/haml/filters/preserve.rb +22 -0
  50. data/lib/haml/filters/ruby.rb +10 -0
  51. data/lib/haml/filters/sass.rb +15 -0
  52. data/lib/haml/filters/scss.rb +15 -0
  53. data/lib/haml/filters/text_base.rb +25 -0
  54. data/lib/haml/filters/tilt_base.rb +49 -0
  55. data/lib/haml/filters.rb +55 -378
  56. data/lib/haml/force_escapable.rb +29 -0
  57. data/lib/haml/helpers.rb +4 -696
  58. data/lib/haml/html.rb +22 -0
  59. data/lib/haml/identity.rb +13 -0
  60. data/lib/haml/object_ref.rb +30 -0
  61. data/lib/haml/parser.rb +208 -43
  62. data/lib/haml/rails_helpers.rb +51 -0
  63. data/lib/haml/rails_template.rb +55 -0
  64. data/lib/haml/railtie.rb +7 -40
  65. data/lib/haml/ruby_expression.rb +32 -0
  66. data/lib/haml/string_splitter.rb +20 -0
  67. data/lib/haml/template.rb +15 -33
  68. data/lib/haml/temple_line_counter.rb +2 -0
  69. data/lib/haml/util.rb +23 -21
  70. data/lib/haml/version.rb +1 -1
  71. data/lib/haml.rb +8 -19
  72. metadata +222 -50
  73. data/.gitmodules +0 -3
  74. data/.travis.yml +0 -54
  75. data/.yardopts +0 -23
  76. data/TODO +0 -24
  77. data/benchmark.rb +0 -66
  78. data/bin/haml +0 -9
  79. data/lib/haml/.gitattributes +0 -1
  80. data/lib/haml/buffer.rb +0 -235
  81. data/lib/haml/exec.rb +0 -348
  82. data/lib/haml/generator.rb +0 -41
  83. data/lib/haml/helpers/action_view_extensions.rb +0 -59
  84. data/lib/haml/helpers/action_view_mods.rb +0 -129
  85. data/lib/haml/helpers/action_view_xss_mods.rb +0 -59
  86. data/lib/haml/helpers/safe_erubi_template.rb +0 -19
  87. data/lib/haml/helpers/safe_erubis_template.rb +0 -32
  88. data/lib/haml/helpers/xss_mods.rb +0 -110
  89. data/lib/haml/options.rb +0 -273
  90. data/lib/haml/plugin.rb +0 -34
  91. data/lib/haml/sass_rails_filter.rb +0 -46
  92. data/lib/haml/template/options.rb +0 -26
  93. data/lib/haml/temple_engine.rb +0 -121
  94. data/yard/default/.gitignore +0 -1
  95. data/yard/default/fulldoc/html/css/common.sass +0 -15
  96. data/yard/default/layout/html/footer.erb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2164872cd8f38c57307ec65c2834988d49538cec038795797be328bd18e3e1c4
4
- data.tar.gz: 6f090e38ab9856973b42a8f61bc34fe10fa7df3595dfc3939c0ead7c422d66d1
3
+ metadata.gz: 0b9bc0a9bea79d404adbf4b0eb540dd256a53c4c99a71f88a2bd25b1b313685a
4
+ data.tar.gz: 7d76a5280aa58671b319d08776d1c93785e3ea71f9664fc40a2602f229c3a55a
5
5
  SHA512:
6
- metadata.gz: 510cbbc03d5d46c0430d7a866166fc089dd253a98584d540d9a46cd2610bb5fc327d39e830c05a939266b330c1048ce9e47a269b39b2c7d35cb0a4ed5d370be0
7
- data.tar.gz: 3292001c396a698256d7292309e631c6d81bb02f26a4fc1b4763ad537dd97a808aa9abd27b3841091afe9a120dfb5dc868c6dfb8c96cbd6538383e92f2871a91
6
+ metadata.gz: 5d44ef26e2b98dfab93bc7e825dc6f10bc5d86c35cb094fd634b127c7da86c4512ee839cd4f0944b0c4abeac577e94d5bd032aca650a1b70d9b7c97bfeca0a34
7
+ data.tar.gz: 5c0c3c3689ddca67701c439d96990126663cd52b97107a3ca2fc3da38bfba5614cecbacf8049a0bc751e096370bfa4733c1cd24eb9034c21082c2215617f6b29
@@ -0,0 +1 @@
1
+ github: haml
@@ -0,0 +1,40 @@
1
+ name: test
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ pull_request:
7
+ types:
8
+ - opened
9
+ - synchronize
10
+ - reopened
11
+ schedule:
12
+ - cron: "00 15 * * *"
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ ruby:
19
+ - '2.5'
20
+ - '2.6'
21
+ - '2.7'
22
+ - '3.0'
23
+ - '3.1'
24
+ - jruby
25
+ - truffleruby-head
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+ - name: Set up Ruby
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby }}
32
+ - uses: actions/cache@v2
33
+ with:
34
+ path: vendor/bundle
35
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
36
+ restore-keys: ${{ runner.os }}-gems-
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
39
+ run: bundle config path vendor/bundle && bundle install -j$(nproc) --retry 3
40
+ - run: bundle exec rake test
data/.gitignore CHANGED
@@ -1,18 +1,19 @@
1
+ /.bundle/
1
2
  /.yardoc
2
- /coverage
3
- /doc
4
- /log
5
- /pkg
6
- /test/rails
7
- /test/gemfiles/*.lock
8
- /.haml
9
- /site
10
- *.rbc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /.idea
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ /haml/
11
12
  .sass-cache
12
- .rbenv-version
13
- .rbx
14
13
  .ruby-version
15
- .rvmrc
16
- Gemfile.lock
17
- tmp
18
- .bundle/
14
+ *.bundle
15
+ *.so
16
+ *.su
17
+ *.a
18
+ *.o
19
+ *.swp
data/CHANGELOG.md CHANGED
@@ -1,5 +1,67 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 6.0.0
4
+
5
+ Released on September 21, 2022
6
+ ([diff](https://github.com/haml/haml/compare/v5.2.2...v6.0.0)).
7
+
8
+ * Replace the implementation with Hamlit
9
+ * Haml 6 is about 1.7x faster than Haml 5 in [this benchmark](benchmark/slim/run-benchmarks.rb).
10
+ * The parser is kept as is, but everything else is replaced.
11
+ * The `haml` CLI interface was also replaced.
12
+ * All Haml helpers except for `preserve` are removed.
13
+ * Some legacy Rails integration is removed.
14
+
15
+ ## 5.2.2
16
+
17
+ Released on July 27, 2021
18
+ ([diff](https://github.com/haml/haml/compare/v5.2.1...v5.2.2)).
19
+
20
+ * Support `config.action_view.annotate_rendered_view_with_filenames = true` of Rails 6.1
21
+
22
+ ## 5.2.1
23
+
24
+ Released on November 30, 2020
25
+ ([diff](https://github.com/haml/haml/compare/v5.2.0...v5.2.1)).
26
+
27
+ * Add in improved "multiline" support for attributes [#1043](https://github.com/haml/haml/issues/1043)
28
+
29
+ ## 5.2
30
+
31
+ Released on September 28, 2020
32
+ ([diff](https://github.com/haml/haml/compare/v5.1.2...v5.2.0)).
33
+
34
+ * Fix crash in the attribute optimizer when `#inspect` is overridden in TrueClass / FalseClass [#972](https://github.com/haml/haml/issues/972)
35
+ * Do not HTML-escape templates that are declared to be plaintext [#1014](https://github.com/haml/haml/issues/1014) (Thanks [@cesarizu](https://github.com/cesarizu))
36
+ * Class names are no longer ordered alphabetically, and now follow a new specification as laid out in REFERENCE [#306](https://github.com/haml/haml/issues/306)
37
+
38
+ ## 5.1.2
39
+
40
+ Released on August 6, 2019
41
+ ([diff](https://github.com/haml/haml/compare/v5.1.1...v5.1.2)).
42
+
43
+ * Fix crash in some environments such as New Relic by unfreezing string literals for ParseNode#inspect. [#1016](https://github.com/haml/haml/pull/1016) (thanks [Jalyna](https://github.com/jalyna))
44
+
45
+ ## 5.1.1
46
+
47
+ Released on May 25, 2019
48
+ ([diff](https://github.com/haml/haml/compare/v5.1.0...v5.1.1)).
49
+
50
+ * Fix NameError bug that happens on ruby 2.6.1-2.6.3 + haml 5.1.0 + rails < 5.1 + erubi. (Akira Matsuda)
51
+
52
+ ## 5.1.0
53
+
54
+ Released on May 16, 2019
55
+ ([diff](https://github.com/haml/haml/compare/v5.0.4...v5.1.0)).
56
+
57
+ * Rails 6 support [#1008](https://github.com/haml/haml/pull/1008) (thanks [Seb Jacobs](https://github.com/sebjacobs))
58
+ * Add `escape_filter_interpolations` option for backwards compatibility with haml 4 defaults [#984](https://github.com/haml/haml/pull/984) (thanks [Will Jordan](https://github.com/wjordan))
59
+ * Fix error on empty :javascript and :css filter blocks [#986](https://github.com/haml/haml/pull/986) (thanks [Will Jordan](https://github.com/wjordan))
60
+ * Respect changes in Haml::Options.defaults in `Haml::TempleEngine` options (Takashi Kokubun)
61
+ * Un-freeze TempleEngine precompiled string literals [#983](https://github.com/haml/haml/pull/983) (thanks [Will Jordan](https://github.com/wjordan))
62
+ * Various performance/memory improvements [#965](https://github.com/haml/haml/pull/965), [#966](https://github.com/haml/haml/pull/966), [#963](https://github.com/haml/haml/pull/963) (thanks [Dillon Welch](https://github.com/oniofchaos))
63
+ * Enable `frozen_string_literal` magic comment for all .rb files [#967](https://github.com/haml/haml/pull/967) (thanks [Dillon Welch](https://github.com/oniofchaos))
64
+
3
65
  ## 5.0.4
4
66
 
5
67
  Released on October 13, 2017
@@ -1452,4 +1514,3 @@ has been moved to [YARD](http://yard.soen.ca).
1452
1514
  YARD is an excellent documentation system,
1453
1515
  and allows us to write our documentation in [Maruku](http://maruku.rubyforge.org),
1454
1516
  which is also excellent.
1455
- >>>>>>> External Changes
data/Gemfile CHANGED
@@ -1,19 +1,23 @@
1
- source "https://rubygems.org"
2
- gemspec
3
-
4
- gem "m"
5
- gem "pry"
1
+ source 'https://rubygems.org'
6
2
 
7
- group :docs do
8
- gem "yard", "~> 0.8.0"
9
- gem "kramdown"
10
- gem "sass"
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"
11
6
  end
12
7
 
13
- platform :mri do
14
- gem "ruby-prof"
15
- end
8
+ # Specify your gem's dependencies in haml.gemspec
9
+ gemspec
10
+
11
+ gem 'benchmark-ips', '2.3.0'
12
+ gem 'maxitest'
13
+ gem 'pry'
14
+
15
+ if /java/ === RUBY_PLATFORM # JRuby
16
+ gem 'pandoc-ruby'
17
+ else
18
+ gem 'redcarpet'
16
19
 
17
- platform :mri_21 do
18
- gem "simplecov"
20
+ if RUBY_PLATFORM !~ /mswin|mingw/ && RUBY_ENGINE != 'truffleruby'
21
+ gem 'stackprof'
22
+ end
19
23
  end
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2009 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
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,9 +1,8 @@
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=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)
4
+ [![Build Status](https://travis-ci.org/haml/haml.svg?branch=main)](http://travis-ci.org/haml/haml)
5
+ [![Code Climate](https://codeclimate.com/github/haml/haml/badges/gpa.svg)](https://codeclimate.com/github/haml/haml)
7
6
  [![Inline docs](http://inch-ci.org/github/haml/haml.png)](http://inch-ci.org/github/haml/haml)
8
7
 
9
8
  Haml is a templating engine for HTML. It's designed to make it both easier and
@@ -32,7 +31,7 @@ to compile it to HTML. For more information on these commands, check out
32
31
  haml --help
33
32
  ~~~
34
33
 
35
- To use Haml programatically, check out the [YARD documentation](http://haml.info/docs/yardoc/).
34
+ To use Haml programmatically, check out the [YARD documentation](http://haml.info/docs/yardoc/).
36
35
 
37
36
  ## Using Haml with Rails
38
37
 
@@ -191,7 +190,7 @@ Some of Natalie's work on Haml was supported by Unspace Interactive.
191
190
 
192
191
  Beyond that, the implementation is licensed under the MIT License.
193
192
 
194
- Copyright (c) 2006-2013 Hampton Catlin, Natalie Weizenbaum and the Haml team
193
+ Copyright (c) 2006-2019 Hampton Catlin, Natalie Weizenbaum and the Haml team
195
194
 
196
195
  Permission is hereby granted, free of charge, to any person obtaining a copy of
197
196
  this software and associated documentation files (the "Software"), to deal in
data/REFERENCE.md CHANGED
@@ -107,13 +107,25 @@ output.
107
107
  In Rails, options can be set by setting the {Haml::Template#options Haml::Template.options}
108
108
  hash in an initializer:
109
109
 
110
- # config/initializers/haml.rb
111
- Haml::Template.options[:format] = :html5
110
+ ```ruby
111
+ # 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
116
+ ```
112
117
 
113
118
  Outside Rails, you can set them by configuring them globally in
114
119
  Haml::Options.defaults:
115
120
 
116
- Haml::Options.defaults[:format] = :html5
121
+ ```ruby
122
+ Haml::Options.defaults[:format] = :html5
123
+ ```
124
+
125
+ In sinatra specifically, you can set them in global config with:
126
+ ```ruby
127
+ set :haml, { escape_html: true }
128
+ ```
117
129
 
118
130
  Finally, you can also set them by passing an options hash to
119
131
  {Haml::Engine#initialize}. For the complete list of available options, please
@@ -223,15 +235,19 @@ is compiled to:
223
235
  <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'></html>
224
236
 
225
237
  Attribute hashes can also be stretched out over multiple lines to accommodate
226
- many attributes. However, newlines may only be placed immediately after commas.
227
- For example:
238
+ many attributes.
228
239
 
229
- %script{:type => "text/javascript",
230
- :src => "javascripts/script_#{2 + 7}"}
240
+ %script{
241
+ "type": text/javascript",
242
+ "src": javascripts/script_#{2 + 7}",
243
+ "data": {
244
+ "controller": "reporter",
245
+ },
246
+ }
231
247
 
232
248
  is compiled to:
233
249
 
234
- <script src='javascripts/script_9' type='text/javascript'></script>
250
+ <script src='javascripts/script_9' type='text/javascript' data-controller='reporter'></script>
235
251
 
236
252
  #### `:class` and `:id` Attributes {#class-and-id-attributes}
237
253
 
@@ -512,6 +528,24 @@ and is compiled to:
512
528
  </div>
513
529
  </div>
514
530
 
531
+ #### Class Name Merging and Ordering
532
+
533
+ Class names are ordered in the following way:
534
+
535
+ 1) Tag identifiers in order (aka, ".alert.me" => "alert me")
536
+ 2) Classes appearing in HTML-style attributes
537
+ 3) Classes appearing in Hash-style attributes
538
+
539
+ For instance, this is a complicated and unintuitive test case illustrating the ordering
540
+
541
+ .foo.moo{:class => ['bar', 'alpha']}(class='baz')
542
+
543
+ The resulting HTML would be as follows:
544
+
545
+ <div class='foo moo baz bar alpha'></div>
546
+
547
+ *Versions of Haml prior to 5.0 would alphabetically sort class names.*
548
+
515
549
  ### Empty (void) Tags: `/`
516
550
 
517
551
  The forward slash character, when placed at the end of a tag definition, causes
@@ -848,7 +882,7 @@ is compiled to:
848
882
 
849
883
  ## Ruby Evaluation
850
884
 
851
- ### Inserting Ruby: `=`
885
+ ### Inserting Ruby: `=` {#inserting_ruby}
852
886
 
853
887
  The equals character is followed by Ruby code. This code is evaluated and the
854
888
  output is inserted into the document. For example:
@@ -1120,8 +1154,8 @@ is compiled to
1120
1154
  <p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
1121
1155
  </div>
1122
1156
 
1123
- Note that `#{}` interpolation within filters is HTML-escaped if you specify
1124
- {Haml::Options#escape_html `:escape_html`} option.
1157
+ Note that `#{}` interpolation within filters is HTML-escaped if you specify true to
1158
+ {Haml::Options#escape_filter_interpolations `:escape_filter_interpolations`} option.
1125
1159
 
1126
1160
  The functionality of some filters such as Markdown can be provided by many
1127
1161
  different libraries. Usually you don't have to worry about this - you can just
@@ -1318,7 +1352,7 @@ that just need a lot of template information.
1318
1352
  So data structures and functions that require lots of arguments
1319
1353
  can be wrapped over multiple lines,
1320
1354
  as long as each line but the last ends in a comma
1321
- (see [Inserting Ruby](#inserting_ruby_)).
1355
+ (see [Inserting Ruby](#inserting_ruby)).
1322
1356
 
1323
1357
  ## Whitespace Preservation
1324
1358
 
data/Rakefile CHANGED
@@ -1,126 +1,116 @@
1
- require "rake/clean"
2
- require "rake/testtask"
3
- require "bundler/gem_tasks"
4
-
5
- task :default => :test
6
-
7
- # FIXME: Redefining :test task to run test/options_test.rb in isolated process since it depends on whether Rails is loaded or not.
8
- # Remove this task when we finished changing escape_html option to be true by default.
9
- isolated_test = Rake::TestTask.new do |t|
10
- t.libs << 'test'
11
- t.test_files = %w[test/options_test.rb]
12
- t.warning = true
13
- t.verbose = true
14
- end
15
- Rake::TestTask.new do |t|
16
- t.libs << 'test'
17
- t.test_files = Dir['test/*_test.rb'] + Dir['test/haml-spec/*_test.rb'] - isolated_test.file_list
18
- t.warning = true
19
- t.verbose = true
1
+ require 'bundler/gem_tasks'
2
+
3
+ #
4
+ # Prepend DevKit into compilation phase
5
+ #
6
+ if Gem.win_platform?
7
+ desc 'Activates DevKit'
8
+ task :devkit do
9
+ begin
10
+ require 'devkit'
11
+ rescue LoadError
12
+ abort 'Failed to load DevKit required for compilation'
13
+ end
14
+ end
15
+ task compile: :devkit
20
16
  end
21
17
 
22
- CLEAN.replace %w(pkg doc coverage .yardoc test/haml vendor)
23
-
24
- desc "Benchmark Haml against ERB. TIMES=n sets the number of runs, default is 1000."
25
- task :benchmark do
26
- sh "ruby benchmark.rb #{ENV['TIMES']}"
27
- end
18
+ require 'rake/testtask'
19
+ if /java/ === RUBY_PLATFORM
20
+ # require 'rake/javaextensiontask'
21
+ # Rake::JavaExtensionTask.new(:haml) do |ext|
22
+ # ext.ext_dir = 'ext/java'
23
+ # ext.lib_dir = 'lib/haml'
24
+ # end
28
25
 
29
- task :set_coverage_env do
30
- ENV["COVERAGE"] = "true"
26
+ task :compile do
27
+ # dummy for now
28
+ end
29
+ else
30
+ require 'rake/extensiontask'
31
+ Rake::ExtensionTask.new(:haml) do |ext|
32
+ ext.lib_dir = 'lib/haml'
33
+ end
31
34
  end
32
35
 
33
- desc "Run Simplecov"
34
- task :coverage => [:set_coverage_env, :test]
36
+ Dir['benchmark/*.rake'].each { |b| import(b) }
35
37
 
36
- task :submodules do
37
- if File.exist?(File.dirname(__FILE__) + "/.git")
38
- sh %{git submodule sync}
39
- sh %{git submodule update --init --recursive}
38
+ namespace :haml do
39
+ Rake::TestTask.new do |t|
40
+ t.libs << 'lib' << 'test'
41
+ files = Dir['test/haml/*_test.rb']
42
+ files << 'test/haml/haml-spec/*_test.rb'
43
+ t.ruby_opts = %w[-rtest_helper]
44
+ t.test_files = files
45
+ t.verbose = true
40
46
  end
41
47
  end
42
48
 
43
- namespace :doc do
44
- task :sass do
45
- require 'sass'
46
- Dir["yard/default/**/*.sass"].each do |sass|
47
- File.open(sass.gsub(/sass$/, 'css'), 'w') do |f|
48
- f.write(Sass::Engine.new(File.read(sass)).render)
49
- end
50
- end
51
- end
52
-
53
- desc "List all undocumented methods and classes."
54
- task :undocumented do
55
- command = 'yard --list --query '
56
- command << '"object.docstring.blank? && '
57
- command << '!(object.type == :method && object.is_alias?)"'
58
- sh command
49
+ namespace :hamlit do
50
+ Rake::TestTask.new do |t|
51
+ t.libs << 'lib' << 'test'
52
+ t.ruby_opts = %w[-rtest_helper]
53
+ t.test_files = Dir['test/hamlit/**/*_test.rb']
54
+ t.verbose = true
59
55
  end
60
56
  end
61
57
 
62
- desc "Generate documentation"
63
- task(:doc => 'doc:sass') {sh "yard"}
64
-
65
- desc "Generate documentation incrementally"
66
- task(:redoc) {sh "yard -c"}
67
-
68
- desc <<END
69
- Profile Haml.
70
- TIMES=n sets the number of runs. Defaults to 1000.
71
- FILE=str sets the file to profile. Defaults to 'standard'
72
- OUTPUT=str sets the ruby-prof output format.
73
- Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
74
- END
75
- task :profile do
76
- times = (ENV['TIMES'] || '1000').to_i
77
- file = ENV['FILE'] || 'test/templates/standard.haml'
78
-
79
- require 'bundler/setup'
80
- require 'ruby-prof'
81
- require 'haml'
82
- file = File.read(File.expand_path("../#{file}", __FILE__))
83
- obj = Object.new
84
- Haml::Engine.new(file).def_method(obj, :render)
85
- result = RubyProf.profile { times.times { obj.render } }
58
+ namespace :test do
59
+ Rake::TestTask.new(:all) do |t|
60
+ t.libs << 'lib' << 'test'
61
+ files = Dir['test/hamlit/**/*_test.rb']
62
+ files += Dir['test/haml/*_test.rb']
63
+ files << 'test/haml/haml-spec/*_test.rb'
64
+ t.ruby_opts = %w[-rtest_helper]
65
+ t.test_files = files
66
+ t.verbose = true
67
+ end
86
68
 
87
- RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
88
- end
69
+ Rake::TestTask.new(:spec) do |t|
70
+ t.libs << 'lib' << 'test'
71
+ t.ruby_opts = %w[-rtest_helper]
72
+ t.test_files = %w[test/haml/haml-spec/ugly_test.rb test/haml/haml-spec/pretty_test.rb]
73
+ t.verbose = true
74
+ end
89
75
 
90
- def gemfiles
91
- @gemfiles ||= begin
92
- Dir[File.dirname(__FILE__) + '/test/gemfiles/Gemfile.*'].
93
- reject {|f| f =~ /\.lock$/}.
94
- reject {|f| RUBY_VERSION < '1.9.3' && f =~ /Gemfile.rails-(\d+).\d+.x/ && $1.to_i > 3}
76
+ Rake::TestTask.new(:engine) do |t|
77
+ t.libs << 'lib' << 'test'
78
+ t.ruby_opts = %w[-rtest_helper]
79
+ t.test_files = %w[test/haml/engine_test.rb]
80
+ t.verbose = true
95
81
  end
96
- end
97
82
 
98
- def with_each_gemfile
99
- gemfiles.each do |gemfile|
100
- Bundler.with_clean_env do
101
- puts "Using gemfile: #{gemfile}"
102
- ENV['BUNDLE_GEMFILE'] = gemfile
103
- yield
104
- end
83
+ Rake::TestTask.new(:filters) do |t|
84
+ t.libs << 'lib' << 'test'
85
+ t.ruby_opts = %w[-rtest_helper]
86
+ t.test_files = %w[test/haml/filters_test.rb]
87
+ t.verbose = true
105
88
  end
106
- end
107
89
 
108
- namespace :test do
109
- namespace :bundles do
110
- desc "Install all dependencies necessary to test Haml."
111
- task :install do
112
- with_each_gemfile {sh "bundle"}
113
- end
90
+ Rake::TestTask.new(:helper) do |t|
91
+ t.libs << 'lib' << 'test'
92
+ t.ruby_opts = %w[-rtest_helper]
93
+ t.test_files = %w[test/haml/helper_test.rb]
94
+ t.verbose = true
95
+ end
114
96
 
115
- desc "Update all dependencies for testing Haml."
116
- task :update do
117
- with_each_gemfile {sh "bundle update"}
118
- end
97
+ Rake::TestTask.new(:template) do |t|
98
+ t.libs << 'lib' << 'test'
99
+ t.ruby_opts = %w[-rtest_helper]
100
+ t.test_files = %w[test/haml/template_test.rb]
101
+ t.verbose = true
119
102
  end
103
+ end
120
104
 
121
- desc "Test all supported versions of rails. This takes a while."
122
- task :rails_compatibility => 'test:bundles:install' do
123
- with_each_gemfile {sh "bundle exec rake test"}
105
+ desc 'bench task for CI'
106
+ task bench: :compile do
107
+ if ENV['SLIM_BENCH'] == '1'
108
+ cmd = %w[bundle exec ruby benchmark/slim/run-benchmarks.rb]
109
+ else
110
+ cmd = ['bin/bench', 'bench', ('-c' if ENV['COMPILE'] == '1'), *ENV['TEMPLATE'].split(',')].compact
124
111
  end
125
- task :rc => :rails_compatibility
112
+ exit system(*cmd)
126
113
  end
114
+
115
+ task default: %w[compile hamlit:test]
116
+ task test: %w[compile test:all]
data/bin/bench ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'haml'
5
+ require 'thor'
6
+ require 'benchmark/ips'
7
+ require_relative '../benchmark/utils/benchmark_ips_extension'
8
+
9
+ class Bench < Thor
10
+ class_option :show_template, type: :boolean, aliases: ['-t']
11
+
12
+ desc 'bench HAML', 'Benchmark haml template'
13
+ option :compile, type: :boolean, aliases: ['-c']
14
+ option :show_code, type: :boolean, aliases: ['-s']
15
+ def bench(*files)
16
+ files.each { |file| render(file) }
17
+ files.each { |file| compile(file) if options[:compile] }
18
+ files.each { |file| code(file) if options[:show_code] }
19
+ end
20
+
21
+ desc 'compile HAML', 'Benchmark compilation'
22
+ def compile(file)
23
+ puts "#{?= * 49}\n Compilation: #{file}\n#{?= * 49}"
24
+ haml = File.read(file)
25
+
26
+ Benchmark.ips do |x|
27
+ x.report("haml v#{Haml::VERSION}") { Haml::Engine.new.call(haml) }
28
+ x.compare!
29
+ end
30
+ end
31
+
32
+ desc 'render HAML', 'Benchmark rendering'
33
+ def render(file)
34
+ puts "#{?= * 49}\n Rendering: #{file}\n#{?= * 49}"
35
+ haml = File.read(file)
36
+ puts haml + "\n" if options[:show_template]
37
+ object = Object.new
38
+ ruby_file = file.gsub(/\.haml\z/, '.rb')
39
+ if File.exist?(ruby_file)
40
+ object.instance_eval(File.read(ruby_file))
41
+ end
42
+
43
+ object.instance_eval "def haml; #{Haml::Engine.new.call(haml)}; end"
44
+
45
+ Benchmark.ips do |x|
46
+ x.report("haml v#{Haml::VERSION}") { object.haml }
47
+ x.compare!
48
+ end
49
+ end
50
+
51
+ desc 'code HAML', 'Show compiled code'
52
+ def code(file)
53
+ haml = File.read(file)
54
+ puts "\n#{?= * 49}\n Haml Source: #{file}\n#{?= * 49}"
55
+ puts Haml::Engine.new.call(haml)
56
+ end
57
+
58
+ private
59
+
60
+ def method_missing(*args)
61
+ return super if args.length > 1
62
+ render(args.first.to_s)
63
+ end
64
+ end
65
+
66
+ Bench.start
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'hamlit'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
data/bin/ruby ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ bundle exec ruby -Ilib:test -rtest_helper $@
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here