serbea 0.4.4 → 0.5.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.rb +1 -1
- data/lib/serbea/bridgetown_support.rb +7 -6
- data/lib/serbea/helpers.rb +14 -4
- data/lib/serbea/rails_support.rb +4 -2
- data/lib/serbea/template_engine.rb +33 -22
- 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: ce17e2b60c2abf63a033d8d358686d4df115e87a4c149ba3c625a403863e129c
|
4
|
+
data.tar.gz: a3901a5286afc92e84b2ecc29b2622e80a592f0d0d9de46a7aa58d836e150c65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52aadba5419583064f26be67a99805ea66af5798b3bd3a34604967c91fdee3f2e6010ba692b6f70a2de798fa5d899bb7760fd3a76975e415932e5922c7f21c6a
|
7
|
+
data.tar.gz: 4bc3fcfa08bb021ceb68ae675f4f47d4fd72a2e1cdd71fe68d8b4e435493238c49f205f10ccc52e0980d160a226433af19b70d39d18bc3d73b30c9afb8be0698
|
data/lib/serbea.rb
CHANGED
@@ -10,7 +10,7 @@ require "serbea/component_renderer"
|
|
10
10
|
module Tilt
|
11
11
|
class SerbeaTemplate < ErubiTemplate
|
12
12
|
def prepare
|
13
|
-
@options.merge!(outvar: "@_erbout", engine_class: Serbea::TemplateEngine)
|
13
|
+
@options.merge!(outvar: "@_erbout", bufval: "Serbea::Buffer.new", engine_class: Serbea::TemplateEngine)
|
14
14
|
super
|
15
15
|
end
|
16
16
|
|
@@ -4,9 +4,9 @@ module Bridgetown
|
|
4
4
|
class SerbeaView < RubyTemplateView
|
5
5
|
include Serbea::Helpers
|
6
6
|
|
7
|
-
def partial(partial_name, options = {})
|
7
|
+
def partial(partial_name, options = {}, &block)
|
8
8
|
options.merge!(options[:locals]) if options[:locals]
|
9
|
-
options[:content] =
|
9
|
+
options[:content] = capture(&block) if block
|
10
10
|
|
11
11
|
partial_segments = partial_name.split("/")
|
12
12
|
partial_segments.last.sub!(%r!^!, "_")
|
@@ -17,11 +17,12 @@ module Bridgetown
|
|
17
17
|
).render(self, options)
|
18
18
|
end
|
19
19
|
|
20
|
-
def markdownify(&block)
|
21
|
-
content = Bridgetown::Utils.reindent_for_markdown(
|
20
|
+
def markdownify(input = nil, &block)
|
21
|
+
content = Bridgetown::Utils.reindent_for_markdown(
|
22
|
+
block.nil? ? input.to_s : capture(&block)
|
23
|
+
)
|
22
24
|
converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
|
23
|
-
|
24
|
-
@_erbout << md_output
|
25
|
+
converter.convert(content).strip
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
data/lib/serbea/helpers.rb
CHANGED
@@ -4,12 +4,22 @@ module Serbea
|
|
4
4
|
Serbea::Pipeline.deny_value_method %i(escape h prepend append assign_to)
|
5
5
|
end
|
6
6
|
|
7
|
-
def capture(obj=nil)
|
7
|
+
def capture(obj = nil, &block)
|
8
8
|
previous_buffer_state = @_erbout
|
9
|
-
@_erbout =
|
10
|
-
|
9
|
+
@_erbout = Serbea::Buffer.new
|
10
|
+
|
11
|
+
# For compatibility with ActionView, not used by Bridgetown normally
|
12
|
+
previous_ob_state = @output_buffer
|
13
|
+
@output_buffer = Serbea::Buffer.new
|
14
|
+
|
15
|
+
result = instance_exec(obj, &block)
|
16
|
+
if @output_buffer != ""
|
17
|
+
# use Rails' ActionView buffer if present
|
18
|
+
result = @output_buffer
|
19
|
+
end
|
11
20
|
@_erbout = previous_buffer_state
|
12
|
-
|
21
|
+
@output_buffer = previous_ob_state
|
22
|
+
|
13
23
|
result.respond_to?(:html_safe) ? result.html_safe : result
|
14
24
|
end
|
15
25
|
|
data/lib/serbea/rails_support.rb
CHANGED
@@ -27,6 +27,8 @@ end
|
|
27
27
|
|
28
28
|
ActionView::Template.register_template_handler(:serb, Serbea::Plugin)
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
if defined?(ActionController::Base)
|
31
|
+
Serbea::Pipeline.output_processor = lambda do |input|
|
32
|
+
input.html_safe? ? input : ActionController::Base.helpers.strip_tags(input)
|
33
|
+
end
|
32
34
|
end
|
@@ -1,5 +1,15 @@
|
|
1
1
|
module Serbea
|
2
|
-
class
|
2
|
+
class Buffer < String
|
3
|
+
def concat_to_s(input)
|
4
|
+
concat input.to_s
|
5
|
+
end
|
6
|
+
|
7
|
+
alias_method :safe_append=, :concat_to_s
|
8
|
+
alias_method :append=, :concat_to_s
|
9
|
+
alias_method :safe_expr_append=, :concat_to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
class TemplateEngine < Erubi::Engine
|
3
13
|
FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m.freeze
|
4
14
|
|
5
15
|
def self.render_directive=(directive)
|
@@ -21,14 +31,14 @@ module Serbea
|
|
21
31
|
end
|
22
32
|
|
23
33
|
def initialize(input, properties={})
|
24
|
-
properties[:regexp] = /{%(
|
34
|
+
properties[:regexp] = /{%(={1,2}|-|\#|%)?(.*?)([-=])?%}([ \t]*\r?\n)?/m
|
25
35
|
properties[:strip_front_matter] = true unless properties.key?(:strip_front_matter)
|
26
36
|
super process_serbea_input(input, properties), properties
|
27
37
|
end
|
28
38
|
|
29
39
|
def add_postamble(postamble)
|
30
40
|
src << postamble
|
31
|
-
src << "@
|
41
|
+
src << "#{@bufvar}.html_safe" if postamble.respond_to?(:html_safe)
|
32
42
|
|
33
43
|
src.gsub!("__RAW_START_PRINT__", "{{")
|
34
44
|
src.gsub!("__RAW_END_PRINT__", "}}")
|
@@ -140,7 +150,7 @@ module Serbea
|
|
140
150
|
end
|
141
151
|
|
142
152
|
if includes_block
|
143
|
-
buff << "{
|
153
|
+
buff << "{%= #{self.class.render_directive}#{pieces.join(" ")} %}"
|
144
154
|
else
|
145
155
|
pieces.last << ")"
|
146
156
|
buff << "{%= #{self.class.render_directive}#{pieces.join(" ")} %}"
|
@@ -149,7 +159,7 @@ module Serbea
|
|
149
159
|
buff << "\n{% %}" # preserve original directive line length
|
150
160
|
end
|
151
161
|
else
|
152
|
-
buff << "{
|
162
|
+
buff << "{% end %}"
|
153
163
|
end
|
154
164
|
end
|
155
165
|
end
|
@@ -158,26 +168,27 @@ module Serbea
|
|
158
168
|
end
|
159
169
|
|
160
170
|
private
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
add_text(lspace) if lspace
|
175
|
-
result = @yield_returns_buffer ? " #{@bufvar}; " : ""
|
176
|
-
src << result << code << ")).to_s; ensure; #{@bufvar} = #{@bufstack}.pop; end;"
|
177
|
-
add_text(rspace) if rspace
|
171
|
+
|
172
|
+
def add_code(code)
|
173
|
+
@src << code
|
174
|
+
@src << ";#{@bufvar};" if code.strip.split(".").first == "end"
|
175
|
+
@src << ';' unless code[Erubi::RANGE_LAST] == "\n"
|
176
|
+
end
|
177
|
+
|
178
|
+
# pulled from Rails' ActionView
|
179
|
+
BLOCK_EXPR = %r!\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z!.freeze
|
180
|
+
|
181
|
+
def add_expression(indicator, code)
|
182
|
+
if BLOCK_EXPR.match?(code)
|
183
|
+
src << "#{@bufvar}.append= " << code
|
178
184
|
else
|
179
185
|
super
|
180
186
|
end
|
181
187
|
end
|
188
|
+
|
189
|
+
# Don't allow == to output escaped strings, as that's the opposite of Rails
|
190
|
+
def add_expression_result_escaped(code)
|
191
|
+
add_expression_result(code)
|
192
|
+
end
|
182
193
|
end # class
|
183
194
|
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.5.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-10-
|
11
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubi
|