serbea 0.3.5 → 0.4.0

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: 3aedaea6776741f8b501ad554019405c093c28947b810d44a1647424206b6cd8
4
- data.tar.gz: 95b6936d84b60f31cacccde7b4213623bb03789d97fc9b07afa0dc2e76e1d27b
3
+ metadata.gz: 18caf5a2b809d0cf64dc3d6ed6b05186ec6c1cdbb6faf4c3c8f01ec607f65918
4
+ data.tar.gz: f94c3df3de70cbfbac1cd481ee41706beff8a0cfc78a23ee54b13ec4345d39fe
5
5
  SHA512:
6
- metadata.gz: bd51862c6db8dc1bac37d6dded1e3f08d8f7cc9e8787011c4eddb44cc62799df80fb1fb16aafcab7a00f696b1fcd57f2872bb6dfc12a5104b3b34c2948d34955
7
- data.tar.gz: f45b665cb6b684892ce792c91b1f14f59f7af33364875eddc7a4b0eb34f2b8e771cce1d1b0ad99aee06fc49dc3f1d6c8a2176118fc0685dde5d3892ce927d93b
6
+ metadata.gz: 27f9d07b128e5b7537be078b8056add0da4caed1304375a3f2decbd00d14232a60ade8d07817f7c520f2479f78957aff9774ba980391edd4643bb1c4b72454b2
7
+ data.tar.gz: dfe541a83671109526c0b9069ef2054dfb9a57c21474180d572ccba8cfcf13b3b59cab5a58e3e9b70e3952ca00ff46ab239a0fdf5f260a07e7956d646ef059b9
@@ -1,7 +1,7 @@
1
1
  module Serbea
2
2
  module Helpers
3
3
  def self.included(mod)
4
- Serbea::Pipeline.deny_value_method %i(escape h prepend append map assign_to)
4
+ Serbea::Pipeline.deny_value_method %i(escape h prepend append assign_to)
5
5
  end
6
6
 
7
7
  def capture(obj=nil)
@@ -34,10 +34,6 @@ module Serbea
34
34
  "#{old_string}#{new_string}"
35
35
  end
36
36
 
37
- def map(input, block)
38
- input.map(&block)
39
- end
40
-
41
37
  def assign_to(input, varname, preserve: false)
42
38
  self.instance_variable_set("@#{varname}", input)
43
39
  preserve ? input : nil
@@ -1,5 +1,27 @@
1
1
  module Serbea
2
2
  class Pipeline
3
+ def self.exec(template, input: (no_input_passed = true; nil), include_helpers: nil)
4
+ anon = Class.new do
5
+ include Serbea::Helpers
6
+
7
+ attr_accessor :input, :output
8
+ end
9
+
10
+ if include_helpers
11
+ anon.include include_helpers
12
+ end
13
+
14
+ pipeline_obj = anon.new
15
+ pipeline_obj.input = input unless no_input_passed
16
+
17
+ full_template = "{{ #{template} | assign_to: :output }}"
18
+
19
+ tmpl = Tilt::SerbeaTemplate.new { full_template }
20
+ tmpl.render(pipeline_obj)
21
+
22
+ pipeline_obj.output
23
+ end
24
+
3
25
  def self.output_processor=(processor)
4
26
  @output_processor = processor
5
27
  end
@@ -22,11 +44,30 @@ module Serbea
22
44
  @value = value
23
45
  end
24
46
 
25
- def filter(name, *args)
47
+ # TODO: clean this up somehow and still support Ruby 2.5..3.0!
48
+ def filter(name, *args, **kwargs)
26
49
  if @value.respond_to?(name) && !self.class.value_methods_denylist.include?(name)
27
- @value = @value.send(name, *args)
50
+ if args.last.is_a?(Proc)
51
+ real_args = args.take(args.length - 1)
52
+ block = args.last
53
+ unless kwargs.empty?
54
+ @value = @value.send(name, *real_args, **kwargs, &block)
55
+ else
56
+ @value = @value.send(name, *real_args, &block)
57
+ end
58
+ else
59
+ unless kwargs.empty?
60
+ @value = @value.send(name, *args, **kwargs)
61
+ else
62
+ @value = @value.send(name, *args)
63
+ end
64
+ end
28
65
  elsif @context.respond_to?(name)
29
- @value = @context.send(name, @value, *args)
66
+ unless kwargs.empty?
67
+ @value = @context.send(name, @value, *args, **kwargs)
68
+ else
69
+ @value = @context.send(name, @value, *args)
70
+ end
30
71
  else
31
72
  "Serbea warning: Filter not found: #{name}".tap do |warning|
32
73
  raise_on_missing_filters ? raise(warning) : STDERR.puts(warning)
@@ -8,6 +8,13 @@ module Serbea
8
8
  def self.render_directive
9
9
  @render_directive ||= "render"
10
10
  end
11
+
12
+ def self.front_matter_preamble=(varname)
13
+ @front_matter_preamble = varname
14
+ end
15
+ def self.front_matter_preamble
16
+ @front_matter_preamble ||= "frontmatter = YAML.load"
17
+ end
11
18
 
12
19
  def self.has_yaml_header?(template)
13
20
  template.lines.first&.match? %r!\A---\s*\r?\n!
@@ -35,7 +42,13 @@ module Serbea
35
42
  string = template.dup
36
43
  if properties[:strip_front_matter] && self.class.has_yaml_header?(string)
37
44
  if string = string.match(FRONT_MATTER_REGEXP)
38
- string = ("{%#%}\n" * string.to_s.lines.count) + string.post_match
45
+ require "yaml" if self.class.front_matter_preamble.include?(" = YAML.load")
46
+
47
+ string = "{% #{self.class.front_matter_preamble} <<~YAMLDATA\n" +
48
+ string[1].sub(/^---\n/,'') +
49
+ "YAMLDATA\n%}" +
50
+ string[2].sub(/^---\n/, '') +
51
+ string.post_match
39
52
  end
40
53
  end
41
54
 
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.3.5"
2
+ VERSION = "0.4.0"
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.5
4
+ version: 0.4.0
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-29 00:00:00.000000000 Z
11
+ date: 2020-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi