serbea 0.10.0 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7961cb287d077b528dd0367681aee6087a5efc9b3838670e7f8c7072b09c9ad
4
- data.tar.gz: ca1a4701f70e49e28c67dfb407018dfd56eaf42391a0aa4230e1a15dc1b57f86
3
+ metadata.gz: c0aa3994d0779dc0bada9d35a6125dafd4501070f780bd353384a1f72bd1be54
4
+ data.tar.gz: 455373e852ca5f680adf28d7efe3198e34b97f84d1fb93d58ab32eac84bde61b
5
5
  SHA512:
6
- metadata.gz: 84036346ec67f5789c380bd0772f1da6644223e1b82f6a5974de93c9c3b82c98b34c5a6f27c8c69dbb598b230a24b33a0ae16a9bee3a284b494eec81cec9f0ff
7
- data.tar.gz: 78da2c4e5f3828153b9933fd0173475aaacdf3bb42e4a56a4ec69f12b6991488559a7cfb57f8f1a64008173dd280b7c3c47de4daebc4cda537ed3638c7af3cbc
6
+ metadata.gz: 9b37ea92fed79e50c3e67ee81e06dfd9daf8c969ee6b6901312b8a74295d73f7a82e7b1fa34555feccd9c877e4e6322cb27e22acd3a3fab30a0b145318bbf221
7
+ data.tar.gz: 37a8dbcf0799f9cdf352bbe633d959ea6f5ec1ba082ba918d223794b0e00b5a2377f5d960f57d7d47dc5db756cb5a12636062359bfe3922878593cbf286b6299
@@ -2,8 +2,10 @@ require "serbea/rouge_lexer"
2
2
  require "bridgetown-core"
3
3
 
4
4
  module Bridgetown
5
- class SerbeaView < RubyTemplateView
5
+ class SerbeaView < ERBView
6
+ alias_method :_erb_capture, :capture
6
7
  include Serbea::Helpers
8
+ alias_method :capture, :_erb_capture
7
9
 
8
10
  def partial(partial_name, options = {}, &block)
9
11
  options.merge!(options[:locals]) if options[:locals]
@@ -17,14 +19,6 @@ module Bridgetown
17
19
  site.in_source_dir(site.config[:partials_dir], "#{partial_name}.serb")
18
20
  ).render(self, options)
19
21
  end
20
-
21
- def markdownify(input = nil, &block)
22
- content = Bridgetown::Utils.reindent_for_markdown(
23
- block.nil? ? input.to_s : capture(&block)
24
- )
25
- converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
26
- converter.convert(content).strip
27
- end
28
22
  end
29
23
 
30
24
  module Converters
@@ -6,52 +6,31 @@ module Serbea
6
6
  Serbea::Pipeline.deny_value_method %i(escape h prepend append assign_to)
7
7
  end
8
8
 
9
- def capture(obj = nil, &block)
9
+ def capture(*args)
10
10
  previous_buffer_state = @_erbout
11
11
  @_erbout = Serbea::OutputBuffer.new
12
-
13
- # For compatibility with ActionView, not used by Bridgetown normally
14
- previous_ob_state = @output_buffer
15
- @output_buffer = Serbea::OutputBuffer.new
16
-
17
-
18
- result = instance_exec(obj, &block)
19
- if @output_buffer != ""
20
- # use Rails' ActionView buffer if present
21
- result = @output_buffer
22
- end
12
+ result = yield(*args)
23
13
  @_erbout = previous_buffer_state
24
- @output_buffer = previous_ob_state
25
14
 
26
15
  result&.html_safe
27
16
  end
28
-
17
+
29
18
  def pipeline(context, value)
30
19
  Pipeline.new(context, value)
31
20
  end
32
-
21
+
33
22
  def helper(name, &helper_block)
34
23
  self.class.define_method(name) do |*args, &block|
35
24
  previous_buffer_state = @_erbout
36
25
  @_erbout = Serbea::OutputBuffer.new
37
-
38
- # For compatibility with ActionView, not used by Bridgetown normally
39
- previous_ob_state = @output_buffer
40
- @output_buffer = Serbea::OutputBuffer.new
41
-
42
26
  result = helper_block.call(*args, &block)
43
- if @output_buffer != ""
44
- # use Rails' ActionView buffer if present
45
- result = @output_buffer
46
- end
47
27
  @_erbout = previous_buffer_state
48
- @output_buffer = previous_ob_state
49
-
28
+
50
29
  result.is_a?(String) ? result.html_safe : result
51
30
  end
52
31
  end
53
32
  alias_method :macro, :helper
54
-
33
+
55
34
  def h(input)
56
35
  ERB::Util.h(input.to_s)
57
36
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "hash_with_dot_access"
4
+
3
5
  module Serbea
