serbea 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 994c7c8ba16f125d6f006e9abeb0a076eb7591ff36232037135c75c79f7c0d1d
4
- data.tar.gz: e5f2e543e4a0ea5f31e0ee53a2d170b9d4f7a0a6084be366b6d0f86f498708f3
3
+ metadata.gz: 212a077a67f1553dc07fc8dd1b989647e19803953fba03976ec9ef95e08a2321
4
+ data.tar.gz: feda65d983102a217bd8426a8404712f882f23d2c6c3fa4be1981518fb20aae4
5
5
  SHA512:
6
- metadata.gz: 634dd9112de1516e8ca87830a8af55ebee81c3c2d42457238388867db8b774b7672f7efe7fc2606da9f727a851d4addebc314950d6162126344f73d1bcbc2c8c
7
- data.tar.gz: aceefb2271b2bf7f653b79386f5842df7b688114a4766d202b66ed0f6307e794f073c191ad693e8962ea1682b2e948efc2bc638b898c16a673fb8454eeb8482f
6
+ metadata.gz: 94edc63cbeb21ce38db5ab1270c2b06f5479d5fd529ea12ccca68d69d6abe7fece8dc83cbfeeeba8e724b4fa7c165f831b23d6059bccd9aef022bc6d6545f16d
7
+ data.tar.gz: b10964bcc171ff4903ae5b98dea1db73b0f21f95a1bbb02027681a84e0834c7838ad3901e00a740586844fc4bf5be78d5d00fc5710e0c310f2bacf44026956db
@@ -42,9 +42,17 @@ Serbea::TemplateEngine.directive :form, ->(code, buffer) do
42
42
  buffer << code
43
43
  buffer << " %}"
44
44
  end
45
+
45
46
  Serbea::TemplateEngine.directive :_, ->(code, buffer) do
46
- buffer << "{%= tag."
47
- buffer << code
47
+ tag_name, space, params = code.lstrip.partition(%r(\s)m)
48
+
49
+ if tag_name.end_with?(":")
50
+ tag_name.chomp!(":")
51
+ tag_name = ":#{tag_name}" unless tag_name.start_with?(":")
52
+ end
53
+
54
+ buffer << "{%= tag.tag_string "
55
+ buffer << tag_name << ", " << params
48
56
  buffer << " %}"
49
57
  end
50
58
 
@@ -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.3"
2
+ VERSION = "0.10.4"
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.10.4
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-03 00:00:00.000000000 Z
11
+ date: 2020-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport