hamlit 0.4.2 → 0.4.3
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/.travis.yml +5 -5
- data/CHANGELOG.md +18 -9
- data/README.md +19 -13
- data/benchmarks/benchmark.rb +2 -1
- data/lib/hamlit/parsers/script.rb +17 -10
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/script_spec.rb +2 -0
- data/spec/hamlit/engine/silent_script_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1688e256cfeb017819cd1ea62ba2a083a9347224
|
4
|
+
data.tar.gz: 77978ed4df48aa09950e3462ea3e00914d1da7e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb9bdcb4facccdb71d92e5e80014797326ac2c1e118b61a137b203ec4f145ad4d2529a58a0450beb340f623909f035cdf824e91fed50e2708bac1ec582a22840
|
7
|
+
data.tar.gz: 3e1a31ea12ab7ab547e7b38516cf80b95f48a29ef3c7cf20d4a8c128eeb0dd1f5499cbd59cf4ff86e8df6bf453487b0f8fcd7a1d4d6efd54e1df3070d391a17a
|
data/.travis.yml
CHANGED
@@ -13,22 +13,22 @@ gemfile:
|
|
13
13
|
env:
|
14
14
|
- TASK=spec
|
15
15
|
- TASK=rails:spec
|
16
|
-
- TASK=bench TIME=
|
16
|
+
- TASK=bench TIME=20
|
17
17
|
matrix:
|
18
18
|
allow_failures:
|
19
|
-
- env: TASK=bench TIME=
|
19
|
+
- env: TASK=bench TIME=20
|
20
20
|
exclude:
|
21
21
|
- env: TASK=spec
|
22
22
|
gemfile: spec/rails/Gemfile
|
23
23
|
- env: TASK=rails:spec
|
24
24
|
gemfile: Gemfile
|
25
|
-
- env: TASK=bench TIME=
|
25
|
+
- env: TASK=bench TIME=20
|
26
26
|
gemfile: spec/rails/Gemfile
|
27
27
|
- rvm: 2.1
|
28
28
|
env: TASK=rails:spec
|
29
29
|
- rvm: 2.1
|
30
|
-
env: TASK=bench TIME=
|
30
|
+
env: TASK=bench TIME=20
|
31
31
|
- rvm: 2.0.0
|
32
32
|
env: TASK=rails:spec
|
33
33
|
- rvm: 2.0.0
|
34
|
-
env: TASK=bench TIME=
|
34
|
+
env: TASK=bench TIME=20
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## v0.4.3
|
2
|
+
|
3
|
+
- Allow empty else statement
|
4
|
+
- https://github.com/k0kubun/hamlit/issues/14
|
5
|
+
- Thanks to @jeffblake
|
6
|
+
- Accept comment-only script
|
7
|
+
- https://github.com/k0kubun/hamlit/issues/13
|
8
|
+
- Thanks to @jeffblake
|
9
|
+
|
1
10
|
## v0.4.2
|
2
11
|
|
3
12
|
- Bugfix about parsing nested attributes
|
@@ -18,41 +27,41 @@
|
|
18
27
|
|
19
28
|
## v0.3.4
|
20
29
|
|
21
|
-
- Allow tab indentation
|
30
|
+
- Allow tab indentation
|
22
31
|
- https://github.com/k0kubun/hamlit/issues/9
|
23
32
|
- Thanks to @tdtds
|
24
33
|
|
25
34
|
## v0.3.3
|
26
35
|
|
27
|
-
- Accept multi byte parsing
|
36
|
+
- Accept multi byte parsing
|
28
37
|
- https://github.com/k0kubun/hamlit/issues/8
|
29
38
|
- Thanks to @machu
|
30
39
|
|
31
40
|
## v0.3.2
|
32
41
|
|
33
|
-
- Bugfix for compiling old attributes
|
42
|
+
- Bugfix for compiling old attributes
|
34
43
|
- https://github.com/k0kubun/hamlit/issues/7
|
35
44
|
- Thanks to @creasty
|
36
45
|
|
37
46
|
## v0.3.1
|
38
47
|
|
39
|
-
- Hyphenate data attributes
|
48
|
+
- Hyphenate data attributes
|
40
49
|
- https://github.com/k0kubun/hamlit/issues/5
|
41
50
|
- Thanks to @os0x
|
42
51
|
|
43
52
|
## v0.3.0
|
44
53
|
|
45
|
-
- Specify a version in dependency of temple
|
54
|
+
- Specify a version in dependency of temple
|
46
55
|
|
47
56
|
## v0.2.0
|
48
57
|
|
49
|
-
- Allow comments in script
|
58
|
+
- Allow comments in script
|
50
59
|
- https://github.com/k0kubun/hamlit/issues/3
|
51
60
|
- Thanks to @eagletmt
|
52
61
|
|
53
62
|
## v0.1.3
|
54
63
|
|
55
|
-
- Bugfix for attribute nesting on runtime
|
64
|
+
- Bugfix for attribute nesting on runtime
|
56
65
|
- https://github.com/k0kubun/hamlit/issues/1
|
57
66
|
- Thanks to @eagletmt
|
58
67
|
|
@@ -64,10 +73,10 @@
|
|
64
73
|
|
65
74
|
## v0.1.1
|
66
75
|
|
67
|
-
- Drop obsolete `--ugly` option for CLI
|
76
|
+
- Drop obsolete `--ugly` option for CLI
|
68
77
|
- Currently pretty mode is not implemented.
|
69
78
|
|
70
79
|
## v0.1.0
|
71
80
|
|
72
|
-
- Initial release
|
81
|
+
- Initial release
|
73
82
|
- Passing haml-spec with ugly mode.
|
data/README.md
CHANGED
@@ -15,21 +15,22 @@ or just replace `gem "haml"` with `gem "hamlit"`.
|
|
15
15
|
## Features
|
16
16
|
### Fast rendering
|
17
17
|
|
18
|
-
Hamlit's rendering is **
|
19
|
-
|
20
|
-

