erbx 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -4
  3. data/lib/erbx/version.rb +2 -2
  4. data/lib/erbx.rb +14 -11
  5. metadata +6 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad2f147fcfb878cb4b5e66e99057db75d644e481a374ad45047ca159332c44ab
4
- data.tar.gz: a60cda49e02290fe2e4ea217f0d4091dddd8bdb003b8f680e71c770583843681
3
+ metadata.gz: e64d1f5fd7aa9ac7e7cf4739c288bafd67b0b45e344ef667c185513648206b5d
4
+ data.tar.gz: 9494c04055d32663df331c9b6a41ea4f08e67070c4edfdf8bc75a1f7f533e22b
5
5
  SHA512:
6
- metadata.gz: eef063d45a794c61fc7f33ac0b8adf7612486a3a5a4e756a26ffa80e71acad668c32c06e3be0884bf98fbbedd0ad62bce3e3bf20e73073c5b74fadc8aba11737
7
- data.tar.gz: edf79d4c143d05bc2334b62f617cd98e8824adc7f54b69fef6acc00168b443083a9495f5eb251c764f0ca3827029311e57e403dcca7e235bff86db0af1c7c414
6
+ metadata.gz: f58e90a4f67778afe3e7a5cea0796f08d28dd1d282b11ca983314c85edba5ca95ce6dce0666ef96f7614cb68d834c3da833121c7e547bfb6db005b1873767c2f
7
+ data.tar.gz: 98664388538b16d2a453e9a356922241731c065b9a4f77b064f5de44bbfec32764d2971da56abc358595bb57b3b9c2406c635109472872a9621217e9136b2015
data/README.md CHANGED
@@ -10,17 +10,17 @@ ERBX is a tiny extension to ERB allowing these tags:
10
10
  - `{{ ... }}` as an equivalent to `<%= ... %>` (print ruby code)
11
11
  - `(( ... ))` as an equivalent to `<%- ... -%>` (run ruby code)
12
12
 
13
+ Both tag pairs are configurable.
14
+
13
15
  ---
14
16
 
15
- Installation
16
- --------------------------------------------------
17
+ ## Installation
17
18
 
18
19
  ```
19
20
  $ gem install erbx
20
21
  ```
21
22
 
22
- Usage
23
- --------------------------------------------------
23
+ ## Usage
24
24
 
25
25
  Given this ERBX templalte:
26
26
 
@@ -57,6 +57,32 @@ puts template.result
57
57
  #=> You rolled [4, 2]
58
58
  ```
59
59
 
60
+ ## Custom Tags
61
+
62
+ If you wish to use different tags in your template, you can provide them using
63
+ these four options:
64
+
65
+ - `code_open` - default `((`
66
+ - `code_close` - default `))`
67
+ - `output_open` - default `{{`
68
+ - `output_close` - default `}}`
69
+
70
+ For example:
71
+
72
+ ```ruby
73
+ # Render example with options
74
+ require 'erbx'
75
+
76
+ template = ERBX.load 'example/template2.md', code_open: '===[', code_close: ']==='
77
+ puts template.result_with_hash number: rand(100..999)
78
+ #=> This template only uses output tags, and uses data provided by the caller.
79
+ #=> This is useful when the file may contain (( markers like these )) that are
80
+ #=> not intended to be interpreted as code.
81
+ #=>
82
+ #=> Random number: 938
83
+
84
+ ```
85
+
60
86
  ## Contributing / Support
61
87
 
62
88
  If you experience any issue, have a question or a suggestion, or if you wish
data/lib/erbx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class ERBX
2
- VERSION = "0.1.2"
3
- end
2
+ VERSION = '0.1.3'
3
+ end
data/lib/erbx.rb CHANGED
@@ -2,25 +2,28 @@ require 'erb'
2
2
 
3
3
  class ERBX
4
4
  class << self
5
- def load(filename)
6
- new File.read filename
5
+ def load(filename, options = {})
6
+ new File.read(filename), options
7
7
  end
8
8
 
9
- def new(content)
10
- erb_content = expose_erb_tags content
9
+ def new(content, options = {})
10
+ erb_content = expose_erb_tags content, options
11
11
  ERB.new erb_content, trim_mode: '%-'
12
12
  end
13
13
 
14
14
  private
15
15
 
16
- def expose_erb_tags(content)
16
+ def expose_erb_tags(content, options = {})
17
+ code_open = options[:code_open] || '(('
18
+ code_close = options[:code_close] || '))'
19
+ output_open = options[:output_open] || '{{'
20
+ output_close = options[:output_close] || '}}'
21
+
17
22
  content
18
- .gsub("((", "<%-")
19
- .gsub("))", "-%>")
20
- .gsub("{{", "<%=")
21
- .gsub("}}", "%>")
23
+ .gsub(code_open, '<%-')
24
+ .gsub(code_close, '-%>')
25
+ .gsub(output_open, '<%=')
26
+ .gsub(output_close, '%>')
22
27
  end
23
28
  end
24
29
  end
25
-
26
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erbx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-19 00:00:00.000000000 Z
11
+ date: 2023-05-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Extended ERB with prettier tags
14
14
  email: db@dannyben.com
@@ -22,7 +22,8 @@ files:
22
22
  homepage: https://github.com/dannyben/erbx
23
23
  licenses:
24
24
  - MIT
25
- metadata: {}
25
+ metadata:
26
+ rubygems_mfa_required: 'true'
26
27
  post_install_message:
27
28
  rdoc_options: []
28
29
  require_paths:
@@ -31,14 +32,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
31
32
  requirements:
32
33
  - - ">="
33
34
  - !ruby/object:Gem::Version
34
- version: 2.4.0
35
+ version: 2.6.0
35
36
  required_rubygems_version: !ruby/object:Gem::Requirement
36
37
  requirements:
37
38
  - - ">="
38
39
  - !ruby/object:Gem::Version
39
40
  version: '0'
40
41
  requirements: []
41
- rubygems_version: 3.3.14
42
+ rubygems_version: 3.3.26
42
43
  signing_key:
43
44
  specification_version: 4
44
45
  summary: ERB Extra