haml 5.2.2 → 6.0.0.beta.1
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.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/test.yml +13 -9
- data/.gitignore +16 -16
- data/CHANGELOG.md +13 -3
- data/Gemfile +18 -11
- data/MIT-LICENSE +1 -1
- data/README.md +13 -19
- data/Rakefile +95 -93
- 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 +135 -179
- data/lib/haml/attribute_compiler.rb +85 -194
- data/lib/haml/attribute_parser.rb +86 -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 +42 -227
- data/lib/haml/error.rb +3 -52
- 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/haml_error.rb +66 -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 +30 -0
- data/lib/haml/parser.rb +179 -49
- data/lib/haml/rails_helpers.rb +51 -0
- data/lib/haml/rails_template.rb +55 -0
- data/lib/haml/railtie.rb +7 -45
- data/lib/haml/ruby_expression.rb +32 -0
- data/lib/haml/string_splitter.rb +20 -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 +211 -57
- data/.gitmodules +0 -3
- data/.yardopts +0 -22
- 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: 6bda3cad64d59ca87a154986af35ca0e8f4aad63ccb20dcfc6baef0d4d1c5484
|
4
|
+
data.tar.gz: 025dca6d373cc07efe22112720722b4b419cb64b7588db502ee96d3597798edb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e526126720ad094d1a15281c028c8c8e002a3bcc1929f40d92caeebe25dccd1e8dc99471e7f52f95290241b65e4a83266c6e7fe58771891095e897408eef9b80
|
7
|
+
data.tar.gz: '078dfbdbd0c4f3904d303a376f2c460f4e35ba33b0e87bb33d449246e925e4d7e42248b32bd1060586d527130629d41e682ee426b2fb9a2539a6adca3ecde09c'
|
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/CHANGELOG.md
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
# Haml Changelog
|
2
2
|
|
3
|
+
## 6.0.0
|
4
|
+
|
5
|
+
Not released yet
|
6
|
+
([diff](https://github.com/haml/haml/compare/v5.2.2...main)).
|
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
|
+
* All Haml helpers except for `preserve` are removed.
|
12
|
+
* Some legacy Rails integration is removed.
|
13
|
+
|
3
14
|
## 5.2.2
|
15
|
+
|
4
16
|
Released on July 27, 2021
|
5
17
|
([diff](https://github.com/haml/haml/compare/v5.2.1...v5.2.2)).
|
6
18
|
|
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+
|
19
|
+
* Support `config.action_view.annotate_rendered_view_with_filenames = true` of Rails 6.1
|
10
20
|
|
11
21
|
## 5.2.1
|
12
22
|
|
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
@@ -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
|
@@ -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/Rakefile
CHANGED
@@ -1,115 +1,117 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Prepend DevKit into compilation phase
|
6
|
+
#
|
7
|
+
if Gem.win_platform?
|
8
|
+
desc 'Activates DevKit'
|
9
|
+
task :devkit do
|
10
|
+
begin
|
11
|
+
require 'devkit'
|
12
|
+
rescue LoadError
|
13
|
+
abort 'Failed to load DevKit required for compilation'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
task compile: :devkit
|
17
|
+
end
|
4
18
|
|
5
|
-
|
19
|
+
require 'rake/testtask'
|
20
|
+
if /java/ === RUBY_PLATFORM
|
21
|
+
# require 'rake/javaextensiontask'
|
22
|
+
# Rake::JavaExtensionTask.new(:haml) do |ext|
|
23
|
+
# ext.ext_dir = 'ext/java'
|
24
|
+
# ext.lib_dir = 'lib/haml'
|
25
|
+
# end
|
6
26
|
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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'] + Dir['test/cases/*_test.rb'] - isolated_test.file_list
|
18
|
-
t.warning = true
|
19
|
-
t.verbose = true
|
27
|
+
task :compile do
|
28
|
+
# dummy for now
|
29
|
+
end
|
30
|
+
else
|
31
|
+
require 'rake/extensiontask'
|
32
|
+
Rake::ExtensionTask.new(:haml) do |ext|
|
33
|
+
ext.lib_dir = 'lib/haml'
|
34
|
+
end
|
20
35
|
end
|
21
36
|
|
22
|
-
|
37
|
+
Dir['benchmark/*.rake'].each { |b| import(b) }
|
23
38
|
|
24
|
-
|
25
|
-
|
26
|
-
|
39
|
+
namespace :haml do
|
40
|
+
Rake::TestTask.new do |t|
|
41
|
+
t.libs << 'lib' << 'test'
|
42
|
+
files = Dir['test/haml/*_test.rb']
|
43
|
+
files << 'test/haml/haml-spec/*_test.rb'
|
44
|
+
t.ruby_opts = %w[-rtest_helper]
|
45
|
+
t.test_files = files
|
46
|
+
t.verbose = true
|
47
|
+
end
|
27
48
|
end
|
28
49
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
50
|
+
namespace :hamlit do
|
51
|
+
Rake::TestTask.new do |t|
|
52
|
+
t.libs << 'lib' << 'test'
|
53
|
+
t.ruby_opts = %w[-rtest_helper]
|
54
|
+
t.test_files = Dir['test/hamlit/**/*_test.rb']
|
55
|
+
t.verbose = true
|
33
56
|
end
|
34
57
|
end
|
35
58
|
|
36
|
-
namespace :
|
37
|
-
|
38
|
-
|
39
|
-
Dir[
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
59
|
+
namespace :test do
|
60
|
+
Rake::TestTask.new(:all) do |t|
|
61
|
+
t.libs << 'lib' << 'test'
|
62
|
+
files = Dir['test/hamlit/**/*_test.rb']
|
63
|
+
files += Dir['test/haml/*_test.rb']
|
64
|
+
files << 'test/haml/haml-spec/*_test.rb'
|
65
|
+
t.ruby_opts = %w[-rtest_helper]
|
66
|
+
t.test_files = files
|
67
|
+
t.verbose = true
|
44
68
|
end
|
45
69
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
sh command
|
70
|
+
Rake::TestTask.new(:spec) do |t|
|
71
|
+
t.libs << 'lib' << 'test'
|
72
|
+
t.ruby_opts = %w[-rtest_helper]
|
73
|
+
t.test_files = %w[test/haml/haml-spec/ugly_test.rb test/haml/haml-spec/pretty_test.rb]
|
74
|
+
t.verbose = true
|
52
75
|
end
|
53
|
-
end
|
54
|
-
|
55
|
-
desc "Generate documentation"
|
56
|
-
task(:doc => 'doc:sass') {sh "yard"}
|
57
|
-
|
58
|
-
desc "Generate documentation incrementally"
|
59
|
-
task(:redoc) {sh "yard -c"}
|
60
|
-
|
61
|
-
desc <<END
|
62
|
-
Profile Haml.
|
63
|
-
TIMES=n sets the number of runs. Defaults to 1000.
|
64
|
-
FILE=str sets the file to profile. Defaults to 'standard'
|
65
|
-
OUTPUT=str sets the ruby-prof output format.
|
66
|
-
Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
|
67
|
-
END
|
68
|
-
task :profile do
|
69
|
-
times = (ENV['TIMES'] || '1000').to_i
|
70
|
-
file = ENV['FILE'] || 'test/templates/standard.haml'
|
71
76
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
result = RubyProf.profile { times.times { obj.render } }
|
79
|
-
|
80
|
-
RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
|
81
|
-
end
|
82
|
-
|
83
|
-
def gemfiles
|
84
|
-
@gemfiles ||= Dir[File.dirname(__FILE__) + '/test/gemfiles/Gemfile.*'].reject {|f| f =~ /\.lock$/}
|
85
|
-
end
|
77
|
+
Rake::TestTask.new(:engine) do |t|
|
78
|
+
t.libs << 'lib' << 'test'
|
79
|
+
t.ruby_opts = %w[-rtest_helper]
|
80
|
+
t.test_files = %w[test/haml/engine_test.rb]
|
81
|
+
t.verbose = true
|
82
|
+
end
|
86
83
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
yield
|
93
|
-
end
|
84
|
+
Rake::TestTask.new(:filters) do |t|
|
85
|
+
t.libs << 'lib' << 'test'
|
86
|
+
t.ruby_opts = %w[-rtest_helper]
|
87
|
+
t.test_files = %w[test/haml/filters_test.rb]
|
88
|
+
t.verbose = true
|
94
89
|
end
|
95
|
-
end
|
96
90
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
91
|
+
Rake::TestTask.new(:helper) do |t|
|
92
|
+
t.libs << 'lib' << 'test'
|
93
|
+
t.ruby_opts = %w[-rtest_helper]
|
94
|
+
t.test_files = %w[test/haml/helper_test.rb]
|
95
|
+
t.verbose = true
|
96
|
+
end
|
103
97
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
98
|
+
Rake::TestTask.new(:template) do |t|
|
99
|
+
t.libs << 'lib' << 'test'
|
100
|
+
t.ruby_opts = %w[-rtest_helper]
|
101
|
+
t.test_files = %w[test/haml/template_test.rb]
|
102
|
+
t.verbose = true
|
108
103
|
end
|
104
|
+
end
|
109
105
|
|
110
|
-
|
111
|
-
|
112
|
-
|
106
|
+
desc 'bench task for CI'
|
107
|
+
task bench: :compile do
|
108
|
+
if ENV['SLIM_BENCH'] == '1'
|
109
|
+
cmd = %w[bundle exec ruby benchmark/slim/run-benchmarks.rb]
|
110
|
+
else
|
111
|
+
cmd = ['bin/bench', 'bench', ('-c' if ENV['COMPILE'] == '1'), *ENV['TEMPLATE'].split(',')].compact
|
113
112
|
end
|
114
|
-
|
113
|
+
exit system(*cmd)
|
115
114
|
end
|
115
|
+
|
116
|
+
task default: %w[compile hamlit:test]
|
117
|
+
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
data/bin/setup
ADDED
data/bin/stackprof
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'hamlit'
|
5
|
+
require 'stackprof'
|
6
|
+
|
7
|
+
def open_flamegraph(report)
|
8
|
+
temp = `mktemp /tmp/stackflame-XXXXXXXX`.strip
|
9
|
+
data_path = "#{temp}.js"
|
10
|
+
system("mv #{temp} #{data_path}")
|
11
|
+
|
12
|
+
File.open(data_path, 'w') do |f|
|
13
|
+
report.print_flamegraph(f)
|
14
|
+
end
|
15
|
+
|
16
|
+
viewer_path = File.join(`bundle show stackprof`.strip, 'lib/stackprof/flamegraph/viewer.html')
|
17
|
+
url = "file://#{viewer_path}?data=#{data_path}"
|
18
|
+
system(%Q[osascript -e 'open location "#{url}"'])
|
19
|
+
end
|
20
|
+
|
21
|
+
haml = File.read(ARGV.first)
|
22
|
+
StackProf.start(mode: :wall, interval: 1, raw: false)
|
23
|
+
Hamlit::Engine.new.call(haml)
|
24
|
+
StackProf.stop
|
25
|
+
|
26
|
+
report = StackProf::Report.new(StackProf.results)
|
27
|
+
report.print_text(false)
|
data/bin/test
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
VERSIONS=(
|
4
|
+
2.1.10
|
5
|
+
2.2.5
|
6
|
+
2.3.1
|
7
|
+
)
|
8
|
+
|
9
|
+
set -e
|
10
|
+
trap 'echo "${VERSIONS[2]}" > .ruby-version' 0
|
11
|
+
|
12
|
+
function test_with() {
|
13
|
+
version=$1
|
14
|
+
rbenv local $version
|
15
|
+
if ! bundle check > /dev/null; then
|
16
|
+
bundle install
|
17
|
+
fi
|
18
|
+
ruby -v
|
19
|
+
bundle exec rake test
|
20
|
+
}
|
21
|
+
|
22
|
+
for version in ${VERSIONS[@]}; do
|
23
|
+
test_with $version
|
24
|
+
done
|
data/exe/haml
ADDED