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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b747bafc667c67c0826b3cbe2c979825df89174d43a3a617780eaec53da6a059
4
- data.tar.gz: 7b359e8cd5faa91971c58974bd2be1daa89dcd666d55a4430bf3a3f3ffd57dd0
3
+ metadata.gz: d1afdeb44daa8b1b9cd20c73ec82ebd02defc8d7322247cdc65870279b380450
4
+ data.tar.gz: 9e7371768fd0cab610e26c9b15020d6320d3d8f78a9f805e56c08d3dcec26ddd
5
5
  SHA512:
6
- metadata.gz: 68a4dce4eb9edafc3fcf3f127421889188d5d4d2bc10b20bd16b48c053baeb2be00ee3cea3ff04d0cc82a764036ef853cd655e47001145f459c9f6745f6e8e89
7
- data.tar.gz: 55e7eb37b580e4c3b2998d52e938fc79fe58db94c7e8e3522b278471e7a971070adfc94b51ff82c54646b584c61a368d41604cd35d6c4edc131a1b2434e48fc2
6
+ metadata.gz: 352d91c0845ee77c0fc4cbea9953f3d9f63fcc230ad2f6f9fc52cbba64bd6da409482a6e2c5e032c39f853acd1c0f62042869a13f9a34a88c74387825b433fc1
7
+ data.tar.gz: fde8baf367844161f6f6afcd10c29450673d56871e67949cb831f0d7c86b2a163b644a80e171ffa4d0a104ef549cfa7201dacf7ea6d6522305bfc6aa82ca8ffc
data/.gitignore CHANGED
@@ -15,7 +15,6 @@ mkmf.log
15
15
  *.gem
16
16
  Gemfile.lock
17
17
  .bundle
18
- .ruby-version
19
18
 
20
19
  # Mac files
21
20
  .DS_Store
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 2.0.0
4
+
5
+ - Add plain ol' Ruby pipeline functionality
6
+ - Raise errors using gem-based classes
7
+ - Upgrade docs site to Bridgetown 1.3.1 and esbuild
8
+
9
+ ## 1.0.1
10
+
11
+ - Widespread release.
@@ -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
@@ -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: #{name}".tap do |warning|
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
@@ -1,6 +1,12 @@
1
1
  require "tilt"
2
2
  require "tilt/erubi"
3
3
 
4
+ module Serbea
5
+ class Error < StandardError; end
6
+
7
+ class FilterMissing < Error; end
8
+ end
9
+
4
10
  require "serbea/helpers"
5
11
  require "serbea/pipeline"
6
12
  require "serbea/template_engine"
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.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: 1.0.1
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: 2021-11-12 00:00:00.000000000 Z
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