superfluid 0.1.0 → 0.2.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: 5048f50c8bdaff6ed69041a2c0fac3deaf00c77df45031249f4afdb2b1543279
4
- data.tar.gz: bd9a01bc4d9005f580e50970d9f3ba008ee0e3dc10ece706b8cc52a7a3120cef
3
+ metadata.gz: fe8974f8f93054605035f4adfc394fe98414fcec3c9db66b58fd957fedbc0797
4
+ data.tar.gz: 95af81f7354548f0a908c429704a2338faafd60bd427d843b3495d045b89835b
5
5
  SHA512:
6
- metadata.gz: 44aed258d521395ad2ec7352d26eda342f1262a56efdc3431f51a9f5ca59ed02601ae7d9a31cf72c2394d62c8cac7092a2d7e04228af63ed43d818db39928798
7
- data.tar.gz: 4a08908b8979771fe0dfe4840990764f1bd1f4bd9b0a1ff744f50f6e887586da19202241bf7b1bd722ef3959fdff11f6f7388c330f3bd7ae959bbf2f6654eddb
6
+ metadata.gz: 1890b05c7e813598d6aed1877b2ce863a31d832a36ff7feef458afc82cada0c424209a6afbe02629ac167917a308c1ccbcfe7a1f28241c2bf9513fb4ff518a75
7
+ data.tar.gz: 85d24dff9714182d95c76edb935316945e24fc402ae203c77dced39b51b3be44782b774b2c868862bbaad5695b1405988064524c304de30c70e19fd9c9e7a9ee
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -143,6 +143,67 @@ You can also freeze the environment -- which also freezes the filter and tag reg
143
143
  environment.freeze
144
144
  ----
145
145
 
146
+ === Systems
147
+
148
+ These are the file systems used to obtain templates for use within your custom tags. By default, an in memory system is provided for you: `Superfluid::Systems::Memory`. {liquid_link} also provides it's own systems as well. Each are described below.
149
+
150
+ ==== Memory
151
+
152
+ Provided by this gem. Use to access templates via an in memory file system. This is enabled for you be default when using `Superfluid.new` and works in conjunction with the `template` tag which is also provided by this gem (see below for details). Again, this system is provided for you but you can be explicit if desired:
153
+
154
+ [source,ruby]
155
+ ----
156
+ environment = Superfluid.build file_system: Superfluid::Systems::Memory.new
157
+ renderer = Superfluid.new(environment:)
158
+
159
+ template = <<~CONTENT
160
+ {% template demo %}
161
+ Hi, this is a {{ subject }}.
162
+ {% endtemplate %}
163
+
164
+ {% render "demo", subject: "demo" %}
165
+ CONTENT
166
+
167
+ renderer.call template
168
+ # "Hi, this is a demo."
169
+ ----
170
+
171
+ ==== Local
172
+
173
+ Provided by {liquid_link}. Use to access templates via your local file system within a specific root folder. Usage:
174
+
175
+ [source,ruby]
176
+ ----
177
+ Pathname("templates").tap(&:mkdir).join("_demo.liquid").tap { it.write "{{ salutation }}" }
178
+
179
+ environment = Superfluid.build file_system: Liquid::LocalFileSystem.new(Pathname("templates"))
180
+ renderer = Superfluid.new(environment:)
181
+
182
+ renderer.call(%({% include "demo" %}, this is a demo), {"salutation" => "Hi"})
183
+ # "Hi, this is a demo"
184
+ ----
185
+
186
+ The above configures the local system to look for partials (templates) within the `templates` folder. You then reference them via the `include` tag.
187
+
188
+ By default, this system uses link:https://docs.ruby-lang.org/en/master/Kernel.html#method-i-format[Kernel#format] syntax to find your partials (i.e. `"_%s.liquid"`). If you don't like this pattern, you can configure differently when creating a new instance. Example:
189
+
190
+ [source,ruby]
191
+ ----
192
+ Liquid::LocalFileSystem.new "/a/path", "%s.html"
193
+ ----
194
+
195
+ ==== Blank
196
+
197
+ Provided by {liquid_link}. This is an abstract class -- meant for subclassing -- because it will fail with a `FileSystemError` when `read_template_file` isn't implemented. Usage:
198
+
199
+ [source,ruby]
200
+ ----
201
+ environment = Superfluid.build file_system: Liquid::BlankFileSystem.new(Pathname("templates"))
202
+ renderer = Superfluid.new(environment:)
203
+ ----
204
+
205
+ The above does nothing and is benign.
206
+
146
207
  === Filters
147
208
 
148
209
  By default, {liquid_link} only allows registration of filters as instance methods on a namespace (`Module`). Unfortunately, this leads to terrible design, bad practices, and unnecessarily hard to test objects. You can still register namespaces but this gem encourages the use of commands (see {command_pattern_link} for further details) and containers via {containable_link} which allows you tap into Functional Programming by using procs, lambdas, and any object that responds to `#call`. This allows you to build -- and reuse -- more powerful filters. The following details the different kinds of filters you can use, each broken down by category.
