rbytes 0.1.4 → 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: 6d5f9b7ef9aa790dd67e77dd0844cd687919c4bf25f79bfea70aa3ba8b2f8af7
4
- data.tar.gz: 893078a760c1d54d8e8b8096f9d99b3e31736cf4346d87fcde240deca8d5c23d
3
+ metadata.gz: f8780a2ff433a3b3e11c59a05fe7bf73a1a742463c659bbf8abd835b17242d43
4
+ data.tar.gz: 10fd5d4eb9271e6e3be8fe2f71262e03a743dbf077b71a925498796c20e2cafe
5
5
  SHA512:
6
- metadata.gz: a53aafcbf1fda5e33e1069a05cccda2ccae4eb3ebb4cb73b26f2129378cc9a90ef1d03308edaf59f9f8a2128a09bf4d4e1d99e942b504a0dbc1791e0f97329df
7
- data.tar.gz: 0e1bb54b2a3bda1b862e005de1f065535ba93a2c8a0277fc6310fff5d97da3c70bf9c6e1ee9dbde9786d3a811408da5390ecc3f60135493392f0dabdc06d17ab
6
+ metadata.gz: c681d786e67cf6423e95b78b687bfec4dea5460ec3238656ed3319347240eae199a21fbf5bc05fb3d67a70fdd6862797712401085e239ce94c56ccb25f7ceea9
7
+ data.tar.gz: e8fae36e2fa7daa3acfd71a760b969e6c09c23dc248f1bedd479930e7c9e064b7c6027e987fa61683250c36a65398cc784f174f2f9890ce0a3764300abe76088
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.2.0 (2023-04-15)
6
+
7
+ - Add `#import_template` directive to inline other templates.
8
+
5
9
  ## 0.1.4 (2023-04-11)
6
10
 
7
11
  - Fix publishing to RailsBytes.
data/README.md CHANGED
@@ -107,6 +107,22 @@ file "config/anycable.yml", ERB.new(
107
107
 
108
108
  **NOTE:** By default, we assume that partials are stored next to the template's entry-point. Partials may have the "_" prefix and ".rb" or ".tt" suffixes.
109
109
 
110
+ Ruby Bytes can also import a sub-template into your template. Simply use the `#import_template` helper in your template:
111
+
112
+ ```erb
113
+ # subtemplate/_partial.rb
114
+ say "Hello from subtemplate's partial!"
115
+
116
+ # subtemplate/subtemplate.rb
117
+ <%= include "partial" %>
118
+
119
+ # template.rb
120
+ <%= import_template("subtemplate/subtemplate.rb")>
121
+ ```
122
+
123
+ Note that the full filename must be passed to the `#import_template` helper, including any file extension, unlike the `#include` helper. All templates within the subtemplate directory will consider that to be their root directory.
124
+
125
+
110
126
  ### Compiling templates
111
127
 
112
128
  You can compile a template by using the `rbytes` executable:
@@ -32,6 +32,10 @@ module RubyBytes
32
32
  indented(render(File.read(resolve_path(path))), indent)
33
33
  end
34
34
 
35
+ def import_template(path, indent: 0)
36
+ indented(self.class.new(File.join(root, path)).render, indent)
37
+ end
38
+
35
39
  private
36
40
 
37
41
  PATH_CANDIDATES = [
@@ -20,7 +20,7 @@ class Rbytes < Thor
20
20
  # TODO: Add more extensions
21
21
  class ::String
22
22
  def parameterize
23
- gsub("::", "/").gsub(/([a-z])([A-Z])/, '\1-\2').downcase
23
+ downcase.gsub(/[^a-z0-9\-_]+/, '-').gsub(/-{2,}/, '-').gsub(/^-|-$/, '')
24
24
  end
25
25
 
26
26
  def underscore
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyBytes # :nodoc:
4
- VERSION = "0.1.4"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -7,7 +7,7 @@ rescue LoadError
7
7
  # TODO: Add more extensions
8
8
  class ::String
9
9
  def parameterize
10
- gsub("::", "/").gsub(/([a-z])([A-Z])/, '\1-\2').downcase
10
+ downcase.gsub(/[^a-z0-9\-_]+/, '-').gsub(/-{2,}/, '-').gsub(/^-|-$/, '')
11
11
  end
12
12
 
13
13
  def underscore
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbytes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-11 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor