serbea 0.10.3 → 0.11.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.
@@ -29,7 +29,7 @@ module Bridgetown
29
29
  # Logic to do the Serbea content conversion.
30
30
  #
31
31
  # @param content [String] Content of the file (without front matter).
32
- # @params convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
32
+ # @param convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
33
33
  # The instantiated object which is processing the file.
34
34
  #
35
35
  # @return [String] The converted content.
@@ -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
@@ -38,13 +40,39 @@ module Serbea
38
40
  end
39
41
 
40
42
  Serbea::TemplateEngine.directive :form, ->(code, buffer) do
41
- buffer << "{%= form_with model:"
43
+ model_name, space, params = code.lstrip.partition(%r(\s)m)
44
+ model_name.chomp!(",")
45
+ model_name = "#{model_name}," unless params.lstrip.start_with?("do", "{")
46
+
47
+ buffer << "{%= form_with model: "
48
+ buffer << model_name << " #{params}"
49
+ buffer << " %}"
50
+ end
51
+
52
+ Serbea::TemplateEngine.directive :frame, ->(code, buffer) do
53
+ buffer << "{%= turbo_frame_tag "
42
54
  buffer << code
43
55
  buffer << " %}"
44
56
  end
57
+
58
+ %i(append prepend update replace remove).each do |action|
59
+ Serbea::TemplateEngine.directive action, ->(code, buffer) do
60
+ buffer << "{%= turbo_stream.#{action} "
61
+ buffer << code
62
+ buffer << " %}"
63
+ end
64
+ end
65
+
45
66
  Serbea::TemplateEngine.directive :_, ->(code, buffer) do
46
- buffer << "{%= tag."
47
- buffer << code
67
+ tag_name, space, params = code.lstrip.partition(%r(\s)m)
68
+
69
+ if tag_name.end_with?(":")
70
+ tag_name.chomp!(":")
71
+ tag_name = ":#{tag_name}" unless tag_name.start_with?(":")
72
+ end
73
+
74
+ buffer << "{%= tag.tag_string "
75
+ buffer << tag_name << ", " << params
48
76
  buffer << " %}"
49
77
  end
50
78
 
@@ -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,11 @@ 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
47
+ end,
48
+ "`" => ->(code, buffer) do
49
+ buffer << "{%= %`"
50
+ buffer << code.gsub(%r("([^\\]?)\#{(.*?)}"), "\"\\1\#{h(\\2)}\"")
51
+ buffer << ".strip %}"
51
52
  end
52
53
  }
53
54
  end
@@ -55,30 +56,21 @@ module Serbea
55
56
  def self.front_matter_preamble=(varname)
56
57
  @front_matter_preamble = varname
57
58
  end
59
+
58
60
  def self.front_matter_preamble
59
61
  @front_matter_preamble ||= "frontmatter = YAML.load"
60
62
  end
61
-
63
+
62
64
  def self.has_yaml_header?(template)
63
65
  template.lines.first&.match? %r!\A---\s*\r?\n!
64
66
  end
65
-
67
+
66
68
  def initialize(input, properties={})