|
18
|
+
Hamlit's rendering is **7.24x times faster** than original haml.
|
21
19
|
|
22
20
|
```
|
23
|
-
|
24
|
-
|
25
|
-
slim:
|
26
|
-
faml:
|
27
|
-
haml:
|
21
|
+
erubis: 114417.8 i/s
|
22
|
+
hamlit: 107367.5 i/s - 1.07x slower
|
23
|
+
slim: 104728.0 i/s - 1.09x slower
|
24
|
+
faml: 87624.2 i/s - 1.31x slower
|
25
|
+
haml: 15796.0 i/s - 7.24x slower
|
28
26
|
```
|
29
27
|
|
30
|
-
[This benchmark](https://github.com/k0kubun/hamlit/blob/
|
28
|
+
[This benchmark](https://github.com/k0kubun/hamlit/blob/b6f112aa1f51816ab9a3a81bd7810ed9cffd26aa/benchmarks/benchmark.rb)
|
31
29
|
is the same as [slim-template/slim](https://github.com/slim-template/slim)'s one for fairness.
|
32
|
-
([The result on travis CI](https://travis-ci.org/k0kubun/hamlit/jobs/
|
30
|
+
([The result on travis CI](https://travis-ci.org/k0kubun/hamlit/jobs/57333515))
|
31
|
+
|
32
|
+
Note that there are [some incompatibilities](https://github.com/k0kubun/hamlit/issues) related to performance.
|
33
|
+
You may want [faml](https://github.com/eagletmt/faml) for a better compatibility.
|
33
34
|
|
34
35
|
### Better parser
|
35
36
|
|
@@ -59,9 +60,7 @@ For compatibility with Haml, Hamlit does not escape html automatically in sinatr
|
|
59
60
|
You can enable html escaping manually:
|
60
61
|
|
61
62
|
```ruby
|
62
|
-
|
63
|
-
Hamlit::Engine.set_default_options(escape_html: true)
|
64
|
-
end
|
63
|
+
set :haml, { escape_html: true }
|
65
64
|
```
|
66
65
|
|
67
66
|
## Why high performance?
|
@@ -81,6 +80,13 @@ code by Hamlit is very fast.
|
|
81
80
|
Not only relying on temple optimizers, but also Hamlit's compiler cares about many cases
|
82
81
|
to optimize performance such as string interpolation.
|
83
82
|
|
83
|
+
## TODO
|
84
|
+
|
85
|
+
Currently there are some important incompatibilities that should be fixed.
|
86
|
+
|
87
|
+
- Remove falsy attributes [#2](https://github.com/k0kubun/hamlit/issues/2)
|
88
|
+
- Escape attribute values [#10](https://github.com/k0kubun/hamlit/issues/10)
|
89
|
+
|
84
90
|
## License
|
85
91
|
|
86
92
|
MIT License
|
data/benchmarks/benchmark.rb
CHANGED
@@ -34,6 +34,7 @@ class Benchmarks
|
|
34
34
|
fast_erubis = Erubis::FastEruby.new(@erb_code)
|
35
35
|
haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
|
36
36
|
tenjin = Tenjin::Engine.new.get_template(@rbhtml_path)
|
37
|
+
hamlit = Hamlit::Engine.new(escape_html: true)
|
37
38
|
|
38
39
|
context = Context.new
|
39
40
|
|
@@ -46,7 +47,7 @@ class Benchmarks
|
|
46
47
|
def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
|
47
48
|
def run_faml; #{Faml::Engine.new.call @haml_code}; end
|
48
49
|
def run_tenjin; _buf = ''; #{tenjin.script}; end
|
49
|
-
def run_hamlit; #{
|
50
|
+
def run_hamlit; #{hamlit.call @haml_code}; end
|
50
51
|
}
|
51
52
|
|
52
53
|
bench('hamlit', Hamlit::VERSION) { context.run_hamlit }
|
@@ -21,8 +21,8 @@ module Hamlit
|
|
21
21
|
assert_scan!(scanner, /=|&=|!=/)
|
22
22
|
options = DEFAULT_SCRIPT_OPTIONS.merge(options)
|
23
23
|
|
24
|
-
code = scan_code(scanner)
|
25
|
-
return syntax_error("There's no Ruby code for = to evaluate.") if code.empty?
|
24
|
+
code, with_comment = scan_code(scanner, comment_check: true)
|
25
|
+
return syntax_error("There's no Ruby code for = to evaluate.") if code.empty? && !with_comment
|
26
26
|
unless has_block?
|
27
27
|
return [:dynamic, code] if options[:disable_escape]
|
28
28
|
return escape_html([:dynamic, code], options[:force_escape])
|
@@ -48,11 +48,12 @@ module Hamlit
|
|
48
48
|
return [:multi]
|
49
49
|
end
|
50
50
|
|
51
|
-
ast = [:code]
|
52
|
-
|
53
|
-
|
51
|
+
ast = [:multi, [:code, scan_code(scanner)]]
|
52
|
+
unless has_block?
|
53
|
+
ast << [:code, 'end'] if @current_indent > next_indent
|
54
|
+
return ast
|
55
|
+
end
|
54
56
|
|
55
|
-
ast = [:multi, ast]
|
56
57
|
ast += with_indented { parse_lines }
|
57
58
|
ast << [:code, 'end'] unless same_indent?(next_line) && internal_statement?(next_line)
|
58
59
|
ast
|
@@ -60,7 +61,7 @@ module Hamlit
|
|
60
61
|
|
61
62
|
private
|
62
63
|
|
63
|
-
def scan_code(scanner)
|
64
|
+
def scan_code(scanner, comment_check: false)
|
64
65
|
code = ''
|
65
66
|
loop do
|
66
67
|
code += (scanner.scan(/.+/) || '').strip
|
@@ -70,15 +71,21 @@ module Hamlit
|
|
70
71
|
scanner = StringScanner.new(current_line)
|
71
72
|
code += ' '
|
72
73
|
end
|
73
|
-
remove_comment(code)
|
74
|
+
remove_comment(code, comment_check: comment_check)
|
74
75
|
end
|
75
76
|
|
76
|
-
def remove_comment(code)
|
77
|
+
def remove_comment(code, comment_check: false)
|
77
78
|
result = ''
|
79
|
+
with_comment = false
|
78
80
|
Ripper.lex(code).each do |(row, col), type, str|
|
79
|
-
|
81
|
+
if type == :on_comment
|
82
|
+
with_comment = true
|
83
|
+
next
|
84
|
+
end
|
80
85
|
result += str
|
81
86
|
end
|
87
|
+
|
88
|
+
return [result, with_comment] if comment_check
|
82
89
|
result
|
83
90
|
end
|
84
91
|
|
data/lib/hamlit/version.rb
CHANGED
@@ -67,6 +67,18 @@ describe Hamlit::Engine do
|
|
67
67
|
HTML
|
68
68
|
end
|
69
69
|
|
70
|
+
it 'renders empty else statement' do
|
71
|
+
assert_render(<<-'HAML', <<-HTML)
|
72
|
+
%span
|
73
|
+
- if false
|
74
|
+
ng
|
75
|
+
- else
|
76
|
+
HAML
|
77
|
+
<span>
|
78
|
+
</span>
|
79
|
+
HTML
|
80
|
+
end
|
81
|
+
|
70
82
|
it 'accept if inside if-else' do
|
71
83
|
assert_render(<<-'HAML', <<-HTML)
|
72
84
|
- if false
|
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: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: temple
|