4
6
  module Rails
5
7
  module FrontmatterHelpers
@@ -42,9 +44,17 @@ Serbea::TemplateEngine.directive :form, ->(code, buffer) do
42
44
  buffer << code
43
45
  buffer << " %}"
44
46
  end
47
+
45
48
  Serbea::TemplateEngine.directive :_, ->(code, buffer) do
46
- buffer << "{%= content_tag "
47
- buffer << code
49
+ tag_name, space, params = code.lstrip.partition(%r(\s)m)
50
+
51
+ if tag_name.end_with?(":")
52
+ tag_name.chomp!(":")
53
+ tag_name = ":#{tag_name}" unless tag_name.start_with?(":")
54
+ end
55
+
56
+ buffer << "{%= tag.tag_string "
57
+ buffer << tag_name << ", " << params
48
58
  buffer << " %}"
49
59
  end
50
60
 
@@ -17,11 +17,10 @@ module Serbea
17
17
  def self.directive(new_directive, directive_resolution)
18
18
  directives[new_directive.to_s] = directive_resolution
19
19
  end
20
+
20
21
  def self.directives
21
22
  @directives ||= {
22
23
  "@" => ->(code, buffer) do
23
- original_line_length = code.lines.size
24
-
25
24
  pieces = code.split(" ")
26
25
  if pieces[0].start_with?(/[A-Z]/) # Ruby class name
27
26
  pieces[0].prepend " "
@@ -45,9 +44,6 @@ module Serbea
45
44
  pieces.last << ")"
46
45
  buffer << "{%= render#{pieces.join(" ")} %}"
47
46
  end
48
- (original_line_length - 1).times do
49
- buffer << "\n{% %}" # preserve original directive line length
50
- end
51
47
  end
52
48
  }
53
49
  end
@@ -55,30 +51,21 @@ module Serbea
55
51
  def self.front_matter_preamble=(varname)
56
52
  @front_matter_preamble = varname
57
53
  end
54
+
58
55
  def self.front_matter_preamble
59
56
  @front_matter_preamble ||= "frontmatter = YAML.load"
60
57
  end
61
-
58
+
62
59
  def self.has_yaml_header?(template)
63
60
  template.lines.first&.match? %r!\A---\s*\r?\n!
64
61
  end
65
-
62
+
66
63
  def initialize(input, properties={})
67
64
  properties[:regexp] = /{%(={1,2}|-|\#|%)?(.*?)([-=])?%}([ \t]*\r?\n)?/m
68
65
  properties[:strip_front_matter] = true unless properties.key?(:strip_front_matter)
69
66
  super process_serbea_input(input, properties), properties
70
67
  end
71
-
72
- def add_postamble(postamble)
73
- src << postamble
74
- src << "#{@bufvar}.html_safe"
75
-
76
- src.gsub!("__RAW_START_PRINT__", "{{")
77
- src.gsub!("__RAW_END_PRINT__", "}}")
78
- src.gsub!("__RAW_START_EVAL__", "{%")
79
- src.gsub!("__RAW_END_EVAL__", "%}")
80
- end
81
-
68
+
82
69
  def process_serbea_input(template, properties)
83
70
  buff = ""
84
71
 
@@ -190,7 +177,11 @@ module Serbea
190
177
  directive = $1 ? self.class.directives[$1] : self.class.directives["@"]
191
178
 
192
179
  if directive
180
+ additional_length = "#{buff}#{code}".lines.size
193
181
  directive.(code, buff)
182
+ (additional_length - buff.lines.size).times do
183
+ buff << "{% %}\n" # preserve original directive line length
184
+ end
194
185
  else
195
186
  raise "Handler for Serbea template directive `#{$1}' not found"
196
187
  end
@@ -202,7 +193,7 @@ module Serbea
202
193
 
203
194
  buff
204
195
  end
205
-
196
+
206
197
  private
207
198
 
208
199
  def add_code(code)
@@ -226,5 +217,15 @@ module Serbea
226
217
  def add_expression_result_escaped(code)
227
218
  add_expression_result(code)
228
219
  end
229
- end # class
220
+
221
+ def add_postamble(postamble)
222
+ src << postamble
223
+ src << "#{@bufvar}.html_safe"
224
+
225
+ src.gsub!("__RAW_START_PRINT__", "{{")
226
+ src.gsub!("__RAW_END_PRINT__", "}}")
227
+ src.gsub!("__RAW_START_EVAL__", "{%")
228
+ src.gsub!("__RAW_END_EVAL__", "%}")
229
+ end
230
+ end
230
231
  end
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.10.0"
2
+ VERSION = "0.10.5"
3
3
  end
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.10.0
4
+ version: 0.10.5
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-12-01 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport