superfluid 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0c3710ceb5f8e3d5869d8ddc3a3d9fde8291132cf94ebe7eb72cf71326d6a57
4
- data.tar.gz: 90fa8ae9ece1ad2021cd0e8e58d3ab2f341d4c32f428bf21c02baa7c6dbea758
3
+ metadata.gz: 55e3fbd59c2ab1e4e156c0777f74eec2e15e6a12224c133fc606592218057a03
4
+ data.tar.gz: 16bd7bee4a6913a4f334cc0f3118cd3b0bb3c363e4b68d8275a6ce654d4c632a
5
5
  SHA512:
6
- metadata.gz: b18219cf36cb6c2b55be26c2b5d587cec0c04ed44337a7615ba5c094f99a20e6453497211c7012755ad699494feb368f4d7e34a4e22ef7b367599dd57257795f
7
- data.tar.gz: 7581feaf8567ec6fffee1aa3096a2d490fd864847445f0af9ab4cc82db1cb64622c192dd19395f07f0eaf57ce661046cf857693165bbb07b2dff774f668e12ef
6
+ metadata.gz: ad32e7c1058088116af46a180051dd751a378c9d9f82e99afa938a863c52be60650368fc5d3e31e8784390f481fb474629fc62cf2c2429ce1b423cd940ecc820
7
+ data.tar.gz: 4d2d1e4735b8c28fc32c9a6bcce2e6cdd7bb41801fd851ca316a1b2e2bd46203fc9b63fc64f8cb434a6cc126ff23da6242bc617bb48669c9c473ee3f73371495
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -6,7 +6,7 @@
6
6
  :containable_link: link:https://alchemists.io/projects/containable[Containable]
7
7
  :core_link: link:https://alchemists.io/projects/core[Core]
8
8
  :functionable_link: link:https://alchemists.io/projects/functionable[Functionable]
9
- :liquid_link: link:https://shopify.github.io/liquid/[Liquid]
9
+ :liquid_link: link:https://shopify.github.io/liquid[Liquid]
10
10
  :struct_link: link:https://alchemists.io/articles/ruby_structs[Struct]
11
11
 
12
12
  = Superfluid
@@ -220,6 +220,32 @@ environment.filter_registry.names
220
220
 
221
221
  The above will produce a list of all registered filters. These including all filters provided by {liquid_link} and those unique to this gem which are:
222
222
 
223
+ ===== `append`
224
+
225
+ Renders a suffix appended to a `String` or `Array`. This also overrides and enhances the default {liquid_link} filter of the same name. Example:
226
+
227
+ *Array*
228
+
229
+ [source,ruby]
230
+ ----
231
+ renderer.call(%({{ data | append: "three" }}), {"data" => %w[one two]})
232
+ # "onetwothree"
233
+
234
+ renderer.call(%({{ data | append: suffix }}), {"data" => %w[one two], "suffix" => "three"})
235
+ # "onetwothree"
236
+ ----
237
+
238
+ *String*
239
+
240
+ [source,ruby]
241
+ ----
242
+ renderer.call %({{ "demo" | append: " suffix" }})
243
+ # "demo suffix"
244
+
245
+ renderer.call(%({{ "demo" | append: suffix }}), {"suffix" => " suffix"})
246
+ # "demo suffix"
247
+ ----
248
+
223
249
  ===== `jsonify`
224
250
 
225
251
  Renders objects as JSON. Example:
@@ -263,6 +289,32 @@ renderer.call(%({{ text | pluralize: 3, "i", "us" }}), {"text" => "octopus"})
263
289
  # "3 octopi"
264
290
  ----
265
291
 
