slimi 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +8 -0
- data/README.md +1 -0
- data/lib/slimi/filters/interpolation.rb +28 -7
- data/lib/slimi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7aed4b0083f7ec850df87f869b5687873dcf98fd6f80ab93854c101e0d03098
|
4
|
+
data.tar.gz: bfa813fce529081b2eb876e00a9b722feecf914a5741c9ca341ec2aa8d1463ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcd9e3abde25cca87e45eb7244658ed6a99d56e458d2b0b3e1199252eb5621480fb7afc12f6246f3760e13a07a2efaabd80f45e5deb868212228cbf96b582a01
|
7
|
+
data.tar.gz: 9fd6030053873163c81f12646461cb502a4d3632e9de4bd8ec77081546081e50fd7e088ad93f23b15666d54007ca1b298f44dd63eeb74b2f5778e716e5e3d6fc
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Slimi
|
2
2
|
|
3
3
|
[![test](https://github.com/r7kamura/slimi/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/slimi/actions/workflows/test.yml)
|
4
|
+
[![](https://badge.fury.io/rb/slimi.svg)](https://rubygems.org/gems/slimi)
|
4
5
|
|
5
6
|
Yet another implementation for [Slim](https://github.com/slim-template/slim) template language.
|
6
7
|
|
@@ -1,34 +1,55 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'strscan'
|
4
|
-
require 'temple'
|
5
4
|
|
6
5
|
module Slimi
|
7
6
|
module Filters
|
8
|
-
class Interpolation
|
7
|
+
class Interpolation
|
8
|
+
def initialize(*); end
|
9
|
+
|
10
|
+
def call(node)
|
11
|
+
convert(node)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def convert(value)
|
17
|
+
if value.instance_of?(::Array)
|
18
|
+
if value[0] == :slimi && value[1] == :interpolate
|
19
|
+
on_slimi_interpolate(value[2], value[3], value[4])
|
20
|
+
else
|
21
|
+
value.map do |element|
|
22
|
+
call(element)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
else
|
26
|
+
value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
9
30
|
# @param [Integer] begin_
|
10
31
|
# @param [Integer] end_
|
11
32
|
# @return [Array] S-expression.
|
12
|
-
def on_slimi_interpolate(begin_,
|
33
|
+
def on_slimi_interpolate(begin_, _end_, string)
|
13
34
|
block = [:multi]
|
14
35
|
scanner = ::StringScanner.new(string)
|
15
36
|
until scanner.eos?
|
16
37
|
charpos = scanner.charpos
|
17
|
-
if (value = scanner.scan(/\\#\{/)
|
38
|
+
if (value = scanner.scan(/\\#\{/))
|
18
39
|
block << [:static, value]
|
19
40
|
elsif scanner.scan(/#\{((?>[^{}]|(\{(?>[^{}]|\g<1>)*\}))*)\}/)
|
20
41
|
code = scanner[1]
|
21
42
|
begin2 = begin_ + charpos + 2
|
22
|
-
end2 = end_ + scanner.charpos - 1
|
23
43
|
if code.start_with?('{') && code.end_with?('}')
|
24
44
|
escape = true
|
25
45
|
code = code[1..-2]
|
26
46
|
begin2 -= 1
|
27
|
-
end2 -= 1
|
28
47
|
else
|
29
48
|
escape = false
|
30
49
|
end
|
31
|
-
block << [:slimi, :position, begin2,
|
50
|
+
block << [:slimi, :position, begin2, begin2 + code.length, [:slim, :output, escape, code, [:multi]]]
|
51
|
+
elsif (value = scanner.scan(/([#\\]?[^#\\]*([#\\][^\\\#{][^#\\]*)*)/)) # rubocop:disable Lint/DuplicateBranch
|
52
|
+
block << [:static, value]
|
32
53
|
end
|
33
54
|
end
|
34
55
|
block
|
data/lib/slimi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slimi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: temple
|