67
69
  properties[:regexp] = /{%(={1,2}|-|\#|%)?(.*?)([-=])?%}([ \t]*\r?\n)?/m
68
70
  properties[:strip_front_matter] = true unless properties.key?(:strip_front_matter)
69
71
  super process_serbea_input(input, properties), properties
70
72
  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
-
73
+
82
74
  def process_serbea_input(template, properties)
83
75
  buff = ""
84
76
 
@@ -180,7 +172,7 @@ module Serbea
180
172
  string = buff
181
173
  buff = ""
182
174
  until string.empty?
183
- text, code, string = string.partition(/{%@([a-z_]+)?(.*?)%}/m)
175
+ text, code, string = string.partition(/{%@([a-z_`]+)?(.*?)%}/m)
184
176
 
185
177
  buff << text
186
178
  if code.length > 0
@@ -190,7 +182,11 @@ module Serbea
190
182
  directive = $1 ? self.class.directives[$1] : self.class.directives["@"]
191
183
 
192
184
  if directive
185
+ additional_length = "#{buff}#{code}".lines.size
193
186
  directive.(code, buff)
187
+ (additional_length - buff.lines.size).times do
188
+ buff << "{% %}\n" # preserve original directive line length
189
+ end
194
190
  else
195
191
  raise "Handler for Serbea template directive `#{$1}' not found"
196
192
  end
@@ -202,7 +198,7 @@ module Serbea
202
198
 
203
199
  buff
204
200
  end
205
-
201
+
206
202
  private
207
203
 
208
204
  def add_code(code)
@@ -226,5 +222,15 @@ module Serbea
226
222
  def add_expression_result_escaped(code)
227
223
  add_expression_result(code)
228
224
  end
229
- end # class
225
+
226
+ def add_postamble(postamble)
227
+ src << postamble
228
+ src << "#{@bufvar}.html_safe"
229
+
230
+ src.gsub!("__RAW_START_PRINT__", "{{")
231
+ src.gsub!("__RAW_END_PRINT__", "}}")
232
+ src.gsub!("__RAW_START_EVAL__", "{%")
233
+ src.gsub!("__RAW_END_EVAL__", "%}")
234
+ end
235
+ end
230
236
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.10.3"
2
+ VERSION = "0.11.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.10.3
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-03 00:00:00.000000000 Z
11
+ date: 2021-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '13.0'
83
- description:
83
+ description:
84
84
  email: maintainers@bridgetownrb.com
85
85
  executables: []
86
86
  extensions: []
@@ -88,8 +88,35 @@ extra_rdoc_files: []
88
88
  files:
89
89
  - ".gitignore"
90
90
  - Gemfile
91
+ - LICENSE.txt
91
92
  - README.md
92
93
  - Rakefile
94
+ - docs/.gitignore
95
+ - docs/Gemfile
96
+ - docs/bridgetown.config.yml
97
+ - docs/frontend/javascript/index.js
98
+ - docs/frontend/styles/index.scss
99
+ - docs/package.json
100
+ - docs/plugins/builders/.keep
101
+ - docs/plugins/site_builder.rb
102
+ - docs/src/404.html
103
+ - docs/src/_components/footer.liquid
104
+ - docs/src/_components/head.liquid
105
+ - docs/src/_components/navbar.liquid
106
+ - docs/src/_data/site_metadata.yml
107
+ - docs/src/_layouts/default.liquid
108
+ - docs/src/_layouts/home.liquid
109
+ - docs/src/_layouts/page.liquid
110
+ - docs/src/_layouts/post.liquid
111
+ - docs/src/favicon.ico
112
+ - docs/src/images/.keep
113
+ - docs/src/images/serbea-logomark.svg
114
+ - docs/src/images/serbea-logotype.svg
115
+ - docs/src/index.md
116
+ - docs/start.js
117
+ - docs/sync.js
118
+ - docs/webpack.config.js
119
+ - docs/yarn.lock
93
120
  - lib/serbea.rb
94
121
  - lib/serbea/bridgetown_support.rb
95
122
  - lib/serbea/helpers.rb
@@ -103,7 +130,7 @@ homepage: https://github.com/bridgetownrb/serbea
103
130
  licenses:
104
131
  - MIT
105
132
  metadata: {}
106
- post_install_message:
133
+ post_install_message:
107
134
  rdoc_options: []
108
135
  require_paths:
109
136
  - lib
@@ -118,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
145
  - !ruby/object:Gem::Version
119
146
  version: '0'
120
147
  requirements: []
121
- rubygems_version: 3.0.6
122
- signing_key:
148
+ rubygems_version: 3.2.3
149
+ signing_key:
123
150
  specification_version: 4
124
151
  summary: Similar to ERB, Except Awesomer
125
152
  test_files: []