hamli 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/hamli/filters/base.rb +25 -0
- data/lib/hamli/filters/interpolation.rb +37 -0
- data/lib/hamli/filters.rb +8 -0
- data/lib/hamli/parser.rb +2 -2
- data/lib/hamli/version.rb +1 -1
- data/lib/hamli.rb +1 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8051356e999f363969f3ccd7c937b17e70ea6e58c283e5836e5ccc0f3163e2a
|
4
|
+
data.tar.gz: 6d08f7c25aa75ebd8fc5e64e009533bf02154521329e2de01789eee469462e86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4c6d223febbf5aec1aaccaa30ef9599aebf32903a8de3afe9fe62ffd8b1b928bfb5eef519551952c6a41d43c0be8b325af4436ad95d69a429949950772cf454
|
7
|
+
data.tar.gz: a78ba804bc6b81fce03df6a85ea885ec809dba8f4c09ea5aed0d80007941149798dda64037ca3f68dbb3ea6d339fe362706ddfb530ada457b53a98a0a14dd6b5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Hamli
|
2
2
|
|
3
3
|
[![test](https://github.com/r7kamura/hamli/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/hamli/actions/workflows/test.yml)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/hamli.svg)](https://rubygems.org/gems/hamli)
|
4
5
|
|
5
6
|
Yet another implementation for [Haml](https://github.com/haml/haml) template language.
|
6
7
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'temple'
|
4
|
+
|
5
|
+
module Hamli
|
6
|
+
module Filters
|
7
|
+
# Pass-through some expressions which are unknown for Temple.
|
8
|
+
class Base < ::Temple::HTML::Filter
|
9
|
+
# @param [Integer] begin_
|
10
|
+
# @param [Integer] end_
|
11
|
+
# @param [Array] expression
|
12
|
+
# @return [Array]
|
13
|
+
def on_hamli_position(begin_, end_, expression)
|
14
|
+
[:hamli, :position, begin_, end_, compile(expression)]
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [String] type
|
18
|
+
# @param [Array] expression
|
19
|
+
# @return [Array]
|
20
|
+
def on_hamli_text(type, expression)
|
21
|
+
[:hamli, :text, type, compile(expression)]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'strscan'
|
4
|
+
|
5
|
+
module Hamli
|
6
|
+
module Filters
|
7
|
+
class Interpolation < Base
|
8
|
+
# @param [Integer] begin_
|
9
|
+
# @param [Integer] end_
|
10
|
+
# @return [Array] S-expression.
|
11
|
+
def on_hamli_interpolate(begin_, _end_, string)
|
12
|
+
block = [:multi]
|
13
|
+
scanner = ::StringScanner.new(string)
|
14
|
+
until scanner.eos?
|
15
|
+
charpos = scanner.charpos
|
16
|
+
if (value = scanner.scan(/\\#\{/))
|
17
|
+
block << [:static, value]
|
18
|
+
elsif scanner.scan(/#\{((?>[^{}]|(\{(?>[^{}]|\g<1>)*\}))*)\}/)
|
19
|
+
code = scanner[1]
|
20
|
+
begin2 = begin_ + charpos + 2
|
21
|
+
if code.start_with?('{') && code.end_with?('}')
|
22
|
+
escape = true
|
23
|
+
code = code[1..-2]
|
24
|
+
begin2 -= 1
|
25
|
+
else
|
26
|
+
escape = false
|
27
|
+
end
|
28
|
+
block << [:hamli, :position, begin2, begin2 + code.length, [:hamli, :output, escape, code, [:multi]]]
|
29
|
+
elsif (value = scanner.scan(/([#\\]?[^#\\]*([#\\][^\\\#{][^#\\]*)*)/)) # rubocop:disable Lint/DuplicateBranch
|
30
|
+
block << [:static, value]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
block
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/hamli/parser.rb
CHANGED
@@ -274,7 +274,7 @@ module Hamli
|
|
274
274
|
)
|
275
275
|
/x
|
276
276
|
)
|
277
|
-
[:hamli, :object_reference, begin_, @scanner.charpos, value]
|
277
|
+
[:hamli, :object_reference, [:hamli, :position, begin_, @scanner.charpos, value]]
|
278
278
|
end
|
279
279
|
|
280
280
|
# Parse ruby attributes part.
|
@@ -292,7 +292,7 @@ module Hamli
|
|
292
292
|
)
|
293
293
|
/x
|
294
294
|
)
|
295
|
-
[:hamli, :ruby_attributes, begin_, @scanner.charpos, value]
|
295
|
+
[:hamli, :ruby_attributes, [:hamli, :position, begin_, @scanner.charpos, value]]
|
296
296
|
end
|
297
297
|
|
298
298
|
# Parse text block part.
|
data/lib/hamli/version.rb
CHANGED
data/lib/hamli.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -43,6 +43,9 @@ files:
|
|
43
43
|
- hamli.gemspec
|
44
44
|
- lib/hamli.rb
|
45
45
|
- lib/hamli/errors.rb
|
46
|
+
- lib/hamli/filters.rb
|
47
|
+
- lib/hamli/filters/base.rb
|
48
|
+
- lib/hamli/filters/interpolation.rb
|
46
49
|
- lib/hamli/parser.rb
|
47
50
|
- lib/hamli/range.rb
|
48
51
|
- lib/hamli/version.rb
|