@@ -159,7 +220,7 @@ environment.filter_registry.names
159
220
 
160
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:
161
222
 
162
- *jsonify*
223
+ ===== `jsonify`
163
224
 
164
225
  Renders objects as JSON. Example:
165
226
 
@@ -169,7 +230,7 @@ renderer.call(%({{ data | jsonify }}), {"data" => {"a" => 1}})
169
230
  # "{\"a\":1}"
170
231
  ----
171
232
 
172
- *parse_json*
233
+ ===== `parse_json`
173
234
 
174
235
  Parses JSON as a primitive. Example:
175
236
 
@@ -183,7 +244,7 @@ renderer.call(
183
244
  # "1"
184
245
  ----
185
246
 
186
- *pluralize*
247
+ ===== `pluralize`
187
248
 
188
249
  Renders a plural string. Example:
189
250
 
@@ -202,7 +263,7 @@ renderer.call(%({{ text | pluralize: 3, "i", "us" }}), {"text" => "octopus"})
202
263
  # "3 octopi"
203
264
  ----
204
265
 
205
- *singularize*
266
+ ===== `singularize`
206
267
 
207
268
  Renders a singular string. Example:
208
269
 
@@ -221,7 +282,7 @@ renderer.call(%({{ text | singularize: 1, "i", "us" }}), {"text" => "octopi"})
221
282
  # "1 octopus"
222
283
  ----
223
284
 
224
- *trim_end*
285
+ ===== `trim_end`
225
286
 
226
287
  Renders string with trimmed end. Example:
227
288
 
@@ -240,7 +301,7 @@ renderer.call(%({{ text | trim_end: 10, "", "" }}), {"text" => "This is a demo."
240
301
  # "This is a"
241
302
  ----
242
303
 
243
- *trim_middle*
304
+ ===== `trim_middle`
244
305
 
245
306
  Renders string with trimmed middle. Example:
246
307
 
@@ -530,6 +591,37 @@ renderer = Superfluid.new do |environment|
530
591
  end
531
592
  ----
532
593
 
594
+ ==== Defaults
595
+
596
+ You have access to all tags supported by {liquid_link} including the tags provided by this gem (which is only the `template` tag at the moment).
597
+
598
+ ===== `template`
599
+
600
+ This tag must be used with the `Memory` system (see _Systems_, mentioned earlier, for details). You can use this tag as follows:
601
+
602
+ [source,ruby]
603
+ ----
604
+ renderer = Superfluid.new
605
+
606
+ template = <<~CONTENT
607
+ {% template demo %}
608
+ Hi, this is a {{ subject }}.
609
+ {% endtemplate %}
610
+
611
+ {% render "demo", subject: "demo" %}
612
+ CONTENT
613
+
614
+ renderer.call template
615
+ # "Hi, this is a demo."
616
+ ----
617
+
618
+ As you can see this tag requires two steps:
619
+
620
+ . Define by using the `template` tag followed by a unique name for your template (in this case: `demo`). You can then use any filters and/or additional tags with your template. Finally, close the tag with `endtemplate`.
621
+ . Render your template by using `render` followed by the unique name of your template (i.e. `demo`) and any attributes you need to provide to the template.
622
+
623
+ The above allows you to define multiple templates for rendering later. Great for situations where you want to organize your in memory code for final later rendering.
624
+
533
625
  ==== Containers
534
626
 
535
627
  Containers are not supported by {liquid_link} but are via this gem using {containable_link}. To use, create a container and then register your dependencies:
@@ -37,7 +37,7 @@ module Superfluid
37
37
 
38
38
  alias invoke call
39
39
 
40
- def names = container.keys
40
+ def names = container.keys.sort
41
41
 
42
42
  private
43
43
 
@@ -22,7 +22,7 @@ module Superfluid
22
22
 
23
23
  def get(name) = (container[name] if container.key? name)
24
24
 
25
- def names = container.keys
25
+ def names = container.keys.sort
26
26
 
27
27
  def to_h = container.each.to_h
28
28
 
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.1.0"
5
+ spec.version = "0.2.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
@@ -1,3 +1,2 @@
1
- �Z�_2C��\�y�Mm
2
- IiB�-�H�.���i��˔΄�Q�
3
- ��n�6������Yg���s��1Ӧ�2~o伪<��
1
+ r��ղ#��]Ŵ�*����
2
+ �p��rZ兮�fH�#&�U;��T�;��b �,����4�����4BE� b��}d��|������� ]v�곶���R�.�t����#��"�wm�h�2�S<�J�e}^S���smPW�#��8��6��MS9@_e��`���:���Ȩn���[:]oli�@���E�Ԇ��B���V��ҟ�^H];ERw��O����L0���$�9>����ga�W�{��k/* 6�<����]�D99�ڌ����T������/)sŊq�T���n�yս�T#I���/���i��hL�l�F6F3"���PG��x"�H��Q�n�M n b��e��2DF��u��pE�oL8��A��f�;Sb��
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
metadata.gz.sig CHANGED
Binary file