hamlit 2.10.1-java → 2.13.2-java
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/workflows/test.yml +30 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +49 -0
- data/Gemfile +1 -7
- data/LICENSE.txt +26 -23
- data/README.md +8 -8
- data/REFERENCE.md +13 -4
- data/benchmark/graph/graph.key +0 -0
- data/benchmark/graph/graph.png +0 -0
- data/bin/update-haml +125 -0
- data/ext/hamlit/hamlit.c +0 -1
- data/hamlit.gemspec +1 -1
- data/lib/hamlit.rb +6 -4
- 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 +133 -73
- 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/temple_line_counter.rb +31 -0
- data/lib/hamlit/version.rb +1 -1
- metadata +32 -27
- data/.travis.yml +0 -47
- 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: 9c157cfa69dafaafe52824f77e7d8b42678ba3710dd09bbb5808a714cfda759a
|
4
|
+
data.tar.gz: 1e734a39a56edf5cd3898d9245506dd865e15734cc590c990c72350f20e48ae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ab77e54fe32548c307d1f1fef0356915be976313721ec70bd33877f5063f5a953c00b722b267af01668ea33c05daef9e07d8c7732936126ca1d06791c81161f
|
7
|
+
data.tar.gz: 57aea5e83ec4a34fd5bd41878b687f13e987c4a2d8a7bec1b7823d86755332f49084d20a61a88ecbdadd7278d9ef1517a871b1b8a338cad02f765bc4862f56d4
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: test
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
pull_request:
|
7
|
+
types:
|
8
|
+
- opened
|
9
|
+
- synchronize
|
10
|
+
- reopened
|
11
|
+
schedule:
|
12
|
+
- cron: "00 15 * * *" # 7:00 PST (-8), 8:00 PDT (-7)
|
13
|
+
jobs:
|
14
|
+
test:
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
container: ${{ matrix.ruby }}
|
17
|
+
strategy:
|
18
|
+
fail-fast: false
|
19
|
+
matrix:
|
20
|
+
ruby:
|
21
|
+
- ruby:2.5
|
22
|
+
- ruby:2.6
|
23
|
+
- ruby:2.7
|
24
|
+
# TODO: add jruby and truffleruby
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v2
|
27
|
+
- run: apt-get update && apt-get install -y nodejs # For execjs
|
28
|
+
- name: bundle install
|
29
|
+
run: bundle install -j$(nproc) --retry 3
|
30
|
+
- run: bundle exec rake test
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,55 @@ 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.2](https://github.com/k0kubun/hamlit/compare/v2.13.1...v2.13.2) - 2020-12-27
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Speed up `hamlit` commands [#166](https://github.com/k0kubun/hamlit/issues/166)
|
12
|
+
*Thanks to @knightq*
|
13
|
+
|
14
|
+
## [2.13.1](https://github.com/k0kubun/hamlit/compare/v2.13.0...v2.13.1) - 2020-12-27
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Support [multiline attributes](https://github.com/haml/haml/pull/1043) of Haml 5.2.1.
|
19
|
+
|
20
|
+
## [2.13.0](https://github.com/k0kubun/hamlit/compare/v2.12.0...v2.13.0) - 2020-10-02
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- Support `--enable-frozen-string-literal` [#162](https://github.com/k0kubun/hamlit/issues/162).
|
25
|
+
*Thanks to @aliismayilov*
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
|
29
|
+
- Upgrade the Haml parser from Haml 4.0 to 5.2 [#163](https://github.com/k0kubun/hamlit/issues/163).
|
30
|
+
- Allow `@` as tag's class name.
|
31
|
+
- Fix NameError on an `InvalidAttributeNameError` reference introduced at Hamlit v2.12.0.
|
32
|
+
- You can no longer specify `ugly` option, which has had no effect.
|
33
|
+
|
34
|
+
## [2.12.0](https://github.com/k0kubun/hamlit/compare/v2.11.1...v2.12.0) - 2020-09-30
|
35
|
+
|
36
|
+
### Changed
|
37
|
+
|
38
|
+
- Class names are no longer ordered alphabetically.
|
39
|
+
*Thanks to @aliismayilov*
|
40
|
+
- This is compatible with [Haml 5.2](https://github.com/haml/haml/blob/v5.2.0/CHANGELOG.md#52)
|
41
|
+
|
42
|
+
## [2.11.1](https://github.com/k0kubun/hamlit/compare/v2.11.0...v2.11.1) - 2020-08-25
|
43
|
+
|
44
|
+
### Fixed
|
45
|
+
|
46
|
+
- Fix a line number on an error after filters like preserve, plain, and ruby.
|
47
|
+
*Thanks to @rgisiger*
|
48
|
+
|
49
|
+
## [2.11.0](https://github.com/k0kubun/hamlit/compare/v2.10.1...v2.11.0) - 2019-12-12
|
50
|
+
|
51
|
+
### Added
|
52
|
+
|
53
|
+
- Support Haml's _revealed_ conditional comment feature on `/![if !IE]` [#153](https://github.com/k0kubun/hamlit/issues/153).
|
54
|
+
*Thanks to @esb*
|
55
|
+
|
7
56
|
## [2.10.1](https://github.com/k0kubun/hamlit/compare/v2.10.0...v2.10.1) - 2019-11-28
|
8
57
|
|
9
58
|
### Added
|
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/README.md
CHANGED
@@ -10,17 +10,17 @@ Hamlit is a high performance [Haml](https://github.com/haml/haml) implementation
|
|
10
10
|
### What is Hamlit?
|
11
11
|
Hamlit is another implementation of [Haml](https://github.com/haml/haml).
|
12
12
|
With some [limitations](REFERENCE.md#limitations) by design for performance,
|
13
|
-
Hamlit is **
|
14
|
-
which is an HTML-escaped version of [slim-template/slim's one](https://github.com/slim-template/slim/blob/
|
13
|
+
Hamlit is **1.94x times faster** than original haml gem in [this benchmark](benchmark/slim/run-benchmarks.rb),
|
14
|
+
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
15
|
|
16
|
-
<img src="https://
|
16
|
+
<img src="https://raw.githubusercontent.com/k0kubun/hamlit/afcc2b36c4861c2f764baa09afd9530ca25eeafa/benchmark/graph/graph.png" width="600x" alt="Hamlit Benchmark" />
|
17
17
|
|
18
18
|
```
|
19
|
-
|
20
|
-
erubi v1.
|
21
|
-
slim
|
22
|
-
faml v0.8.1:
|
23
|
-
haml v5.0
|
19
|
+
hamlit v2.13.0: 247404.4 i/s
|
20
|
+
erubi v1.9.0: 244356.4 i/s - 1.01x slower
|
21
|
+
slim v4.1.0: 238254.3 i/s - 1.04x slower
|
22
|
+
faml v0.8.1: 197293.2 i/s - 1.25x slower
|
23
|
+
haml v5.2.0: 127834.4 i/s - 1.94x slower
|
24
24
|
```
|
25
25
|
|
26
26
|
### Why is Hamlit faster?
|
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.
|
Binary file
|
Binary file
|
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 = '5.2.1'
|
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\n"
|
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
data/hamlit.gemspec
CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_development_dependency 'haml', '>= 5'
|
38
38
|
spec.add_development_dependency 'less'
|
39
39
|
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
|
40
|
-
spec.add_development_dependency 'rails', '>= 4.0
|
40
|
+
spec.add_development_dependency 'rails', '>= 4.0'
|
41
41
|
spec.add_development_dependency 'rake'
|
42
42
|
spec.add_development_dependency 'rake-compiler'
|
43
43
|
spec.add_development_dependency 'sass'
|
data/lib/hamlit.rb
CHANGED
@@ -4,8 +4,10 @@ require 'hamlit/error'
|
|
4
4
|
require 'hamlit/version'
|
5
5
|
require 'hamlit/template'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
if File.basename($0) != 'hamlit'
|
8
|
+
begin
|
9
|
+
require 'rails'
|
10
|
+
require 'hamlit/railtie'
|
11
|
+
rescue LoadError
|
12
|
+
end
|
11
13
|
end
|
@@ -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)
|