serbea 0.4.1 → 0.4.2

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: 2403adca3b4cbb2e82ad7bb758df50c04257d45f1b303a1a9b03a15453d66953
4
- data.tar.gz: 1ccfc568da131dd13d9cc627b05fb13577854d4edfbf2ea0a3353b69b097a5f2
3
+ metadata.gz: 22177afa63ae7dccc14171dbfaac1d77b237b75b97f4779eeefc4c7fdf44dd5b
4
+ data.tar.gz: fa0591db51fd9d2f78541d48a717369d7d9b5b5e22be38f5c126972fbba8aa57
5
5
  SHA512:
6
- metadata.gz: 22633765cd7a2ce0020cdd27708e2bc349cc9ccd168d1d15f7f135926d4a0333098fa05ebd34b7f77811371620f01860d7876935e0be47160e03714f8efc01d6
7
- data.tar.gz: 9c5a097fe9fdb43738e3d61f3d61d973d15bff640ad3ae85cc9fb670e61c4a31154f67522bf9651f65ec6a1e67bf755d1b50ea6bc2508b42dfe9dd6f24c627d3
6
+ metadata.gz: 1c5c3e615db4ea48225efc20a0f345a05aadd14f2ba9d38fe7406298fcfa371a77d3e8517d08d05dfe34f42cf7025818309b210ab6e7b0d14daeca0ccabe438c
7
+ data.tar.gz: 699e31b8fc7fd9bd32437170c5cf5c48b625f905c1a2b7312b4476ec8b3a89c76cbe1d7056bffdf1000099cbd67abd2862717a58177ee9725eb65090bc983ce1
@@ -1,9 +1,12 @@
1
+ require "serbea/rouge_lexer"
2
+
1
3
  module Bridgetown
2
4
  class SerbeaView < RubyTemplateView
3
5
  include Serbea::Helpers
4
6
 
5
7
  def partial(partial_name, options = {})
6
8
  options.merge!(options[:locals]) if options[:locals]
9
+ options[:content] = yield if block_given?
7
10
 
8
11
  partial_segments = partial_name.split("/")
9
12
  partial_segments.last.sub!(%r!^!, "_")
@@ -13,14 +16,9 @@ module Bridgetown
13
16
  site.in_source_dir(site.config[:partials_dir], "#{partial_name}.serb")
14
17
  ).render(self, options)
15
18
  end
16
-
17
- def markdownify
18
- previous_buffer_state = @_erbout
19
- @_erbout = +""
20
- result = yield
21
- @_erbout = previous_buffer_state
22
-
23
- content = Bridgetown::Utils.reindent_for_markdown(result)
19
+
20
+ def markdownify(&block)
21
+ content = Bridgetown::Utils.reindent_for_markdown(capture(&block))
24
22
  converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
25
23
  md_output = converter.convert(content).strip
26
24
  @_erbout << md_output
@@ -29,6 +27,7 @@ module Bridgetown
29
27
 
30
28
  module Converters
31
29
  class SerbeaTemplates < Converter
30
+ priority :highest
32
31
  input :serb
33
32
 
34
33
  # Logic to do the Serbea content conversion.
@@ -51,6 +50,20 @@ module Bridgetown
51
50
  serb_renderer.render(serb_view)
52
51
  end
53
52
  end
53
+
54
+ def matches(ext, convertible)
55
+ if convertible.data[:template_engine] == "serbea" ||
56
+ (convertible.data[:template_engine].nil? &&
57
+ @config[:template_engine] == "serbea")
58
+ return true
59
+ end
60
+
61
+ super(ext)
62
+ end
63
+
64
+ def output_ext(ext)
65
+ ext == ".serb" ? ".html" : ext
66
+ end
54
67
  end
55
68
  end
56
69
  end
@@ -22,7 +22,8 @@ module Serbea
22
22
  end
23
23
 
24
24
  def h(input)
25
- Erubi.h(input)
25
+ result = Erubi.h(input)
26
+ h.respond_to?(:html_safe) ? result.html_safe : result
26
27
  end
27
28
  alias_method :escape, :h
28
29
 
@@ -32,6 +32,13 @@ module Serbea
32
32
  end
33
33
  end
34
34
 
35
+ def self.raise_on_missing_filters=(config_boolean)
36
+ @raise_on_missing_filters = config_boolean
37
+ end
38
+ def self.raise_on_missing_filters
39
+ @raise_on_missing_filters ||= false
40
+ end
41
+
35
42
  def self.deny_value_method(name)
36
43
  value_methods_denylist.merge Array(name)
37
44
  end
@@ -70,7 +77,7 @@ module Serbea
70
77
  end
71
78
  else
72
79
  "Serbea warning: Filter not found: #{name}".tap do |warning|
73
- raise_on_missing_filters ? raise(warning) : STDERR.puts(warning)
80
+ self.class.raise_on_missing_filters ? raise(warning) : STDERR.puts(warning)
74
81
  end
75
82
  end
76
83
 
@@ -80,7 +87,5 @@ module Serbea
80
87
  def to_s
81
88
  self.class.output_processor.call @value.to_s
82
89
  end
83
-
84
- def raise_on_missing_filters; false; end
85
90
  end
86
91
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rouge"
4
+
5
+ module Rouge
6
+ module Lexers
7
+ class Serbea < TemplateLexer
8
+ title "Serbea"
9
+ desc "Embedded Ruby Serbea template files"
10
+
11
+ tag 'serb'
12
+
13
+ filenames '*.serb'
14
+
15
+ def initialize(opts={})
16
+ @ruby_lexer = Ruby.new(opts)
17
+
18
+ super(opts)
19
+ end
20
+
21
+ start do
22
+ parent.reset!
23
+ @ruby_lexer.reset!
24
+ end
25
+
26
+ open = /{%%|{%=|{%#|{%-|{%|{{/
27
+ close = /%%}|-%}|%}|}}/
28
+
29
+ state :root do
30
+ rule %r/{%#/, Comment, :comment
31
+
32
+ rule open, Comment::Preproc, :ruby
33
+
34
+ rule %r/.+?(?=#{open})|.+/m do
35
+ delegate parent
36
+ end
37
+ end
38
+
39
+ state :comment do
40
+ rule close, Comment, :pop!
41
+ rule %r/.+?(?=#{close})|.+/m, Comment
42
+ end
43
+
44
+ state :ruby do
45
+ rule close, Comment::Preproc, :pop!
46
+
47
+ rule %r/.+?(?=#{close})|.+/m do
48
+ delegate @ruby_lexer
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -91,7 +91,7 @@ module Serbea
91
91
 
92
92
  pipeline_suffix = processed_filters ? ") %}" : ")) %}"
93
93
 
94
- subs = subs.sub("{{", "{%= pipeline(self, (").sub("}}", pipeline_suffix).gsub("__PIPE_C__", '\|')
94
+ subs = subs.sub("{{", "{%= pipeline(self, (").sub("}}", pipeline_suffix).gsub("__PIPE_C__", '|')
95
95
 
96
96
  buff << subs
97
97
 
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
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.4.1
4
+ version: 0.4.2
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-09-30 00:00:00.000000000 Z
11
+ date: 2020-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi
@@ -54,6 +54,7 @@ files:
54
54
  - lib/serbea/helpers.rb
55
55
  - lib/serbea/pipeline.rb
56
56
  - lib/serbea/rails_support.rb
57
+ - lib/serbea/rouge_lexer.rb
57
58
  - lib/serbea/template_engine.rb
58
59
  - lib/version.rb
59
60
  - serbea.gemspec