serbea 0.3.0 → 0.3.5

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: 170e76b3b2d6c6024d9721f95831ebc85dd32fda2bca10f2471546bbc95cc5f7
4
- data.tar.gz: 5dc3336c8549c6933325646f5a3fecdee6fec520393df8e141f86a3ef4b3f0ae
3
+ metadata.gz: 3aedaea6776741f8b501ad554019405c093c28947b810d44a1647424206b6cd8
4
+ data.tar.gz: 95b6936d84b60f31cacccde7b4213623bb03789d97fc9b07afa0dc2e76e1d27b
5
5
  SHA512:
6
- metadata.gz: a8733456977f41a78a2e4a56bd8d25a4b737abdedf54d19cfbf7ad61f43a9edbbd422e1d81206205df366ef56d751567a87284de9c480887a79cefb0ae51ae1c
7
- data.tar.gz: 57c097000a365d52fa0ee88ca8472957dccbfc898b2acb6d066f3fea49e865f94033cfcb30b9edc6585a1fb72ab191b524fb631c437b86a16c2a707e078b85ca
6
+ metadata.gz: bd51862c6db8dc1bac37d6dded1e3f08d8f7cc9e8787011c4eddb44cc62799df80fb1fb16aafcab7a00f696b1fcd57f2872bb6dfc12a5104b3b34c2948d34955
7
+ data.tar.gz: f45b665cb6b684892ce792c91b1f14f59f7af33364875eddc7a4b0eb34f2b8e771cce1d1b0ad99aee06fc49dc3f1d6c8a2176118fc0685dde5d3892ce927d93b
@@ -3,9 +3,9 @@ require "tilt/erubi"
3
3
  require "erubi/capture_end"
4
4
 
5
5
  require "serbea/helpers"
6
- require "serbea/component_renderer"
7
6
  require "serbea/pipeline"
8
7
  require "serbea/template_engine"
8
+ require "serbea/component_renderer"
9
9
 
10
10
  module Tilt
11
11
  class SerbeaTemplate < ErubiTemplate
@@ -1,5 +1,9 @@
1
1
  module Serbea
2
2
  module Helpers
3
+ def self.included(mod)
4
+ Serbea::Pipeline.deny_value_method %i(escape h prepend append map assign_to)
5
+ end
6
+
3
7
  def capture(obj=nil)
4
8
  previous_buffer_state = @_erbout
5
9
  @_erbout = +""
@@ -21,5 +25,22 @@ module Serbea
21
25
  Erubi.h(input)
22
26
  end
23
27
  alias_method :escape, :h
28
+
29
+ def prepend(old_string, new_string)
30
+ "#{new_string}#{old_string}"
31
+ end
32
+
33
+ def append(old_string, new_string)
34
+ "#{old_string}#{new_string}"
35
+ end
36
+
37
+ def map(input, block)
38
+ input.map(&block)
39
+ end
40
+
41
+ def assign_to(input, varname, preserve: false)
42
+ self.instance_variable_set("@#{varname}", input)
43
+ preserve ? input : nil
44
+ end
24
45
  end
25
46
  end
@@ -10,19 +10,26 @@ module Serbea
10
10
  end
11
11
  end
12
12
 
13
+ def self.deny_value_method(name)
14
+ value_methods_denylist.merge Array(name)
15
+ end
16
+ def self.value_methods_denylist
17
+ @value_methods_denylist ||= Set.new
18
+ end
19
+
13
20
  def initialize(context, value)
14
21
  @context = context
15
22
  @value = value
16
23
  end
17
24
 
18
- def filter(sym, *aargs)
19
- if @value.respond_to?(sym)
20
- @value = @value.send(sym, *aargs)
21
- elsif @context.respond_to?(sym)
22
- @value = @context.send(sym, @value, *aargs)
25
+ def filter(name, *args)
26
+ if @value.respond_to?(name) && !self.class.value_methods_denylist.include?(name)
27
+ @value = @value.send(name, *args)
28
+ elsif @context.respond_to?(name)
29
+ @value = @context.send(name, @value, *args)
23
30
  else
24
- "Serbea warning: Filter not found: #{sym}".tap do |warning|
25
- raise_on_missing_filters ? raise(warning) : puts(warning)
31
+ "Serbea warning: Filter not found: #{name}".tap do |warning|
32
+ raise_on_missing_filters ? raise(warning) : STDERR.puts(warning)
26
33
  end
27
34
  end
28
35
 
@@ -35,8 +35,7 @@ module Serbea
35
35
  string = template.dup
36
36
  if properties[:strip_front_matter] && self.class.has_yaml_header?(string)
37
37
  if string = string.match(FRONT_MATTER_REGEXP)
38
- string = string.post_match
39
- # yaml_data = SafeYAML.load(template.captures[0])
38
+ string = ("{%#%}\n" * string.to_s.lines.count) + string.post_match
40
39
  end
41
40
  end
42
41
 
@@ -56,7 +55,7 @@ module Serbea
56
55
  end
57
56
  end
58
57
 
59
- # Process the pipeline outputs
58
+ # Process any pipelines
60
59
  string = buff
61
60
  buff = ""
62
61
  until string.empty?
@@ -68,7 +67,7 @@ module Serbea
68
67
 
69
68
  code = code.gsub('\|', "__PIPE_C__")
70
69
 
71
- subs = code.gsub(/\s*\|\s+(.*?)\s([^|}]*)/) do
70
+ subs = code.gsub(/\s*\|>?\s+(.*?)\s([^|}]*)/) do
72
71
  args = $2
73
72
  args = nil if args.strip == ""
74
73
  prefix = processed_filters ? ")" : "))"
@@ -82,7 +81,15 @@ module Serbea
82
81
  end
83
82
  end
84
83
 
85
- # Process the render directives
84
+ # Process any directives
85
+ #
86
+ # TODO: allow custom directives! aka
87
+ # {%@something whatever %}
88
+ # {%@script
89
+ # const foo = "really? #{really}!"
90
+ # alert(foo.toLowerCase())
91
+ # %}
92
+ # {%@preact AwesomeChart data={#{ruby_data.to_json}} %}
86
93
  string = buff
87
94
  buff = ""
88
95
  until string.empty?
@@ -100,8 +107,17 @@ module Serbea
100
107
  else # string or something else
101
108
  pieces[0].prepend "("
102
109
  end
103
- if pieces.last == "do"
104
- pieces.last.prepend ") "
110
+
111
+ includes_block = false
112
+ pieces.reverse.each do |piece|
113
+ if piece == "do" && (pieces.last == "do" || pieces.last.end_with?("|"))
114
+ piece.prepend(") ")
115
+ includes_block = true
116
+ break
117
+ end
118
+ end
119
+
120
+ if includes_block
105
121
  buff << "{%:= #{self.class.render_directive}#{pieces.join(" ")} %}"
106
122
  else
107
123
  pieces.last << ")"
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.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.3.0
4
+ version: 0.3.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-09-22 00:00:00.000000000 Z
11
+ date: 2020-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi