hamlit 2.10.0 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +17 -11
- data/CHANGELOG.md +45 -1
- data/Gemfile +1 -7
- data/LICENSE.txt +26 -23
- data/REFERENCE.md +13 -4
- data/bin/bench +2 -2
- data/bin/update-haml +125 -0
- data/ext/hamlit/hamlit.c +0 -1
- data/lib/hamlit/attribute_builder.rb +2 -2
- data/lib/hamlit/attribute_compiler.rb +3 -3
- data/lib/hamlit/compiler/children_compiler.rb +18 -4
- data/lib/hamlit/compiler/comment_compiler.rb +8 -5
- data/lib/hamlit/filters/escaped.rb +1 -1
- data/lib/hamlit/filters/markdown.rb +1 -0
- data/lib/hamlit/filters/preserve.rb +1 -1
- data/lib/hamlit/filters/text_base.rb +1 -1
- data/lib/hamlit/filters/tilt_base.rb +1 -1
- data/lib/hamlit/html.rb +8 -0
- data/lib/hamlit/parser.rb +6 -2
- data/lib/hamlit/parser/haml_attribute_builder.rb +164 -0
- data/lib/hamlit/parser/haml_buffer.rb +20 -130
- data/lib/hamlit/parser/haml_compiler.rb +1 -553
- data/lib/hamlit/parser/haml_error.rb +29 -25
- data/lib/hamlit/parser/haml_escapable.rb +1 -0
- data/lib/hamlit/parser/haml_generator.rb +1 -0
- data/lib/hamlit/parser/haml_helpers.rb +41 -59
- data/lib/hamlit/parser/{haml_xss_mods.rb → haml_helpers/xss_mods.rb} +20 -15
- data/lib/hamlit/parser/haml_options.rb +53 -66
- data/lib/hamlit/parser/haml_parser.rb +103 -71
- data/lib/hamlit/parser/haml_temple_engine.rb +123 -0
- data/lib/hamlit/parser/haml_util.rb +10 -40
- data/lib/hamlit/rails_template.rb +1 -1
- data/lib/hamlit/string_splitter.rb +1 -0
- data/lib/hamlit/template.rb +1 -1
- data/lib/hamlit/temple_line_counter.rb +31 -0
- data/lib/hamlit/version.rb +1 -1
- metadata +10 -6
- data/lib/hamlit/parser/MIT-LICENSE +0 -20
- data/lib/hamlit/parser/README.md +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b080bac2aef1f473d967c016e0610d319cd43b89fbaea3a113949ed6dacfd04
|
4
|
+
data.tar.gz: be1115f4778772e95102c2ab995abd7ff7f3f6c9e86ab8eefac26a38b1a20bd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b5a640a456b34d551d4e65df868d59c027f4566ff357643f2b42458417356599f6d2cb3a9413ff17e431c69d782f2b9e5a603de147e1a6947f646910d8c3bf4
|
7
|
+
data.tar.gz: d13cb779bc02e9914f754054a7b8ab6b2ff6721259b15c87638fbbb2b6a528323b407e22ce4fcdd0a1e91ab1c7f05c5cd7d26e19b96016efaf91b1a188ac6579
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -4,36 +4,42 @@ branches:
|
|
4
4
|
only:
|
5
5
|
- master
|
6
6
|
script:
|
7
|
-
-
|
7
|
+
- bundle exec rake $TASK
|
8
|
+
env:
|
9
|
+
- RUBYOPT='-w'
|
8
10
|
matrix:
|
9
11
|
include:
|
10
12
|
- rvm: 2.3.8
|
11
13
|
env: TASK=test
|
12
|
-
- rvm: 2.4.
|
14
|
+
- rvm: 2.4.9
|
13
15
|
env: TASK=test
|
14
|
-
- rvm: 2.5.
|
16
|
+
- rvm: 2.5.7
|
15
17
|
env: TASK=test
|
16
|
-
- rvm: 2.6.
|
18
|
+
- rvm: 2.6.5
|
17
19
|
env: TASK=test
|
20
|
+
- rvm: 2.7.0
|
21
|
+
env: TASK=test
|
22
|
+
- rvm: 2.7.0
|
23
|
+
env: TASK=test RUBYOPT='-w --enable-frozen-string-literal'
|
18
24
|
- rvm: ruby-head
|
19
25
|
env: TASK=test
|
20
26
|
- rvm: jruby-9.2.8.0
|
21
27
|
env: TASK=test
|
22
28
|
- rvm: truffleruby
|
23
29
|
env: TASK=test
|
24
|
-
- rvm: 2.
|
30
|
+
- rvm: 2.7.0
|
25
31
|
env: TASK=bench TEMPLATE=benchmark/boolean_attribute.haml,benchmark/class_attribute.haml,benchmark/id_attribute.haml,benchmark/data_attribute.haml,benchmark/common_attribute.haml
|
26
|
-
- rvm: 2.
|
32
|
+
- rvm: 2.7.0
|
27
33
|
env: TASK=bench 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
|
28
|
-
- rvm: 2.
|
34
|
+
- rvm: 2.7.0
|
29
35
|
env: TASK=bench SLIM_BENCH=1
|
30
|
-
- rvm: 2.
|
36
|
+
- rvm: 2.7.0
|
31
37
|
env: TASK=bench TEMPLATE=benchmark/etc/attribute_builder.haml
|
32
|
-
- rvm: 2.
|
38
|
+
- rvm: 2.7.0
|
33
39
|
env: TASK=bench TEMPLATE=benchmark/etc/static_analyzer.haml
|
34
|
-
- rvm: 2.
|
40
|
+
- rvm: 2.7.0
|
35
41
|
env: TASK=bench TEMPLATE=benchmark/etc/string_interpolation.haml
|
36
|
-
- rvm: 2.
|
42
|
+
- rvm: 2.7.0
|
37
43
|
env: TASK=bench TEMPLATE=test/haml/templates/standard.haml COMPILE=1
|
38
44
|
allow_failures:
|
39
45
|
- rvm: ruby-head
|
data/CHANGELOG.md
CHANGED
@@ -4,12 +4,56 @@ 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
|
+
## [2.13.0](https://github.com/k0kubun/hamlit/compare/v2.12.0...v2.13.0) - 2020-10-2
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Support `--enable-frozen-string-literal` [#162](https://github.com/k0kubun/hamlit/issues/162).
|
12
|
+
*Thanks to @aliismayilov*
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- Upgrade the Haml parser from Haml 4.0 to 5.2 [#163](https://github.com/k0kubun/hamlit/issues/163).
|
17
|
+
- Allow `@` as tag's class name.
|
18
|
+
- Fix NameError on an `InvalidAttributeNameError` reference introduced at Hamlit v2.12.0.
|
19
|
+
|
20
|
+
## [2.12.0](https://github.com/k0kubun/hamlit/compare/v2.11.1...v2.12.0) - 2020-09-30
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- Class names are no longer ordered alphabetically.
|
25
|
+
*Thanks to @aliismayilov*
|
26
|
+
- This is compatible with [Haml 5.2](https://github.com/haml/haml/blob/v5.2.0/CHANGELOG.md#52)
|
27
|
+
|
28
|
+
## [2.11.1](https://github.com/k0kubun/hamlit/compare/v2.11.0...v2.11.1) - 2020-08-25
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
|
32
|
+
- Fix a line number on an error after filters like preserve, plain, and ruby.
|
33
|
+
*Thanks to @rgisiger*
|
34
|
+
|
35
|
+
## [2.11.0](https://github.com/k0kubun/hamlit/compare/v2.10.1...v2.11.0) - 2019-12-12
|
36
|
+
|
37
|
+
### Added
|
38
|
+
|
39
|
+
- Support Haml's _revealed_ conditional comment feature on `/![if !IE]` [#153](https://github.com/k0kubun/hamlit/issues/153).
|
40
|
+
*Thanks to @esb*
|
41
|
+
|
42
|
+
## [2.10.1](https://github.com/k0kubun/hamlit/compare/v2.10.0...v2.10.1) - 2019-11-28
|
43
|
+
|
44
|
+
### Added
|
45
|
+
|
46
|
+
- Register `Hamlit::Template` to Tilt as :hamlit as well, in addition to :haml
|
47
|
+
|
7
48
|
## [2.10.0](https://github.com/k0kubun/hamlit/compare/v2.9.5...v2.10.0) - 2019-09-15
|
8
49
|
|
9
50
|
### Added
|
10
51
|
|
11
|
-
- Optimize template rendering by
|
52
|
+
- Optimize template rendering by string interpolation [#146](https://github.com/k0kubun/hamlit/issues/146)
|
12
53
|
- Exploiting pre-allocation of string interpolation introduced in Ruby 2.5 [ruby/ruby#1626](https://github.com/ruby/ruby/pull/1626)
|
54
|
+
|
55
|
+
### Changed
|
56
|
+
|
13
57
|
- Require temple.gem >= 0.8.2
|
14
58
|
|
15
59
|
## [2.9.5](https://github.com/k0kubun/hamlit/compare/v2.9.4...v2.9.5) - 2019-09-08
|
data/Gemfile
CHANGED
@@ -8,10 +8,6 @@ end
|
|
8
8
|
# Specify your gem's dependencies in hamlit.gemspec
|
9
9
|
gemspec
|
10
10
|
|
11
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
|
12
|
-
gem 'rack', '< 2'
|
13
|
-
end
|
14
|
-
|
15
11
|
gem 'benchmark-ips', '2.3.0'
|
16
12
|
gem 'maxitest'
|
17
13
|
gem 'pry'
|
@@ -22,9 +18,7 @@ else
|
|
22
18
|
gem 'redcarpet'
|
23
19
|
|
24
20
|
if RUBY_PLATFORM !~ /mswin|mingw/ && RUBY_ENGINE != 'truffleruby'
|
25
|
-
|
26
|
-
gem 'faml'
|
27
|
-
end
|
21
|
+
gem 'faml'
|
28
22
|
gem 'stackprof'
|
29
23
|
end
|
30
24
|
end
|
data/LICENSE.txt
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
Copyright (c) 2006-2019 Hampton Catlin and Natalie Weizenbaum
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
21
|
+
|
22
|
+
===
|
23
|
+
|
24
|
+
The above license is applied to lib/hamlit/parser/*.rb and test/haml/*.
|
25
|
+
Everything else is licensed under:
|
26
|
+
|
1
27
|
The MIT License (MIT)
|
2
28
|
|
3
29
|
Copyright (c) 2015 Takashi Kokubun
|
@@ -19,26 +45,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
45
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
46
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
47
|
THE SOFTWARE.
|
22
|
-
|
23
|
-
lib/hamlit/parser/*.rb and test/haml/* are:
|
24
|
-
|
25
|
-
Copyright (c) 2006-2009 Hampton Catlin and Natalie Weizenbaum
|
26
|
-
|
27
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
28
|
-
a copy of this software and associated documentation files (the
|
29
|
-
"Software"), to deal in the Software without restriction, including
|
30
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
31
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
32
|
-
permit persons to whom the Software is furnished to do so, subject to
|
33
|
-
the following conditions:
|
34
|
-
|
35
|
-
The above copyright notice and this permission notice shall be
|
36
|
-
included in all copies or substantial portions of the Software.
|
37
|
-
|
38
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
39
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
40
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
41
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
42
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
43
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
44
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/REFERENCE.md
CHANGED
@@ -57,6 +57,7 @@ for full features in original implementation.
|
|
57
57
|
- [x] :plain
|
58
58
|
- [x] :preserve
|
59
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.
|
60
61
|
- [x] :sass
|
61
62
|
- [x] :scss
|
62
63
|
- [ ] :textile
|
@@ -121,10 +122,10 @@ and merging multiple ids results in concatenation by "\_".
|
|
121
122
|
%div{ id: false }
|
122
123
|
|
123
124
|
# Output
|
124
|
-
<div id='foo_bar'></
|
125
|
-
<div id='foo_bar'></
|
126
|
-
<div id='foo_bar'></
|
127
|
-
<div id=''></
|
125
|
+
<div id='foo_bar'></div>
|
126
|
+
<div id='foo_bar'></div>
|
127
|
+
<div id='foo_bar'></div>
|
128
|
+
<div id=''></div>
|
128
129
|
```
|
129
130
|
|
130
131
|
### class attribute
|
@@ -224,6 +225,14 @@ Hamlit::RailsTemplate.set_options attr_quote: '"'
|
|
224
225
|
set :haml, { attr_quote: '"' }
|
225
226
|
```
|
226
227
|
|
228
|
+
## Ruby module
|
229
|
+
|
230
|
+
`Hamlit::Template` is a module registered to `Tilt`. You can use it like:
|
231
|
+
|
232
|
+
```rb
|
233
|
+
Hamlit::Template.new { "%strong Yay for HAML!" }.render
|
234
|
+
```
|
235
|
+
|
227
236
|
## Creating a custom filter
|
228
237
|
|
229
238
|
Currently it doesn't have filter registering interface compatible with Haml.
|
data/bin/bench
CHANGED
@@ -43,7 +43,7 @@ class Bench < Thor
|
|
43
43
|
object.instance_eval(File.read(ruby_file))
|
44
44
|
end
|
45
45
|
|
46
|
-
Haml::Engine.new(haml, escape_html: true, escape_attrs: true
|
46
|
+
Haml::Engine.new(haml, escape_html: true, escape_attrs: true).def_method(object, :haml)
|
47
47
|
object.instance_eval "def faml; #{Faml::Engine.new.call(haml)}; end"
|
48
48
|
object.instance_eval "def hamlit; #{Hamlit::Engine.new.call(haml)}; end"
|
49
49
|
|
@@ -59,7 +59,7 @@ class Bench < Thor
|
|
59
59
|
def code(file)
|
60
60
|
haml = File.read(file)
|
61
61
|
puts "#{?= * 49}\n Haml Source: #{file}\n#{?= * 49}"
|
62
|
-
puts Haml::Engine.new(haml, escape_html: true, escape_attrs: true
|
62
|
+
puts Haml::Engine.new(haml, escape_html: true, escape_attrs: true).precompiled
|
63
63
|
puts "\n#{?= * 49}\n Faml Source: #{file}\n#{?= * 49}"
|
64
64
|
puts Faml::Engine.new.call(haml)
|
65
65
|
puts "\n#{?= * 49}\n Hamlit Source: #{file}\n#{?= * 49}"
|
data/bin/update-haml
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
HAML_REPO = 'haml/haml'
|
6
|
+
HAML_VERSION = 'v5.2.0'
|
7
|
+
|
8
|
+
module GitHubFetcher
|
9
|
+
def self.fetch(repo, tag:, path:)
|
10
|
+
Dir.mktmpdir do |dir|
|
11
|
+
Dir.chdir(dir) do
|
12
|
+
url = "https://github.com/#{repo}/archive/#{tag}.tar.gz"
|
13
|
+
system("curl -L --fail --retry 3 --retry-delay 1 #{url} -o - | tar zxf -")
|
14
|
+
FileUtils.mv("#{File.basename(repo)}-#{tag.sub(/\Av/, '')}", path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class LicenseBuilder
|
21
|
+
DELIMITER = "\n==="
|
22
|
+
|
23
|
+
def initialize(haml_license:, hamlit_license:)
|
24
|
+
@haml_license = haml_license
|
25
|
+
@hamlit_license = hamlit_license
|
26
|
+
end
|
27
|
+
|
28
|
+
def build
|
29
|
+
license = [
|
30
|
+
File.read(@haml_license),
|
31
|
+
File.read(@hamlit_license).split(DELIMITER, 2).last,
|
32
|
+
].join(DELIMITER)
|
33
|
+
File.write(@hamlit_license, license)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generate lib/hamlit/parser from haml
|
38
|
+
class HamlitParserBuilder
|
39
|
+
TARGET_FILES = [
|
40
|
+
'attribute_builder.rb',
|
41
|
+
'buffer.rb',
|
42
|
+
'error.rb',
|
43
|
+
'helpers.rb',
|
44
|
+
'options.rb',
|
45
|
+
'temple_engine.rb',
|
46
|
+
# TODO: make the upstream sharable first
|
47
|
+
# 'parser.rb',
|
48
|
+
'util.rb',
|
49
|
+
'helpers/xss_mods.rb',
|
50
|
+
]
|
51
|
+
|
52
|
+
# Classes which are just referenced by Options and not really used by the parser
|
53
|
+
DUMMY_CLASSES = {
|
54
|
+
'compiler.rb' => 'Compiler',
|
55
|
+
'escapable.rb' => 'Escapable',
|
56
|
+
'generator.rb' => 'Generator',
|
57
|
+
}
|
58
|
+
|
59
|
+
def initialize(haml:, hamlit_parser:)
|
60
|
+
@haml = haml
|
61
|
+
@hamlit_parser = hamlit_parser
|
62
|
+
end
|
63
|
+
|
64
|
+
def build
|
65
|
+
TARGET_FILES.each do |file|
|
66
|
+
src_path = File.join(@haml, file)
|
67
|
+
dest_path = File.join(@hamlit_parser, "haml_#{file}")
|
68
|
+
|
69
|
+
FileUtils.mkdir_p(File.dirname(dest_path))
|
70
|
+
FileUtils.cp(src_path, dest_path)
|
71
|
+
|
72
|
+
src = File.read(dest_path)
|
73
|
+
patch_source!(src, file: file)
|
74
|
+
File.write(dest_path, src)
|
75
|
+
end
|
76
|
+
|
77
|
+
DUMMY_CLASSES.each do |file, klass|
|
78
|
+
dest_path = File.join(@hamlit_parser, "haml_#{file}")
|
79
|
+
src = "class Hamlit::Haml#{klass}; end"
|
80
|
+
File.write(dest_path, src)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def patch_source!(src, file:)
|
87
|
+
# Use Hamlit::HamlFoo instead of Haml::Foo
|
88
|
+
src.gsub!(/^module Haml\n((?: #[^\n]+\n)*) (module|class) ([^ ]+)/, "module Hamlit\n\\1 \\2 Haml\\3")
|
89
|
+
src.gsub!(/\bHaml::/, 'Hamlit::Haml')
|
90
|
+
|
91
|
+
# Prefix Haml to references without Haml::
|
92
|
+
src.gsub!(/\b(AttributeBuilder|Error|InvalidAttributeNameError|Options|Parser|SyntaxError)\./, 'Haml\0')
|
93
|
+
src.gsub!(/\brescue SyntaxError /, 'rescue HamlSyntaxError ')
|
94
|
+
|
95
|
+
# Hamlit should not rely on Haml
|
96
|
+
src.gsub!(/^require 'haml\/([^']+)'/, "require 'hamlit/parser/haml_\\1'")
|
97
|
+
|
98
|
+
case file
|
99
|
+
when 'error.rb'
|
100
|
+
src.gsub!(/^ class ([^ ]+) < ([^ ]+);/, ' class Haml\1 < Haml\2;')
|
101
|
+
when 'helpers.rb'
|
102
|
+
src.gsub!(/^ def is_haml\?\n false\n end/m) { |str| str.gsub(/^ /, ' # ') } # not needed for the parser
|
103
|
+
when 'options.rb'
|
104
|
+
src.gsub!(/\.is_a\?\(Options\)/, '.is_a?(HamlOptions)')
|
105
|
+
when 'temple_engine.rb'
|
106
|
+
src.gsub!(/\buse (Generator|Escapable)$/, 'use Haml\1')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
FileUtils.rm_rf(haml = File.expand_path('../haml', __dir__))
|
112
|
+
GitHubFetcher.fetch(HAML_REPO, tag: HAML_VERSION, path: haml)
|
113
|
+
|
114
|
+
hamlit = File.expand_path('..', __dir__)
|
115
|
+
LicenseBuilder.new(
|
116
|
+
haml_license: File.join(haml, 'MIT-LICENSE'),
|
117
|
+
hamlit_license: File.join(hamlit, 'LICENSE.txt'),
|
118
|
+
).build
|
119
|
+
|
120
|
+
hamlit_parser = File.join(hamlit, 'lib/hamlit/parser')
|
121
|
+
# TODO: FileUtils.rm_rf(hamlit_parser = File.join(hamlit, 'lib/hamlit/parser'))
|
122
|
+
HamlitParserBuilder.new(
|
123
|
+
haml: File.join(haml, 'lib/haml'),
|
124
|
+
hamlit_parser: hamlit_parser,
|
125
|
+
).build
|
data/ext/hamlit/hamlit.c
CHANGED
@@ -47,7 +47,7 @@ module Hamlit::AttributeBuilder
|
|
47
47
|
when value.is_a?(String)
|
48
48
|
# noop
|
49
49
|
when value.is_a?(Array)
|
50
|
-
value = value.flatten.select { |v| v }.map(&:to_s).
|
50
|
+
value = value.flatten.select { |v| v }.map(&:to_s).uniq.join(' ')
|
51
51
|
when value
|
52
52
|
value = value.to_s
|
53
53
|
else
|
@@ -67,7 +67,7 @@ module Hamlit::AttributeBuilder
|
|
67
67
|
classes << value.to_s
|
68
68
|
end
|
69
69
|
end
|
70
|
-
escape_html(escape_attrs, classes.map(&:to_s).
|
70
|
+
escape_html(escape_attrs, classes.map(&:to_s).uniq.join(' '))
|
71
71
|
end
|
72
72
|
|
73
73
|
def build_data(escape_attrs, quote, *hashes)
|
@@ -17,7 +17,7 @@ module Hamlit
|
|
17
17
|
if node.value[:object_ref] != :nil || !Ripper.respond_to?(:lex) # No Ripper.lex in truffleruby
|
18
18
|
return runtime_compile(node)
|
19
19
|
end
|
20
|
-
node.value[:
|
20
|
+
[node.value[:dynamic_attributes].new, node.value[:dynamic_attributes].old].compact.each do |attribute_str|
|
21
21
|
hash = AttributeParser.parse(attribute_str)
|
22
22
|
return runtime_compile(node) unless hash
|
23
23
|
hashes << hash
|
@@ -28,11 +28,11 @@ module Hamlit
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def runtime_compile(node)
|
31
|
-
attrs =
|
31
|
+
attrs = []
|
32
32
|
attrs.unshift(node.value[:attributes].inspect) if node.value[:attributes] != {}
|
33
33
|
|
34
34
|
args = [@escape_attrs.inspect, "#{@quote.inspect}.freeze", @format.inspect].push(node.value[:object_ref]) + attrs
|
35
|
-
[:html, :attrs, [:dynamic, "::Hamlit::AttributeBuilder.build(#{args.join(', ')})"]]
|
35
|
+
[:html, :attrs, [:dynamic, "::Hamlit::AttributeBuilder.build(#{args.join(', ')}, #{node.value[:dynamic_attributes].to_literal})"]]
|
36
36
|
end
|
37
37
|
|
38
38
|
def static_compile(static_hash, dynamic_hashes)
|
@@ -1,4 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'hamlit/temple_line_counter'
|
3
|
+
|
2
4
|
module Hamlit
|
3
5
|
class Compiler
|
4
6
|
class ChildrenCompiler
|
@@ -14,7 +16,7 @@ module Hamlit
|
|
14
16
|
node.children.each do |n|
|
15
17
|
rstrip_whitespace!(temple) if nuke_prev_whitespace?(n)
|
16
18
|
insert_newlines!(temple, n)
|
17
|
-
temple <<
|
19
|
+
temple << moving_lineno(n) { block.call(n) }
|
18
20
|
temple << :whitespace if insert_whitespace?(n)
|
19
21
|
end
|
20
22
|
rstrip_whitespace!(temple) if nuke_inner_whitespace?(node)
|
@@ -27,19 +29,31 @@ module Hamlit
|
|
27
29
|
(node.line - @lineno).times do
|
28
30
|
temple << [:newline]
|
29
31
|
end
|
32
|
+
|
30
33
|
@lineno = node.line
|
34
|
+
end
|
31
35
|
|
36
|
+
def moving_lineno(node, &block)
|
37
|
+
# before: As they may have children, we need to increment lineno before compilation.
|
32
38
|
case node.type
|
33
39
|
when :script, :silent_script
|
34
40
|
@lineno += 1
|
35
|
-
when :filter
|
36
|
-
@lineno += (node.value[:text] || '').split("\n").size
|
37
41
|
when :tag
|
38
|
-
node.value[:
|
42
|
+
[node.value[:dynamic_attributes].new, node.value[:dynamic_attributes].old].compact.each do |attribute_hash|
|
39
43
|
@lineno += attribute_hash.count("\n")
|
40
44
|
end
|
41
45
|
@lineno += 1 if node.children.empty? && node.value[:parse]
|
42
46
|
end
|
47
|
+
|
48
|
+
temple = block.call # compile
|
49
|
+
|
50
|
+
# after: filter may not have children, and for some dynamic filters we can't predict the number of lines.
|
51
|
+
case node.type
|
52
|
+
when :filter
|
53
|
+
@lineno += TempleLineCounter.count_lines(temple)
|
54
|
+
end
|
55
|
+
|
56
|
+
temple
|
43
57
|
end
|
44
58
|
|
45
59
|
def confirm_whitespace(temple)
|