slimi 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +33 -1
- data/README.md +1 -0
- data/lib/slimi/engine.rb +2 -0
- data/lib/slimi/filters/amble.rb +23 -0
- data/lib/slimi/filters/attribute.rb +3 -3
- data/lib/slimi/filters/base.rb +41 -0
- data/lib/slimi/filters/control.rb +3 -3
- data/lib/slimi/filters/do_inserter.rb +5 -5
- data/lib/slimi/filters/embedded.rb +15 -15
- data/lib/slimi/filters/end_inserter.rb +2 -2
- data/lib/slimi/filters/interpolation.rb +2 -24
- data/lib/slimi/filters/output.rb +3 -3
- data/lib/slimi/filters/text.rb +3 -3
- data/lib/slimi/filters/unposition.rb +7 -23
- data/lib/slimi/filters.rb +2 -0
- data/lib/slimi/parser.rb +8 -8
- data/lib/slimi/rails_template_handler.rb +68 -5
- data/lib/slimi/railtie.rb +1 -0
- data/lib/slimi/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12b1a25a767a9ca17da4d9d99cf520d857131cd9d28acaf73d18a7696354c694
|
4
|
+
data.tar.gz: fee58aeb65387fd4846e74ce6885bb96e97dca9db3f2f95578693e20752249a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d97004ce75686f701d0a27bb8ac200e56956d5556fe4dbc874e523870d4c0467ee6eba5d5a1d7e34fc6d792d6df17ec85df689a297e94be56d44dadd33902c66
|
7
|
+
data.tar.gz: d719cc21f5288051ae6e7be83cb1f85e82000dc0e7345160d0087f3d61d9aab9a17ce45978437ceefa6d47ce063034022170e2062fd5404ee4182f245edf0792
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 0.6.0 - 2022-01-03
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Support annotate_rendered_view_with_filenames.
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- Rename expression name from slim to slimi.
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
- Fix bug at registering handler to ActionView.
|
18
|
+
- Fix Engine options at RailsTemplateHandler.
|
19
|
+
- Define missing :generator option at Engine.
|
20
|
+
|
5
21
|
## 0.5.1 - 2022-01-02
|
6
22
|
|
7
23
|
### Changed
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,47 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
slimi (0.
|
4
|
+
slimi (0.6.0)
|
5
5
|
temple
|
6
6
|
tilt
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
actionview (7.0.0)
|
12
|
+
activesupport (= 7.0.0)
|
13
|
+
builder (~> 3.1)
|
14
|
+
erubi (~> 1.4)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
17
|
+
activesupport (7.0.0)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 1.6, < 2)
|
20
|
+
minitest (>= 5.1)
|
21
|
+
tzinfo (~> 2.0)
|
11
22
|
ast (2.4.2)
|
23
|
+
builder (3.2.4)
|
24
|
+
concurrent-ruby (1.1.9)
|
25
|
+
crass (1.0.6)
|
12
26
|
diff-lcs (1.4.4)
|
27
|
+
erubi (1.10.0)
|
28
|
+
i18n (1.8.11)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
loofah (2.13.0)
|
31
|
+
crass (~> 1.0.2)
|
32
|
+
nokogiri (>= 1.5.9)
|
33
|
+
minitest (5.15.0)
|
34
|
+
nokogiri (1.12.5-x86_64-linux)
|
35
|
+
racc (~> 1.4)
|
13
36
|
parallel (1.21.0)
|
14
37
|
parser (3.0.3.2)
|
15
38
|
ast (~> 2.4.1)
|
39
|
+
racc (1.6.0)
|
40
|
+
rails-dom-testing (2.0.3)
|
41
|
+
activesupport (>= 4.2.0)
|
42
|
+
nokogiri (>= 1.6)
|
43
|
+
rails-html-sanitizer (1.4.2)
|
44
|
+
loofah (~> 2.3)
|
16
45
|
rainbow (3.0.0)
|
17
46
|
rake (13.0.6)
|
18
47
|
regexp_parser (2.2.0)
|
@@ -46,12 +75,15 @@ GEM
|
|
46
75
|
ruby-progressbar (1.11.0)
|
47
76
|
temple (0.8.2)
|
48
77
|
tilt (2.0.10)
|
78
|
+
tzinfo (2.0.4)
|
79
|
+
concurrent-ruby (~> 1.0)
|
49
80
|
unicode-display_width (2.1.0)
|
50
81
|
|
51
82
|
PLATFORMS
|
52
83
|
x86_64-linux
|
53
84
|
|
54
85
|
DEPENDENCIES
|
86
|
+
actionview
|
55
87
|
rake (~> 13.0)
|
56
88
|
rspec
|
57
89
|
rubocop
|
data/README.md
CHANGED
data/lib/slimi/engine.rb
CHANGED
@@ -9,6 +9,7 @@ module Slimi
|
|
9
9
|
attr_quote: '"',
|
10
10
|
default_tag: 'div',
|
11
11
|
format: :xhtml,
|
12
|
+
generator: ::Temple::Generators::StringBuffer,
|
12
13
|
merge_attrs: { 'class' => ' ' },
|
13
14
|
pretty: false,
|
14
15
|
sort_attrs: true
|
@@ -28,6 +29,7 @@ module Slimi
|
|
28
29
|
use Filters::Attribute
|
29
30
|
use(:AttributeRemover) { ::Temple::HTML::AttributeRemover.new(remove_empty_attrs: options[:merge_attrs].keys) }
|
30
31
|
html :Pretty
|
32
|
+
use Filters::Amble
|
31
33
|
filter :Escapable
|
32
34
|
filter :ControlFlow
|
33
35
|
filter :MultiFlattener
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Slimi
|
4
|
+
module Filters
|
5
|
+
# Support Rails annotate_rendered_view_with_filenames feature.
|
6
|
+
class Amble < Base
|
7
|
+
define_options(
|
8
|
+
:postamble,
|
9
|
+
:preamble
|
10
|
+
)
|
11
|
+
|
12
|
+
# @param [Array] expression
|
13
|
+
# @return [Array]
|
14
|
+
def call(expression)
|
15
|
+
result = %i[multi]
|
16
|
+
result << [:static, options[:preamble]] if options[:preamble]
|
17
|
+
result << expression
|
18
|
+
result << [:static, options[:postamble]] if options[:postamble]
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
5
|
# Handle `[:slimi, :attributes, ...]`.
|
6
|
-
class Attribute <
|
6
|
+
class Attribute < Base
|
7
7
|
define_options :merge_attrs
|
8
8
|
|
9
9
|
# @param [Array<Array>] expressions
|
@@ -16,7 +16,7 @@ module Slimi
|
|
16
16
|
# @param [Array] value
|
17
17
|
# @return [Array]
|
18
18
|
def on_html_attr(name, value)
|
19
|
-
if value[0] == :
|
19
|
+
if value[0] == :slimi && value[1] == :attrvalue && !options[:merge_attrs][name]
|
20
20
|
escape = value[2]
|
21
21
|
code = value[3]
|
22
22
|
case code
|
@@ -42,7 +42,7 @@ module Slimi
|
|
42
42
|
# @param [Boolean] escape
|
43
43
|
# @param [String] code\
|
44
44
|
# @return [Array]\
|
45
|
-
def
|
45
|
+
def on_slimi_attrvalue(escape, code)
|
46
46
|
if (delimiter = options[:merge_attrs][@attr])
|
47
47
|
tmp = unique_name
|
48
48
|
[:multi,
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'temple'
|
4
|
+
|
5
|
+
module Slimi
|
6
|
+
module Filters
|
7
|
+
# Pass-through some expressions which are unknown for Temple.
|
8
|
+
class Base < ::Temple::HTML::Filter
|
9
|
+
# @param [String] code
|
10
|
+
# @param [Array] expression
|
11
|
+
# @return [Array]
|
12
|
+
def on_slimi_control(code, expression)
|
13
|
+
[:slimi, :control, code, compile(expression)]
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [String] type
|
17
|
+
# @param [String] code
|
18
|
+
# @param [Array] expression
|
19
|
+
# @param [Array] attributes
|
20
|
+
# @return [Array]
|
21
|
+
def on_slimi_embedded(type, expression, attributes)
|
22
|
+
[:slimi, :embedded, type, compile(expression), attributes]
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [Boolean] escape
|
26
|
+
# @param [String] code
|
27
|
+
# @param [Array] expression
|
28
|
+
# @return [Array]
|
29
|
+
def on_slimi_output(escape, code, expression)
|
30
|
+
[:slimi, :output, escape, code, compile(expression)]
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [String] type
|
34
|
+
# @param [Array] expression
|
35
|
+
# @return [Array]
|
36
|
+
def on_slimi_text(type, expression)
|
37
|
+
[:slimi, :text, type, compile(expression)]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
|
-
# Handle `[:
|
6
|
-
class Control <
|
5
|
+
# Handle `[:slimi, :control, code, multi]`.
|
6
|
+
class Control < Base
|
7
7
|
# @param [String] code
|
8
8
|
# @param [Array] multi
|
9
9
|
# @return [Array]
|
10
|
-
def
|
10
|
+
def on_slimi_control(code, multi)
|
11
11
|
[
|
12
12
|
:multi,
|
13
13
|
[:code, code],
|
@@ -3,24 +3,24 @@
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
5
|
# Append missing `do` to embedded Ruby code.
|
6
|
-
class DoInserter <
|
6
|
+
class DoInserter < Base
|
7
7
|
VALID_RUBY_LINE_REGEXP = /(\A(if|unless|else|elsif|when|begin|rescue|ensure|case)\b)|\bdo\s*(\|[^|]*\|\s*)?\Z/.freeze
|
8
8
|
|
9
9
|
# @param [String] code
|
10
10
|
# @param [Array] expressio
|
11
11
|
# @return [Array]
|
12
|
-
def
|
12
|
+
def on_slimi_control(code, expression)
|
13
13
|
code += ' do' unless code.match?(VALID_RUBY_LINE_REGEXP) || empty_exp?(expression)
|
14
|
-
[:
|
14
|
+
[:slimi, :control, code, compile(expression)]
|
15
15
|
end
|
16
16
|
|
17
17
|
# @param [Boolean] escape
|
18
18
|
# @param [String] code
|
19
19
|
# @param [Array] expression
|
20
20
|
# @return [Array]
|
21
|
-
def
|
21
|
+
def on_slimi_output(escape, code, expression)
|
22
22
|
code += ' do' unless code.match?(VALID_RUBY_LINE_REGEXP) || empty_exp?(expression)
|
23
|
-
[:
|
23
|
+
[:slimi, :output, escape, code, compile(expression)]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -3,21 +3,21 @@
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
5
|
# @api private
|
6
|
-
class TextCollector <
|
6
|
+
class TextCollector < Base
|
7
7
|
def call(exp)
|
8
8
|
@collected = ''
|
9
9
|
super(exp)
|
10
10
|
@collected
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def on_slimi_interpolate(text)
|
14
14
|
@collected << text
|
15
15
|
nil
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
# @api private
|
20
|
-
class NewlineCollector <
|
20
|
+
class NewlineCollector < Base
|
21
21
|
def call(exp)
|
22
22
|
@collected = [:multi]
|
23
23
|
super(exp)
|
@@ -31,7 +31,7 @@ module Slimi
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# @api private
|
34
|
-
class OutputProtector <
|
34
|
+
class OutputProtector < Base
|
35
35
|
def call(exp)
|
36
36
|
@protect = []
|
37
37
|
@collected = ''
|
@@ -45,9 +45,9 @@ module Slimi
|
|
45
45
|
nil
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def on_slimi_output(escape, text, content)
|
49
49
|
@collected << @tag
|
50
|
-
@protect << [:
|
50
|
+
@protect << [:slimi, :output, escape, text, content]
|
51
51
|
nil
|
52
52
|
end
|
53
53
|
|
@@ -64,7 +64,7 @@ module Slimi
|
|
64
64
|
|
65
65
|
# Temple filter which processes embedded engines
|
66
66
|
# @api private
|
67
|
-
class Embedded <
|
67
|
+
class Embedded < Base
|
68
68
|
@engines = {}
|
69
69
|
|
70
70
|
class << self
|
@@ -101,12 +101,12 @@ module Slimi
|
|
101
101
|
@disabled = normalize_engine_list(options[:disable_engines])
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
104
|
+
def on_slimi_embedded(name, body, attrs)
|
105
105
|
name = name.to_sym
|
106
106
|
raise(Temple::FilterError, "Embedded engine #{name} is disabled") unless enabled?(name)
|
107
107
|
|
108
108
|
@engines[name] ||= self.class.create(name, options)
|
109
|
-
@engines[name].
|
109
|
+
@engines[name].on_slimi_embedded(name, body, attrs)
|
110
110
|
end
|
111
111
|
|
112
112
|
def enabled?(name)
|
@@ -122,7 +122,7 @@ module Slimi
|
|
122
122
|
list&.map(&:to_sym)
|
123
123
|
end
|
124
124
|
|
125
|
-
class Engine <
|
125
|
+
class Engine < Base
|
126
126
|
protected
|
127
127
|
|
128
128
|
def collect_text(body)
|
@@ -138,7 +138,7 @@ module Slimi
|
|
138
138
|
|
139
139
|
# Basic tilt engine
|
140
140
|
class TiltEngine < Engine
|
141
|
-
def
|
141
|
+
def on_slimi_embedded(engine, body, _attrs)
|
142
142
|
tilt_engine = Tilt[engine] || raise(Temple::FilterError, "Tilt engine #{engine} is not available.")
|
143
143
|
tilt_options = options[engine.to_sym] || {}
|
144
144
|
tilt_options[:default_encoding] ||= 'utf-8'
|
@@ -194,7 +194,7 @@ module Slimi
|
|
194
194
|
class TagEngine < Engine
|
195
195
|
disable_option_validator!
|
196
196
|
|
197
|
-
def
|
197
|
+
def on_slimi_embedded(engine, body, attrs)
|
198
198
|
unless options[:attributes].empty?
|
199
199
|
options[:attributes].map do |k, v|
|
200
200
|
attrs << [:html, :attr, k, [:static, v]]
|
@@ -207,7 +207,7 @@ module Slimi
|
|
207
207
|
opts.delete(:tag)
|
208
208
|
opts.delete(:attributes)
|
209
209
|
@engine ||= options[:engine].new(opts)
|
210
|
-
body = @engine.
|
210
|
+
body = @engine.on_slimi_embedded(engine, body, attrs)
|
211
211
|
end
|
212
212
|
|
213
213
|
[:html, :tag, options[:tag], attrs, body]
|
@@ -221,14 +221,14 @@ module Slimi
|
|
221
221
|
|
222
222
|
set_options tag: :script, attributes: {}
|
223
223
|
|
224
|
-
def
|
224
|
+
def on_slimi_embedded(engine, body, attrs)
|
225
225
|
super(engine, [:html, :js, body], attrs)
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
229
229
|
# Embeds ruby code
|
230
230
|
class RubyEngine < Engine
|
231
|
-
def
|
231
|
+
def on_slimi_embedded(_engine, body, _attrs)
|
232
232
|
[:multi, [:newline], [:code, "#{collect_text(body)}\n"]]
|
233
233
|
end
|
234
234
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
5
|
# Append missing `end` line to embedded Ruby code in control block.
|
6
|
-
class EndInserter <
|
6
|
+
class EndInserter < Base
|
7
7
|
# @param [Array<Array>] expressions
|
8
8
|
def on_multi(*expressions)
|
9
9
|
result = [:multi]
|
@@ -49,7 +49,7 @@ module Slimi
|
|
49
49
|
|
50
50
|
# @return [Boolean]
|
51
51
|
def control?
|
52
|
-
@expression[0] == :
|
52
|
+
@expression[0] == :slimi && @expression[1] == :control
|
53
53
|
end
|
54
54
|
|
55
55
|
# @return [Boolean]
|
@@ -4,29 +4,7 @@ require 'strscan'
|
|
4
4
|
|
5
5
|
module Slimi
|
6
6
|
module Filters
|
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
|
-
|
7
|
+
class Interpolation < Base
|
30
8
|
# @param [Integer] begin_
|
31
9
|
# @param [Integer] end_
|
32
10
|
# @return [Array] S-expression.
|
@@ -47,7 +25,7 @@ module Slimi
|
|
47
25
|
else
|
48
26
|
escape = false
|
49
27
|
end
|
50
|
-
block << [:slimi, :position, begin2, begin2 + code.length, [:
|
28
|
+
block << [:slimi, :position, begin2, begin2 + code.length, [:slimi, :output, escape, code, [:multi]]]
|
51
29
|
elsif (value = scanner.scan(/([#\\]?[^#\\]*([#\\][^\\\#{][^#\\]*)*)/)) # rubocop:disable Lint/DuplicateBranch
|
52
30
|
block << [:static, value]
|
53
31
|
end
|
data/lib/slimi/filters/output.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
|
-
# Handle `[:
|
6
|
-
class Output <
|
5
|
+
# Handle `[:slimi, :output, escape, code, multi]`.
|
6
|
+
class Output < Base
|
7
7
|
define_options :disable_capture
|
8
8
|
|
9
9
|
IF_REGEXP = /\A(if|unless)\b|\bdo\s*(\|[^|]*\|)?\s*$/.freeze
|
@@ -12,7 +12,7 @@ module Slimi
|
|
12
12
|
# @param [String] code
|
13
13
|
# @param [Array] multi
|
14
14
|
# @return [Array]
|
15
|
-
def
|
15
|
+
def on_slimi_output(escape, code, multi)
|
16
16
|
if code.match?(IF_REGEXP)
|
17
17
|
tmp = unique_name
|
18
18
|
[
|
data/lib/slimi/filters/text.rb
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
|
-
# Handle `[:
|
6
|
-
class Text <
|
5
|
+
# Handle `[:slimi, :text, multi]`.
|
6
|
+
class Text < Base
|
7
7
|
# @param [Symbol] _type
|
8
8
|
# @param [Array] multi
|
9
9
|
# @return [Array]
|
10
|
-
def
|
10
|
+
def on_slimi_text(_type, multi)
|
11
11
|
compile(multi)
|
12
12
|
end
|
13
13
|
end
|
@@ -2,29 +2,13 @@
|
|
2
2
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
|
-
class Unposition
|
6
|
-
|
7
|
-
|
8
|
-
# @param [Array]
|
9
|
-
# @return [Array]
|
10
|
-
def
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def convert(value)
|
17
|
-
if value.instance_of?(::Array)
|
18
|
-
if value[0] == :slimi && value[1] == :position
|
19
|
-
call(value[4])
|
20
|
-
else
|
21
|
-
value.map do |element|
|
22
|
-
call(element)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
else
|
26
|
-
value
|
27
|
-
end
|
5
|
+
class Unposition < Base
|
6
|
+
# @param [Integer] _begin
|
7
|
+
# @param [Integer] _end
|
8
|
+
# @param [Array] expression
|
9
|
+
# @return [Array]
|
10
|
+
def on_slimi_position(_begin, _end, expression)
|
11
|
+
compile(expression)
|
28
12
|
end
|
29
13
|
end
|
30
14
|
end
|
data/lib/slimi/filters.rb
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
module Slimi
|
4
4
|
module Filters
|
5
|
+
autoload :Amble, 'slimi/filters/amble'
|
5
6
|
autoload :Attribute, 'slimi/filters/attribute'
|
7
|
+
autoload :Base, 'slimi/filters/base'
|
6
8
|
autoload :Control, 'slimi/filters/control'
|
7
9
|
autoload :DoInserter, 'slimi/filters/do_inserter'
|
8
10
|
autoload :Embedded, 'slimi/filters/embedded'
|
data/lib/slimi/parser.rb
CHANGED
@@ -115,7 +115,7 @@ module Slimi
|
|
115
115
|
|
116
116
|
embedded_template_engine_name = @scanner[1]
|
117
117
|
attributes = parse_attributes
|
118
|
-
@stacks.last << [:
|
118
|
+
@stacks.last << [:slimi, :embedded, embedded_template_engine_name, parse_text_block, attributes]
|
119
119
|
end
|
120
120
|
|
121
121
|
# @return [Boolean]
|
@@ -150,14 +150,14 @@ module Slimi
|
|
150
150
|
block = [:multi]
|
151
151
|
@stacks.last.insert(-2, [:static, ' ']) if with_leading_white_space2
|
152
152
|
@scanner.skip(/[ \t]+/)
|
153
|
-
tag << with_position { [:
|
153
|
+
tag << with_position { [:slimi, :output, escape, parse_broken_lines, block] }
|
154
154
|
@stacks.last << [:static, ' '] if with_trailing_white_space2
|
155
155
|
@stacks << block
|
156
156
|
elsif @scanner.skip(%r{[ \t]*/[ \t]*})
|
157
157
|
syntax_error!(Errors::UnexpectedTextAfterClosedTagError) unless @scanner.match?(/\r?\n/)
|
158
158
|
else
|
159
159
|
@scanner.skip(/[ \t]+/)
|
160
|
-
tag << [:
|
160
|
+
tag << [:slimi, :text, :inline, parse_text_block]
|
161
161
|
end
|
162
162
|
true
|
163
163
|
else
|
@@ -272,7 +272,7 @@ module Slimi
|
|
272
272
|
charpos = @scanner.charpos
|
273
273
|
attribute_value = parse_ruby_attribute_value(attribute_delimiter_closing)
|
274
274
|
syntax_error!(Errors::InvalidEmptyAttributeError) if attribute_value.empty?
|
275
|
-
attributes << [:html, :attr, attribute_name, [:slimi, :position, charpos, charpos + attribute_value.length, [:
|
275
|
+
attributes << [:html, :attr, attribute_name, [:slimi, :position, charpos, charpos + attribute_value.length, [:slimi, :attrvalue, escape, attribute_value]]]
|
276
276
|
elsif !attribute_delimiter_closing_part_regexp
|
277
277
|
break
|
278
278
|
elsif @scanner.skip(boolean_attribute_regexp)
|
@@ -334,7 +334,7 @@ module Slimi
|
|
334
334
|
def parse_html_comment
|
335
335
|
if @scanner.skip(%r{/!})
|
336
336
|
text_block = parse_text_block
|
337
|
-
text = [:
|
337
|
+
text = [:slimi, :text, :verbatim, text_block]
|
338
338
|
@stacks.last << [:html, :comment, text]
|
339
339
|
true
|
340
340
|
else
|
@@ -381,7 +381,7 @@ module Slimi
|
|
381
381
|
def parse_verbatim_text_block_inner
|
382
382
|
if @scanner.skip(/([|']) ?/)
|
383
383
|
with_trailing_white_space = @scanner[1] == "'"
|
384
|
-
@stacks.last << [:
|
384
|
+
@stacks.last << [:slimi, :text, :verbatim, parse_text_block]
|
385
385
|
@stacks.last << [:static, ' '] if with_trailing_white_space
|
386
386
|
true
|
387
387
|
else
|
@@ -420,7 +420,7 @@ module Slimi
|
|
420
420
|
if @scanner.skip(/-/)
|
421
421
|
block = [:multi]
|
422
422
|
@scanner.skip(/[ \t]+/)
|
423
|
-
@stacks.last << with_position { [:
|
423
|
+
@stacks.last << with_position { [:slimi, :control, parse_broken_lines, block] }
|
424
424
|
@stacks << block
|
425
425
|
true
|
426
426
|
else
|
@@ -443,7 +443,7 @@ module Slimi
|
|
443
443
|
block = [:multi]
|
444
444
|
@stacks.last << [:static, ' '] if with_trailing_white_space
|
445
445
|
@scanner.skip(/[ \t]+/)
|
446
|
-
@stacks.last << with_position { [:
|
446
|
+
@stacks.last << with_position { [:slimi, :output, escape, parse_broken_lines, block] }
|
447
447
|
@stacks.last << [:static, ' '] if with_leading_white_space
|
448
448
|
@stacks << block
|
449
449
|
else
|
@@ -1,14 +1,77 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Slimi
|
4
|
+
# Render Slim template in response to requests from Rails.
|
4
5
|
class RailsTemplateHandler
|
5
|
-
|
6
|
-
|
6
|
+
# @param [ActionView::Template] template
|
7
|
+
# @param [String, nil] source
|
8
|
+
# @return [String]
|
9
|
+
def call(template, source = nil)
|
10
|
+
Renderer.new(
|
11
|
+
source: source,
|
12
|
+
template: template
|
13
|
+
).call
|
7
14
|
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
@
|
16
|
+
# Render HTML from given source and options.
|
17
|
+
class Renderer
|
18
|
+
# @param [String] source
|
19
|
+
# @param [ActionView::Template] template
|
20
|
+
def initialize(
|
21
|
+
source:,
|
22
|
+
template:
|
23
|
+
)
|
24
|
+
@source = source
|
25
|
+
@template = template
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String]
|
29
|
+
def call
|
30
|
+
engine.call(source)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [Slimi::Engine]
|
36
|
+
def engine
|
37
|
+
Engine.new(engine_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Hash{Symbol => Object}]
|
41
|
+
def engine_options
|
42
|
+
engine_default_options.merge(engine_amble_options)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Hash{Symbol => Object}]
|
46
|
+
def engine_default_options
|
47
|
+
{
|
48
|
+
generator: ::Temple::Generators::RailsOutputBuffer,
|
49
|
+
streaming: true,
|
50
|
+
use_html_safe: true
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Hash{Symbol => Object}]
|
55
|
+
def engine_amble_options
|
56
|
+
if with_annotate_rendered_view_with_filenames?
|
57
|
+
{
|
58
|
+
postamble: "<!-- END #{@template.short_identifier} -->\n",
|
59
|
+
preamble: "<!-- BEGIN #{@template.short_identifier} -->\n"
|
60
|
+
}
|
61
|
+
else
|
62
|
+
{}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [String]
|
67
|
+
def source
|
68
|
+
@source || @template.source
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Boolean]
|
72
|
+
def with_annotate_rendered_view_with_filenames?
|
73
|
+
::ActionView::Base.try(:annotate_rendered_view_with_filenames) && @template.format == :html
|
74
|
+
end
|
12
75
|
end
|
13
76
|
end
|
14
77
|
end
|
data/lib/slimi/railtie.rb
CHANGED
data/lib/slimi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slimi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -60,7 +60,9 @@ files:
|
|
60
60
|
- lib/slimi/engine.rb
|
61
61
|
- lib/slimi/errors.rb
|
62
62
|
- lib/slimi/filters.rb
|
63
|
+
- lib/slimi/filters/amble.rb
|
63
64
|
- lib/slimi/filters/attribute.rb
|
65
|
+
- lib/slimi/filters/base.rb
|
64
66
|
- lib/slimi/filters/control.rb
|
65
67
|
- lib/slimi/filters/do_inserter.rb
|
66
68
|
- lib/slimi/filters/embedded.rb
|