hamlit 3.0.1 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/bench.yml +2 -24
- data/.github/workflows/test.yml +2 -8
- data/CHANGELOG.md +15 -0
- data/Gemfile +0 -1
- data/README.md +17 -40
- data/REFERENCE.md +1 -75
- data/Rakefile +1 -6
- data/bin/bench +0 -6
- data/lib/hamlit/engine.rb +1 -1
- data/lib/hamlit/filters/tilt_base.rb +5 -1
- data/lib/hamlit/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0739d31df6aecc4a332c868e258322fb77a8e6003d5aa2c5fee02468809f009b'
|
4
|
+
data.tar.gz: 1917aeca307e771331e8e6d997ef58c90f106c2f4c002e35c4fb7fd424779db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80000682f6fa89d6ceedd7137d3b1156bb9850707640bfdaf3330249c81251f6a036b3e175617d6e9b51e218d5f2cf12b551772c223e83bc6f7836afe260e62b
|
7
|
+
data.tar.gz: 87b2fb79433a8c593d0dbd4d0df17f28f5b5d64c250833048d4f6eddeb729c9394aa13a541cad8f2436237dd7da2a218af06910e4d9886f3a6ed7322f62d5d1a
|
data/.github/workflows/bench.yml
CHANGED
@@ -13,34 +13,12 @@ on:
|
|
13
13
|
jobs:
|
14
14
|
bench:
|
15
15
|
runs-on: ubuntu-latest
|
16
|
-
strategy:
|
17
|
-
fail-fast: false
|
18
|
-
matrix:
|
19
|
-
include:
|
20
|
-
- slim: 1
|
21
|
-
- template: 'benchmark/boolean_attribute.haml,benchmark/class_attribute.haml,benchmark/id_attribute.haml,benchmark/data_attribute.haml,benchmark/common_attribute.haml'
|
22
|
-
- template: 'benchmark/dynamic_attributes/boolean_attribute.haml,benchmark/dynamic_attributes/class_attribute.haml,benchmark/dynamic_attributes/id_attribute.haml,benchmark/dynamic_attributes/data_attribute.haml,benchmark/dynamic_attributes/common_attribute.haml'
|
23
|
-
- template: 'benchmark/etc/attribute_builder.haml'
|
24
|
-
- template: 'benchmark/etc/static_analyzer.haml'
|
25
|
-
- template: 'benchmark/etc/string_interpolation.haml'
|
26
|
-
- template: 'test/haml/templates/standard.haml'
|
27
|
-
compile: 1
|
28
16
|
steps:
|
29
17
|
- uses: actions/checkout@v2
|
18
|
+
- run: sudo apt-get update && sudo apt-get install -y nodejs libxslt-dev # nodejs for execjs, libxslt for TruffleRuby nokogiri
|
30
19
|
- name: Set up Ruby
|
31
20
|
uses: ruby/setup-ruby@v1
|
32
21
|
with:
|
33
22
|
ruby-version: '3.0'
|
34
|
-
|
35
|
-
with:
|
36
|
-
path: vendor/bundle
|
37
|
-
key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
38
|
-
restore-keys: ${{ runner.os }}-gems-
|
39
|
-
- run: sudo apt-get update && sudo apt-get install -y nodejs libxslt-dev # nodejs for execjs, libxslt for TruffleRuby nokogiri
|
40
|
-
- name: bundle install
|
41
|
-
run: bundle config path vendor/bundle && bundle install -j$(nproc) --retry 3
|
23
|
+
bundler-cache: true
|
42
24
|
- run: bundle exec rake bench
|
43
|
-
env:
|
44
|
-
SLIM_BENCH: ${{ matrix.slim }}
|
45
|
-
TEMPLATE: ${{ matrix.template }}
|
46
|
-
COMPILE: ${{ matrix.compile }}
|
data/.github/workflows/test.yml
CHANGED
@@ -25,16 +25,10 @@ jobs:
|
|
25
25
|
- truffleruby-head
|
26
26
|
steps:
|
27
27
|
- uses: actions/checkout@v2
|
28
|
+
- run: sudo apt-get update && sudo apt-get install -y nodejs libxslt-dev # nodejs for execjs, libxslt for TruffleRuby nokogiri
|
28
29
|
- name: Set up Ruby
|
29
30
|
uses: ruby/setup-ruby@v1
|
30
31
|
with:
|
31
32
|
ruby-version: ${{ matrix.ruby }}
|
32
|
-
|
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
|
33
|
+
bundler-cache: true
|
40
34
|
- run: bundle exec rake test
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file. This
|
|
4
4
|
project adheres to [Semantic Versioning](http://semver.org/). This change log is based upon
|
5
5
|
[keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog).
|
6
6
|
|
7
|
+
## [3.0.3](https://github.com/k0kubun/hamlit/compare/v3.0.2...v3.0.3) - 2022-11-07
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Support sass-embedded [#196](https://github.com/k0kubun/hamlit/issues/196)
|
12
|
+
*Thanks to @ntkme*
|
13
|
+
|
14
|
+
## [3.0.2](https://github.com/k0kubun/hamlit/compare/v3.0.1...v3.0.2) - 2022-10-13
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- `Hamlit::Engine` and `Hamlit::Template` use StringBuffer instead of ArrayBuffer
|
19
|
+
- It seems more performant in many cases with recent Ruby versions.
|
20
|
+
- `Hamlit::RailsTemplate` is not affected.
|
21
|
+
|
7
22
|
## [3.0.1](https://github.com/k0kubun/hamlit/compare/v3.0.0...v3.0.1) - 2022-08-18
|
8
23
|
|
9
24
|
### Changed
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,12 +5,22 @@
|
|
5
5
|
|
6
6
|
Hamlit is a high performance [Haml](https://github.com/haml/haml) implementation.
|
7
7
|
|
8
|
+
## Project status
|
9
|
+
|
10
|
+
**Hamlit's implementation was copied to Haml 6.**
|
11
|
+
From Haml 6, you don't need to switch to Hamlit.
|
12
|
+
|
13
|
+
Both Haml 6 and Hamlit are still maintained by [@k0kubun](https://github.com/k0kubun).
|
14
|
+
While you don't need to immediately deprecate Hamlit, Haml 6 has more maintainers
|
15
|
+
and you'd better start a new project with Haml rather than Hamlit,
|
16
|
+
given no performance difference between them.
|
17
|
+
|
8
18
|
## Introduction
|
9
19
|
|
10
20
|
### What is Hamlit?
|
11
21
|
Hamlit is another implementation of [Haml](https://github.com/haml/haml).
|
12
|
-
With some [
|
13
|
-
Hamlit is **1.94x times faster** than original
|
22
|
+
With some [Hamlit's characteristics](REFERENCE.md#hamlits-characteristics) for performance,
|
23
|
+
Hamlit is **1.94x times faster** than the original Haml 5 in [this benchmark](benchmark/run-benchmarks.rb),
|
14
24
|
which is an HTML-escaped version of [slim-template/slim's one](https://github.com/slim-template/slim/blob/4.1.0/benchmarks/run-benchmarks.rb) for fairness. ([Result on Travis](https://travis-ci.org/github/k0kubun/hamlit/jobs/732178446))
|
15
25
|
|
16
26
|
<img src="https://raw.githubusercontent.com/k0kubun/hamlit/afcc2b36c4861c2f764baa09afd9530ca25eeafa/benchmark/graph/graph.png" width="600x" alt="Hamlit Benchmark" />
|
@@ -23,11 +33,12 @@ which is an HTML-escaped version of [slim-template/slim's one](https://github.co
|
|
23
33
|
haml v5.2.0: 127834.4 i/s - 1.94x slower
|
24
34
|
```
|
25
35
|
|
26
|
-
### Why is Hamlit
|
36
|
+
### Why is Hamlit fast?
|
27
37
|
|
28
38
|
#### Less string concatenation by design
|
29
|
-
As written in [
|
30
|
-
|
39
|
+
As written in [Hamlit's characteristics](REFERENCE.md#hamlits-characteristics),
|
40
|
+
Hamlit drops some not-so-important features which require works on runtime.
|
41
|
+
With the optimized language design, we can reduce the string concatenation
|
31
42
|
to build attributes.
|
32
43
|
|
33
44
|
#### Static analyzer
|
@@ -42,7 +53,7 @@ with C extension.
|
|
42
53
|
|
43
54
|
## Usage
|
44
55
|
|
45
|
-
|
56
|
+
See [REFERENCE.md](REFERENCE.md) for details.
|
46
57
|
|
47
58
|
### Rails
|
48
59
|
|
@@ -97,40 +108,6 @@ $ hamlit render in.haml
|
|
97
108
|
|
98
109
|
## Contributing
|
99
110
|
|
100
|
-
### Test latest version
|
101
|
-
|
102
|
-
```rb
|
103
|
-
# Gemfile
|
104
|
-
gem 'hamlit', github: 'k0kubun/hamlit', submodules: true
|
105
|
-
```
|
106
|
-
|
107
|
-
### Development
|
108
|
-
|
109
|
-
Contributions are welcomed. It'd be good to see
|
110
|
-
[Temple's EXPRESSIONS.md](https://github.com/judofyr/temple/blob/v0.7.6/EXPRESSIONS.md)
|
111
|
-
to learn Temple which is a template engine framework used in Hamlit.
|
112
|
-
|
113
|
-
```bash
|
114
|
-
$ git clone --recursive https://github.com/k0kubun/hamlit
|
115
|
-
$ cd hamlit
|
116
|
-
$ bundle install
|
117
|
-
|
118
|
-
# Run all tests
|
119
|
-
$ bundle exec rake test
|
120
|
-
|
121
|
-
# Run one test
|
122
|
-
$ bundle exec ruby -Ilib:test -rtest_helper test/hamlit/line_number_test.rb -l 12
|
123
|
-
|
124
|
-
# Show compiling/rendering result of some template
|
125
|
-
$ bundle exec exe/hamlit compile in.haml
|
126
|
-
$ bundle exec exe/hamlit render in.haml
|
127
|
-
|
128
|
-
# Use rails app to debug Hamlit
|
129
|
-
$ cd sample/rails
|
130
|
-
$ bundle install
|
131
|
-
$ bundle exec rails s
|
132
|
-
```
|
133
|
-
|
134
111
|
### Reporting an issue
|
135
112
|
|
136
113
|
Please report an issue with following information:
|
data/REFERENCE.md
CHANGED
@@ -5,81 +5,7 @@ See [Haml's tutorial](http://haml.info/tutorial.html) if you are not familiar wi
|
|
5
5
|
|
6
6
|
[REFERENCE - Haml Documentation](http://haml.info/docs/yardoc/file.REFERENCE.html)
|
7
7
|
|
8
|
-
##
|
9
|
-
|
10
|
-
See [Haml's reference](http://haml.info/docs/yardoc/file.REFERENCE.html)
|
11
|
-
for full features in original implementation.
|
12
|
-
|
13
|
-
- [ ] Using Haml
|
14
|
-
- [x] Rails XSS Protection
|
15
|
-
- [x] Ruby Module
|
16
|
-
- [x] Options
|
17
|
-
- [ ] Encodings
|
18
|
-
- [x] Plain Text
|
19
|
-
- [x] Escaping: \
|
20
|
-
- [ ] HTML Elements
|
21
|
-
- [x] Element Name: %
|
22
|
-
- [ ] Attributes: `
|
23
|
-
- [x] :class and :id Attributes
|
24
|
-
- [x] HTML-style Attributes: ()
|
25
|
-
- [x] Ruby 1.9-style Hashes
|
26
|
-
- [ ] Attribute Methods
|
27
|
-
- [x] Boolean Attributes
|
28
|
-
- [x] HTML5 Custom Data Attributes
|
29
|
-
- [x] Class and ID: . and #
|
30
|
-
- Implicit Div Elements
|
31
|
-
- [x] Empty (void) Tags: /
|
32
|
-
- [x] Whitespace Removal: > and <
|
33
|
-
- [x] Object Reference: []
|
34
|
-
- [x] Doctype: !!!
|
35
|
-
- [x] Comments
|
36
|
-
- [x] HTML Comments: /
|
37
|
-
- [x] Conditional Comments: /[]
|
38
|
-
- [x] Haml Comments: -#
|
39
|
-
- [x] Ruby Evaluation
|
40
|
-
- [x] Inserting Ruby: =
|
41
|
-
- [x] Running Ruby: -
|
42
|
-
- [x] Ruby Blocks
|
43
|
-
- [x] Whitespace Preservation: ~
|
44
|
-
- [x] Ruby Interpolation: #{}
|
45
|
-
- [x] Escaping HTML: &=
|
46
|
-
- [x] Unescaping HTML: !=
|
47
|
-
- [ ] Filters
|
48
|
-
- [x] :cdata
|
49
|
-
- [x] :coffee
|
50
|
-
- [x] :css
|
51
|
-
- [x] :erb
|
52
|
-
- [x] :escaped
|
53
|
-
- [x] :javascript
|
54
|
-
- [x] :less
|
55
|
-
- [x] :markdown
|
56
|
-
- [ ] :maruku
|
57
|
-
- [x] :plain
|
58
|
-
- [x] :preserve
|
59
|
-
- [x] :ruby
|
60
|
-
- `haml_io` API is not supported. Use [hamlit-haml\_io.gem](https://github.com/hamlit/hamlit-haml_io) if you need.
|
61
|
-
- [x] :sass
|
62
|
-
- [x] :scss
|
63
|
-
- [ ] :textile
|
64
|
-
- [ ] Custom Filters
|
65
|
-
- [x] Helper Methods
|
66
|
-
- [x] preserve
|
67
|
-
- [x] surround
|
68
|
-
- [x] precede
|
69
|
-
- [x] succeed
|
70
|
-
- [x] Multiline: |
|
71
|
-
- [x] Whitespace Preservation
|
72
|
-
- [ ] Helpers
|
73
|
-
|
74
|
-
|
75
|
-
## Limitations
|
76
|
-
|
77
|
-
### No Haml buffer
|
78
|
-
Hamlit uses `Array` as buffer for performance. So you can't touch Haml::Buffer from template when using Hamlit.
|
79
|
-
|
80
|
-
### Haml helpers are still in development
|
81
|
-
At the same time, because some methods in `Haml::Helpers` require `Haml::Buffer`, they are not supported now.
|
82
|
-
But some helpers are supported on Rails. Some of not-implemented methods are planned to be supported.
|
8
|
+
## Hamlit's characteristics
|
83
9
|
|
84
10
|
### Limited attributes hyphenation
|
85
11
|
In Haml, `%a{ foo: { bar: 'baz' } }` is rendered as `<a foo-bar='baz'></a>`, whatever foo is.
|
data/Rakefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'bundler/setup'
|
2
1
|
require 'bundler/gem_tasks'
|
3
2
|
|
4
3
|
#
|
@@ -105,11 +104,7 @@ end
|
|
105
104
|
|
106
105
|
desc 'bench task for CI'
|
107
106
|
task bench: :compile do
|
108
|
-
|
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
|
112
|
-
end
|
107
|
+
cmd = %w[bundle exec ruby benchmark/run-benchmarks.rb]
|
113
108
|
exit system(*cmd)
|
114
109
|
end
|
115
110
|
|
data/bin/bench
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'hamlit'
|
5
|
-
require 'faml'
|
6
5
|
require 'thor'
|
7
6
|
require 'benchmark/ips'
|
8
7
|
require_relative '../benchmark/utils/benchmark_ips_extension'
|
@@ -26,7 +25,6 @@ class Bench < Thor
|
|
26
25
|
|
27
26
|
Benchmark.ips do |x|
|
28
27
|
x.report("haml v#{Haml::VERSION}") { Haml::Engine.new(haml, escape_html: true, escape_attrs: true).precompiled }
|
29
|
-
x.report("faml v#{Faml::VERSION}") { Faml::Engine.new.call(haml) }
|
30
28
|
x.report("hamlit v#{Hamlit::VERSION}") { Hamlit::Engine.new.call(haml) }
|
31
29
|
x.compare!
|
32
30
|
end
|
@@ -44,12 +42,10 @@ class Bench < Thor
|
|
44
42
|
end
|
45
43
|
|
46
44
|
Haml::Engine.new(haml, escape_html: true, escape_attrs: true).def_method(object, :haml)
|
47
|
-
object.instance_eval "def faml; #{Faml::Engine.new.call(haml)}; end"
|
48
45
|
object.instance_eval "def hamlit; #{Hamlit::Engine.new.call(haml)}; end"
|
49
46
|
|
50
47
|
Benchmark.ips do |x|
|
51
48
|
x.report("haml v#{Haml::VERSION}") { object.haml }
|
52
|
-
x.report("faml v#{Faml::VERSION}") { object.faml }
|
53
49
|
x.report("hamlit v#{Hamlit::VERSION}") { object.hamlit }
|
54
50
|
x.compare!
|
55
51
|
end
|
@@ -60,8 +56,6 @@ class Bench < Thor
|
|
60
56
|
haml = File.read(file)
|
61
57
|
puts "#{?= * 49}\n Haml Source: #{file}\n#{?= * 49}"
|
62
58
|
puts Haml::Engine.new(haml, escape_html: true, escape_attrs: true).precompiled
|
63
|
-
puts "\n#{?= * 49}\n Faml Source: #{file}\n#{?= * 49}"
|
64
|
-
puts Faml::Engine.new.call(haml)
|
65
59
|
puts "\n#{?= * 49}\n Hamlit Source: #{file}\n#{?= * 49}"
|
66
60
|
puts Hamlit::Engine.new.call(haml)
|
67
61
|
end
|
data/lib/hamlit/engine.rb
CHANGED
@@ -7,7 +7,11 @@ module Hamlit
|
|
7
7
|
def self.render(name, source, indent_width: 0)
|
8
8
|
text = ::Tilt["t.#{name}"].new { source }.render
|
9
9
|
return text if indent_width == 0
|
10
|
-
text.
|
10
|
+
if text.frozen?
|
11
|
+
text.gsub(/^/, ' ' * indent_width)
|
12
|
+
else
|
13
|
+
text.gsub!(/^/, ' ' * indent_width)
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
def explicit_require?(needed_registration)
|
data/lib/hamlit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08
|
11
|
+
date: 2022-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: temple
|
@@ -346,7 +346,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
346
346
|
- !ruby/object:Gem::Version
|
347
347
|
version: '0'
|
348
348
|
requirements: []
|
349
|
-
rubygems_version: 3.
|
349
|
+
rubygems_version: 3.3.7
|
350
350
|
signing_key:
|
351
351
|
specification_version: 4
|
352
352
|
summary: High Performance Haml Implementation
|