serbea 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +11 -0
- data/lib/serbea/helpers.rb +1 -1
- data/lib/serbea/pipeline.rb +34 -4
- data/lib/serbea/template_engine.rb +1 -1
- data/lib/serbea.rb +6 -0
- data/lib/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1afdeb44daa8b1b9cd20c73ec82ebd02defc8d7322247cdc65870279b380450
|
4
|
+
data.tar.gz: 9e7371768fd0cab610e26c9b15020d6320d3d8f78a9f805e56c08d3dcec26ddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 352d91c0845ee77c0fc4cbea9953f3d9f63fcc230ad2f6f9fc52cbba64bd6da409482a6e2c5e032c39f853acd1c0f62042869a13f9a34a88c74387825b433fc1
|
7
|
+
data.tar.gz: fde8baf367844161f6f6afcd10c29450673d56871e67949cb831f0d7c86b2a163b644a80e171ffa4d0a104ef549cfa7201dacf7ea6d6522305bfc6aa82ca8ffc
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.2
|
data/CHANGELOG.md
ADDED
data/lib/serbea/helpers.rb
CHANGED
@@ -30,7 +30,7 @@ module Serbea
|
|
30
30
|
def import(*args, **kwargs, &block)
|
31
31
|
helper_names = %i(partial render)
|
32
32
|
available_helper = helper_names.find { |meth| respond_to?(meth) }
|
33
|
-
raise "Serbea Error: no `render' or `partial' helper available in #{self.class}" unless available_helper
|
33
|
+
raise Serbea::Error, "Serbea Error: no `render' or `partial' helper available in #{self.class}" unless available_helper
|
34
34
|
available_helper == :partial ? partial(*args, **kwargs, &block) : render(*args, **kwargs, &block)
|
35
35
|
nil
|
36
36
|
end
|
data/lib/serbea/pipeline.rb
CHANGED
@@ -4,6 +4,17 @@ require "active_support/core_ext/object/blank"
|
|
4
4
|
|
5
5
|
module Serbea
|
6
6
|
class Pipeline
|
7
|
+
# If you include this in any regular Ruby template environment (say ERB),
|
8
|
+
# you can then use Serbea-style pipeline code within the block, e.g.
|
9
|
+
#
|
10
|
+
# `pipe "Hello world" do upcase | split(" ") | join(", ") end`
|
11
|
+
# => `HELLO, WORLD`
|
12
|
+
module Helper
|
13
|
+
def pipe(input = nil, &blk)
|
14
|
+
Pipeline.new(binding, input).tap { _1.instance_exec(&blk) }.value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
7
18
|
# Exec the pipes!
|
8
19
|
# @param template [String]
|
9
20
|
# @param locals [Hash]
|
@@ -85,13 +96,13 @@ module Serbea
|
|
85
96
|
if var.respond_to?(:call)
|
86
97
|
@value = var.call(@value, *args, **kwargs)
|
87
98
|
else
|
88
|
-
"Serbea warning: Filter #{name} does not respond to call".tap do |warning|
|
89
|
-
self.class.raise_on_missing_filters ? raise(warning) : STDERR.puts(warning)
|
99
|
+
"Serbea warning: Filter '#{name}' does not respond to call".tap do |warning|
|
100
|
+
self.class.raise_on_missing_filters ? raise(Serbea::FilterMissing, warning) : STDERR.puts(warning)
|
90
101
|
end
|
91
102
|
end
|
92
103
|
else
|
93
|
-
"Serbea warning: Filter not found
|
94
|
-
self.class.raise_on_missing_filters ? raise(warning) : STDERR.puts(warning)
|
104
|
+
"Serbea warning: Filter `#{name}' not found".tap do |warning|
|
105
|
+
self.class.raise_on_missing_filters ? raise(Serbea::FilterMissing, warning) : STDERR.puts(warning)
|
95
106
|
end
|
96
107
|
end
|
97
108
|
|
@@ -101,5 +112,24 @@ module Serbea
|
|
101
112
|
def to_s
|
102
113
|
self.class.output_processor.call(@value.is_a?(String) ? @value : @value.to_s)
|
103
114
|
end
|
115
|
+
|
116
|
+
def |(*)
|
117
|
+
self
|
118
|
+
end
|
119
|
+
|
120
|
+
def method_missing(...)
|
121
|
+
filter(...)
|
122
|
+
end
|
123
|
+
|
124
|
+
def value(callback = nil)
|
125
|
+
return @value unless callback
|
126
|
+
|
127
|
+
@value = if callback.is_a?(Proc)
|
128
|
+
callback.(@value)
|
129
|
+
else
|
130
|
+
callback
|
131
|
+
end
|
132
|
+
self
|
133
|
+
end
|
104
134
|
end
|
105
135
|
end
|
@@ -188,7 +188,7 @@ module Serbea
|
|
188
188
|
buff << "{% %}\n" # preserve original directive line length
|
189
189
|
end
|
190
190
|
else
|
191
|
-
raise "Handler for Serbea template directive `#{$1}' not found"
|
191
|
+
raise Serbea::Error, "Handler for Serbea template directive `#{$1}' not found"
|
192
192
|
end
|
193
193
|
else
|
194
194
|
buff << "{% end %}"
|
data/lib/serbea.rb
CHANGED
data/lib/version.rb
CHANGED
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:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2023-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -74,6 +74,8 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- ".github/workflows/ci.yml"
|
76
76
|
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- CHANGELOG.md
|
77
79
|
- Gemfile
|
78
80
|
- LICENSE.txt
|
79
81
|
- README.md
|