serbea 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/serbea/rails_support.rb +11 -0
- data/lib/serbea/template_engine.rb +43 -32
- data/lib/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: f7961cb287d077b528dd0367681aee6087a5efc9b3838670e7f8c7072b09c9ad
|
4
|
+
data.tar.gz: ca1a4701f70e49e28c67dfb407018dfd56eaf42391a0aa4230e1a15dc1b57f86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84036346ec67f5789c380bd0772f1da6644223e1b82f6a5974de93c9c3b82c98b34c5a6f27c8c69dbb598b230a24b33a0ae16a9bee3a284b494eec81cec9f0ff
|
7
|
+
data.tar.gz: 78da2c4e5f3828153b9933fd0173475aaacdf3bb42e4a56a4ec69f12b6991488559a7cfb57f8f1a64008173dd280b7c3c47de4daebc4cda537ed3638c7af3cbc
|
data/lib/serbea/rails_support.rb
CHANGED
@@ -37,4 +37,15 @@ module Serbea
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
Serbea::TemplateEngine.directive :form, ->(code, buffer) do
|
41
|
+
buffer << "{%= form_with model:"
|
42
|
+
buffer << code
|
43
|
+
buffer << " %}"
|
44
|
+
end
|
45
|
+
Serbea::TemplateEngine.directive :_, ->(code, buffer) do
|
46
|
+
buffer << "{%= content_tag "
|
47
|
+
buffer << code
|
48
|
+
buffer << " %}"
|
49
|
+
end
|
50
|
+
|
40
51
|
ActionView::Template.register_template_handler(:serb, Serbea::Rails::TemplateHandler)
|
@@ -14,11 +14,42 @@ module Serbea
|
|
14
14
|
class TemplateEngine < Erubi::Engine
|
15
15
|
FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m.freeze
|
16
16
|
|
17
|
-
def self.
|
18
|
-
|
17
|
+
def self.directive(new_directive, directive_resolution)
|
18
|
+
directives[new_directive.to_s] = directive_resolution
|
19
19
|
end
|
20
|
-
def self.
|
21
|
-
@
|
20
|
+
def self.directives
|
21
|
+
@directives ||= {
|
22
|
+
"@" => ->(code, buffer) do
|
23
|
+
original_line_length = code.lines.size
|
24
|
+
|
25
|
+
pieces = code.split(" ")
|
26
|
+
if pieces[0].start_with?(/[A-Z]/) # Ruby class name
|
27
|
+
pieces[0].prepend " "
|
28
|
+
pieces[0] << ".new("
|
29
|
+
else # string or something else
|
30
|
+
pieces[0].prepend "("
|
31
|
+
end
|
32
|
+
|
33
|
+
includes_block = false
|
34
|
+
pieces.reverse.each do |piece|
|
35
|
+
if piece == "do" && (pieces.last == "do" || pieces.last.end_with?("|"))
|
36
|
+
piece.prepend(") ")
|
37
|
+
includes_block = true
|
38
|
+
break
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if includes_block
|
43
|
+
buffer << "{%= render#{pieces.join(" ")} %}"
|
44
|
+
else
|
45
|
+
pieces.last << ")"
|
46
|
+
buffer << "{%= render#{pieces.join(" ")} %}"
|
47
|
+
end
|
48
|
+
(original_line_length - 1).times do
|
49
|
+
buffer << "\n{% %}" # preserve original directive line length
|
50
|
+
end
|
51
|
+
end
|
52
|
+
}
|
22
53
|
end
|
23
54
|
|
24
55
|
def self.front_matter_preamble=(varname)
|
@@ -149,39 +180,19 @@ module Serbea
|
|
149
180
|
string = buff
|
150
181
|
buff = ""
|
151
182
|
until string.empty?
|
152
|
-
text, code, string = string.partition(/{%@(.*?)%}/m)
|
153
|
-
|
183
|
+
text, code, string = string.partition(/{%@([a-z_]+)?(.*?)%}/m)
|
184
|
+
|
154
185
|
buff << text
|
155
186
|
if code.length > 0
|
156
|
-
|
187
|
+
directive = $1
|
188
|
+
code = $2
|
157
189
|
unless ["end", ""].include? code.strip
|
158
|
-
|
159
|
-
|
160
|
-
pieces = code.split(" ")
|
161
|
-
if pieces[0].start_with?(/[A-Z]/) # Ruby class name
|
162
|
-
pieces[0].prepend " "
|
163
|
-
pieces[0] << ".new("
|
164
|
-
else # string or something else
|
165
|
-
pieces[0].prepend "("
|
166
|
-
end
|
190
|
+
directive = $1 ? self.class.directives[$1] : self.class.directives["@"]
|
167
191
|
|
168
|
-
|
169
|
-
|
170
|
-
if piece == "do" && (pieces.last == "do" || pieces.last.end_with?("|"))
|
171
|
-
piece.prepend(") ")
|
172
|
-
includes_block = true
|
173
|
-
break
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
if includes_block
|
178
|
-
buff << "{%= #{self.class.render_directive}#{pieces.join(" ")} %}"
|
192
|
+
if directive
|
193
|
+
directive.(code, buff)
|
179
194
|
else
|
180
|
-
|
181
|
-
buff << "{%= #{self.class.render_directive}#{pieces.join(" ")} %}"
|
182
|
-
end
|
183
|
-
(original_line_length - 1).times do
|
184
|
-
buff << "\n{% %}" # preserve original directive line length
|
195
|
+
raise "Handler for Serbea template directive `#{$1}' not found"
|
185
196
|
end
|
186
197
|
else
|
187
198
|
buff << "{% end %}"
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serbea
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|