serbea 1.0.1 → 2.1.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.gitignore +0 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +18 -0
- data/lib/serbea/helpers.rb +15 -4
- data/lib/serbea/pipeline.rb +36 -8
- data/lib/serbea/template_engine.rb +1 -1
- data/lib/serbea.rb +6 -0
- data/lib/version.rb +1 -1
- data/serbea.gemspec +0 -1
- metadata +4 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbaec081de265cae08c41dbcbfe2ea7686447ff169d8756f45ea446d756a4519
|
4
|
+
data.tar.gz: 40d58553c10c8c10299064ce1ae88a030b947ac6c0b92aea8e8c9282cca7ac16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4762251bb0285d122b59ac3611cbda5afdfedb6c075f97b2746456ce6be3fffd6362a82967d9bbedbc8fa092649f9e8240de293e58826dd79e4128be15c4922
|
7
|
+
data.tar.gz: 3e224dbdf536ac4f8207a217cb216151ce5609c3be8e984971470267cce69b7c1ab85fa3f6c88f95467fcc553d7f6f790ef5ba54563647203b114d4221a8800c
|
data/.github/workflows/ci.yml
CHANGED
@@ -13,7 +13,7 @@ jobs:
|
|
13
13
|
runs-on: ubuntu-latest
|
14
14
|
strategy:
|
15
15
|
matrix:
|
16
|
-
ruby_version: [2.7.2, 3.0.0]
|
16
|
+
ruby_version: [2.7.2, 3.0.0, 3.2.0]
|
17
17
|
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
18
18
|
# Has to be top level to cache properly
|
19
19
|
env:
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 2.1.0
|
4
|
+
|
5
|
+
- Remove Active Support as a dependency
|
6
|
+
- This now provides rudimentary support of `html_safe` mechanics. Note that
|
7
|
+
it does NOT handle _any_ additional String methods. It simply allows cloning a string via `html_safe` to mark it safe, and `html_safe?` to query if it's safe.
|
8
|
+
- This _might_ be a breaking change, but likely not if you're using Serbea along with Rails or Bridgetown. To restore previous functionality manually, just install the `activesupport` gem and `require "active_support/core_ext/string/output_safety"` before you require the Serbea gem.
|
9
|
+
|
10
|
+
## 2.0.0
|
11
|
+
|
12
|
+
- Add plain ol' Ruby pipeline functionality
|
13
|
+
- Raise errors using gem-based classes
|
14
|
+
- Upgrade docs site to Bridgetown 1.3.1 and esbuild
|
15
|
+
|
16
|
+
## 1.0.1
|
17
|
+
|
18
|
+
- Widespread release.
|
data/lib/serbea/helpers.rb
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
|
1
|
+
unless "".respond_to?(:html_safe)
|
2
|
+
# The simplest HTML safety "polyfill" around
|
3
|
+
class String
|
4
|
+
def html_safe
|
5
|
+
self.class.new(self).tap { _1.instance_variable_set(:@html_safe, true) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def html_safe?
|
9
|
+
instance_variable_get(:@html_safe) == true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
2
13
|
|
3
14
|
module Serbea
|
4
15
|
module Helpers
|
@@ -10,7 +21,7 @@ module Serbea
|
|
10
21
|
previous_buffer_state = @_erbout
|
11
22
|
@_erbout = Serbea::OutputBuffer.new
|
12
23
|
result = yield(*args)
|
13
|
-
result = @_erbout.
|
24
|
+
result = @_erbout.empty? ? result : @_erbout
|
14
25
|
@_erbout = previous_buffer_state
|
15
26
|
|
16
27
|
Serbea::OutputBuffer === result ? result.html_safe : result
|
@@ -30,13 +41,13 @@ module Serbea
|
|
30
41
|
def import(*args, **kwargs, &block)
|
31
42
|
helper_names = %i(partial render)
|
32
43
|
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
|
44
|
+
raise Serbea::Error, "Serbea Error: no `render' or `partial' helper available in #{self.class}" unless available_helper
|
34
45
|
available_helper == :partial ? partial(*args, **kwargs, &block) : render(*args, **kwargs, &block)
|
35
46
|
nil
|
36
47
|
end
|
37
48
|
|
38
49
|
def h(input)
|
39
|
-
|
50
|
+
Erubi.h(input.to_s)
|
40
51
|
end
|
41
52
|
alias_method :escape, :h
|
42
53
|
|
data/lib/serbea/pipeline.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
require "set"
|
2
|
-
require "active_support/core_ext/string/output_safety"
|
3
|
-
require "active_support/core_ext/object/blank"
|
4
2
|
|
5
3
|
module Serbea
|
6
4
|
class Pipeline
|
5
|
+
# If you include this in any regular Ruby template environment (say ERB),
|
6
|
+
# you can then use Serbea-style pipeline code within the block, e.g.
|
7
|
+
#
|
8
|
+
# `pipe "Hello world" do upcase | split(" ") | join(", ") end`
|
9
|
+
# => `HELLO, WORLD`
|
10
|
+
module Helper
|
11
|
+
def pipe(input = nil, &blk)
|
12
|
+
Pipeline.new(binding, input).tap { _1.instance_exec(&blk) }.value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
7
16
|
# Exec the pipes!
|
8
17
|
# @param template [String]
|
9
18
|
# @param locals [Hash]
|
@@ -25,7 +34,7 @@ module Serbea
|
|
25
34
|
full_template = "{{ #{template} | assign_to: :output }}"
|
26
35
|
|
27
36
|
tmpl = Tilt::SerbeaTemplate.new { full_template }
|
28
|
-
tmpl.render(pipeline_obj, locals.
|
37
|
+
tmpl.render(pipeline_obj, locals.empty? ? kwargs : locals)
|
29
38
|
|
30
39
|
pipeline_obj.output
|
31
40
|
end
|
@@ -38,7 +47,7 @@ module Serbea
|
|
38
47
|
# @return [Proc]
|
39
48
|
def self.output_processor
|
40
49
|
@output_processor ||= lambda do |input|
|
41
|
-
(!input.html_safe? && self.autoescape) ?
|
50
|
+
(!input.html_safe? && self.autoescape) ? Erubi.h(input) : input.html_safe
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
@@ -85,13 +94,13 @@ module Serbea
|
|
85
94
|
if var.respond_to?(:call)
|
86
95
|
@value = var.call(@value, *args, **kwargs)
|
87
96
|
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)
|
97
|
+
"Serbea warning: Filter '#{name}' does not respond to call".tap do |warning|
|
98
|
+
self.class.raise_on_missing_filters ? raise(Serbea::FilterMissing, warning) : STDERR.puts(warning)
|
90
99
|
end
|
91
100
|
end
|
92
101
|
else
|
93
|
-
"Serbea warning: Filter not found
|
94
|
-
self.class.raise_on_missing_filters ? raise(warning) : STDERR.puts(warning)
|
102
|
+
"Serbea warning: Filter `#{name}' not found".tap do |warning|
|
103
|
+
self.class.raise_on_missing_filters ? raise(Serbea::FilterMissing, warning) : STDERR.puts(warning)
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
@@ -101,5 +110,24 @@ module Serbea
|
|
101
110
|
def to_s
|
102
111
|
self.class.output_processor.call(@value.is_a?(String) ? @value : @value.to_s)
|
103
112
|
end
|
113
|
+
|
114
|
+
def |(*)
|
115
|
+
self
|
116
|
+
end
|
117
|
+
|
118
|
+
def method_missing(...)
|
119
|
+
filter(...)
|
120
|
+
end
|
121
|
+
|
122
|
+
def value(callback = nil)
|
123
|
+
return @value unless callback
|
124
|
+
|
125
|
+
@value = if callback.is_a?(Proc)
|
126
|
+
callback.(@value)
|
127
|
+
else
|
128
|
+
callback
|
129
|
+
end
|
130
|
+
self
|
131
|
+
end
|
104
132
|
end
|
105
133
|
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
data/serbea.gemspec
CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|docs|serbea-rails)/!) }
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_runtime_dependency("activesupport", ">= 6.0")
|
20
19
|
spec.add_runtime_dependency("erubi", ">= 1.10")
|
21
20
|
spec.add_runtime_dependency("tilt", "~> 2.0")
|
22
21
|
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serbea
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.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-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '6.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '6.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: erubi
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +60,8 @@ extra_rdoc_files: []
|
|
74
60
|
files:
|
75
61
|
- ".github/workflows/ci.yml"
|
76
62
|
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- CHANGELOG.md
|
77
65
|
- Gemfile
|
78
66
|
- LICENSE.txt
|
79
67
|
- README.md
|