curly_bracket_parser 0.9.0 → 0.9.1
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 +4 -4
- data/README.md +4 -4
- data/lib/curly_bracket_parser.rb +5 -15
- data/lib/curly_bracket_parser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e5f953c9b35c41ca0b623017a51fd7d9d122cdcd02654306a95bcd0b32d7a2e
|
4
|
+
data.tar.gz: cfb7e3120bb559ee8dcb2c4840c98dc8d741b18d1ad6a287b77e6930025462f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67b58ee971ab43ffa2f2c5f71dc413c9ed9c96fdf61678eb4fa6dd1a3c5f20051cda50622c95bede909b27aeab94aa50a588372c9bd2171cd65374f2cc31d1da
|
7
|
+
data.tar.gz: 19c1dbddc62920667d6cfbdadaea54927b8402c3b7cc3ab0797e2d65fc4b0349fe9bbd5e0092fb0df600dcec5006b9eb166d54282e03e4d7a9b629ecae2af363
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# curly_bracket_parser
|
2
2
|
|
3
|
-
Ruby gem
|
3
|
+
Ruby gem providing a simple parser to replace curly brackets `{{like_this}}` inside strings like URLs, texts or even files easily.
|
4
4
|
|
5
5
|
Additional support for build-in filters and custom filters make them more powerful. `{{example|my_filter}}`
|
6
6
|
|
7
|
-
Using [LuckyCase](https://github.com/magynhard/lucky_case), all its case formats are supported as filter.
|
7
|
+
Using [LuckyCase](https://github.com/magynhard/lucky_case), all its case formats are supported as filter by default.
|
8
8
|
|
9
9
|
|
10
10
|
|
@@ -13,7 +13,7 @@ Using [LuckyCase](https://github.com/magynhard/lucky_case), all its case formats
|
|
13
13
|
# Contents
|
14
14
|
|
15
15
|
* [Installation](#installation)
|
16
|
-
* [Usage](#usage)
|
16
|
+
* [Usage examples](#usage)
|
17
17
|
* [Documentation](#documentation)
|
18
18
|
* [Contributing](#contributing)
|
19
19
|
|
@@ -91,7 +91,7 @@ Use `#parse_file!` instead to write the parsed string directly into the file!
|
|
91
91
|
|
92
92
|
You can define default variables, which will be replaced automatically without passing them by parameters, but can be overwritten with parameters.
|
93
93
|
|
94
|
-
Because of providing blocks, your variables can dynamically depend on other states.
|
94
|
+
Because of providing blocks, your variables can dynamically depend on other states (e.g. current date).
|
95
95
|
|
96
96
|
```ruby
|
97
97
|
CurlyBracketParser.register_default_var('version') do
|
data/lib/curly_bracket_parser.rb
CHANGED
@@ -32,7 +32,7 @@ module CurlyBracketParser
|
|
32
32
|
# @param [String] string to parse
|
33
33
|
# @param [Hash<Symbol => String>] variables <key: 'value'>
|
34
34
|
# @param [Symbol] unresolved_vars :raise, :keep, :replace => define how to act when unresolved variables within the string are found.
|
35
|
-
# @param [String] replace_pattern pattern used when param unresolved_vars is set to :replace. You can include the var name \\1 and filter \\
|
35
|
+
# @param [String] replace_pattern pattern used when param unresolved_vars is set to :replace. You can include the var name \\1 and filter \\2. Empty string to remove unresolved variables.
|
36
36
|
# @return [String, UnresolvedVariablesError] parsed string
|
37
37
|
def self.parse(string, variables, unresolved_vars: :raise, replace_pattern: "##\\1##")
|
38
38
|
variables ||= {}
|
@@ -103,7 +103,7 @@ module CurlyBracketParser
|
|
103
103
|
#
|
104
104
|
# @param [String] filter name of the filter, also used then in your strings, e.g. {{var_name|my_filter_name}}
|
105
105
|
# @param [Lambda] function of the filter to run the variable against
|
106
|
-
# @
|
106
|
+
# @raise [FilterAlreadyRegisteredError] if filter does already exist
|
107
107
|
def self.register_filter(filter, &block)
|
108
108
|
@@registered_filters ||= {}
|
109
109
|
filter = filter.to_s
|
@@ -112,10 +112,13 @@ module CurlyBracketParser
|
|
112
112
|
else
|
113
113
|
@@registered_filters[filter] = block
|
114
114
|
end
|
115
|
+
nil
|
115
116
|
end
|
116
117
|
|
117
118
|
#----------------------------------------------------------------------------------------------------
|
118
119
|
|
120
|
+
# Process the given value with the given filter
|
121
|
+
#
|
119
122
|
# @param [String] filter name of the filter, also used then in your strings, e.g. {{var_name|my_filter_name}}
|
120
123
|
# @param [String] value string to apply the specified filter on
|
121
124
|
# @return [String] converted string with applied filter
|
@@ -155,19 +158,6 @@ module CurlyBracketParser
|
|
155
158
|
|
156
159
|
#----------------------------------------------------------------------------------------------------
|
157
160
|
|
158
|
-
# Check if given variable has a defined filter
|
159
|
-
# @example
|
160
|
-
# {{variable|filter}} => has filter, true
|
161
|
-
# {{variable2}} => has no filter, false
|
162
|
-
#
|
163
|
-
# @param [String] variable
|
164
|
-
# @return [Boolean] true if has a defined filter, otherwise false
|
165
|
-
def self.has_filter?(variable)
|
166
|
-
decode_variable(variable)[:filter] != nil
|
167
|
-
end
|
168
|
-
|
169
|
-
#----------------------------------------------------------------------------------------------------
|
170
|
-
|
171
161
|
# Return the given default variable by processing its block/proc
|
172
162
|
#
|
173
163
|
# @param [String] name of the variable to return
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curly_bracket_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthäus Beyrle
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lucky_case
|