292
+ ===== `prepend`
293
+
294
+ Renders a prefix prepended to a `String` or `Array`. This also overrides and enhances the default {liquid_link} filter of the same name. Example:
295
+
296
+ *Array*
297
+
298
+ [source,ruby]
299
+ ----
300
+ renderer.call(%({{ data | prepend: "one" }}), {"data" => %w[two three]})
301
+ # "onetwothree"
302
+
303
+ renderer.call(%({{ data | prepend: prefix }}), {"data" => %w[two three], "prefix" => "one"})
304
+ # "onetwothree"
305
+ ----
306
+
307
+ *String*
308
+
309
+ [source,ruby]
310
+ ----
311
+ renderer.call %({{ "demo" | prepend: "prefix " }})
312
+ # "prefix demo"
313
+
314
+ renderer.call(%({{ "demo" | prepend: prefix }}), {"prefix" => "prefix "})
315
+ # "demo prefix"
316
+ ----
317
+
266
318
  ===== `singularize`
267
319
 
268
320
  Renders a singular string. Example:
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superfluid
4
+ # Custom filters.
5
+ module Filters
6
+ require "functionable"
7
+
8
+ # Shared primitive behavior.
9
+ module Common
10
+ extend Functionable
11
+
12
+ def append target, suffix
13
+ case target
14
+ when Array then target.dup.append suffix
15
+ when String then "#{target}#{suffix}"
16
+ else fail Liquid::ArgumentError, "Unsupported type: #{target.class}."
17
+ end
18
+ end
19
+
20
+ def prepend target, prefix
21
+ case target
22
+ when Array then target.dup.prepend prefix
23
+ when String then "#{prefix}#{target}"
24
+ else fail Liquid::ArgumentError, "Unsupported type: #{target.class}."
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -9,7 +9,7 @@ module Superfluid
9
9
  module Filters
10
10
  # A container of filter dependencies.
11
11
  module Container
12
- extend Containable
12
+ extend Containable[register: Register]
13
13
 
14
14
  using Refinements::String
15
15
 
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "containable"
4
+
5
+ module Superfluid
6
+ # A custom register which allows key overrides.
7
+ class Register < Containable::Register
8
+ def call key, value = nil, as: :cache, &block
9
+ dependencies[namespacify(key)] = [block || value, as]
10
+ end
11
+ end
12
+ end
@@ -10,12 +10,12 @@ module Superfluid
10
10
  attr_reader :mode
11
11
 
12
12
  def initialize container = Filters::Container,
13
- defaults: Liquid::StandardFilters,
13
+ defaults: [Liquid::StandardFilters, Filters::Common],
14
14
  mode: :strict
15
15
  @container = container
16
16
  @mode = mode
17
17
 
18
- add defaults
18
+ add(*defaults)
19
19
  end
20
20
 
21
21
  def add(*, **)
@@ -80,8 +80,6 @@ module Superfluid
80
80
  def add_commands(**collection) = collection.each { |name, command| add_command name, command }
81
81
 
82
82
  def add_command name, callable
83
- return if container.key? name
84
-
85
83
  case callable
86
84
  in Proc | Method | Core::Composable then container.register(name) { callable }
87
85
  else fail Liquid::ArgumentError, "Filter must be callable."
@@ -6,7 +6,7 @@ module Superfluid
6
6
  module Tags
7
7
  # A container of tag dependencies.
8
8
  module Container
9
- extend Containable
9
+ extend Containable[register: Register]
10
10
 
11
11
  register :template, Template
12
12
  end
data/superfluid.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "superfluid"
5
- spec.version = "0.2.1"
5
+ spec.version = "0.3.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/superfluid"
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superfluid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -146,7 +146,9 @@ files:
146
146
  - lib/superfluid.rb
147
147
  - lib/superfluid/configuration.rb
148
148
  - lib/superfluid/environment.rb
149
+ - lib/superfluid/filters/common.rb
149
150
  - lib/superfluid/filters/container.rb
151
+ - lib/superfluid/register.rb
150
152
  - lib/superfluid/registries/filter.rb
151
153
  - lib/superfluid/registries/tag.rb
152
154
  - lib/superfluid/renderer.rb
@@ -179,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
181
  - !ruby/object:Gem::Version
180
182
  version: '0'
181
183
  requirements: []
182
- rubygems_version: 4.0.23
184
+ rubygems_version: 4.0.24
183
185
  specification_version: 4
184
186
  summary: Enhances Liquid with object composition and functional design.
185
187
  test_files: []
metadata.gz.sig CHANGED
Binary file