curly_bracket_parser 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d129cee0f2fe16c754b7b4f10d31505d8279dc4399c03e94bab98f9c86b9c60
4
- data.tar.gz: 4477f5908c20c4f3513705dd973f702a6addd118f8aab221cab9bc3c751167f4
3
+ metadata.gz: 7e5f953c9b35c41ca0b623017a51fd7d9d122cdcd02654306a95bcd0b32d7a2e
4
+ data.tar.gz: cfb7e3120bb559ee8dcb2c4840c98dc8d741b18d1ad6a287b77e6930025462f0
5
5
  SHA512:
6
- metadata.gz: 633664bae5c9062f5d71a0ec643db1c957b936e88a5fae88a7dda9cbb80d12d2682e37d4b8da33cd1c7a1fdd52e28a169a792bdb66ae004fb716fef4cb595c22
7
- data.tar.gz: a6aebeae6ee35a392fe90b8d6d59838abb4bb49097ef2048c4e62fcddd95c61837cffc20c5367d8a3a77a4f2b3035ddbea12ae1b7ab7b249957200836ba876cf
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 with simple parser to replace curly brackets `{{like_this}}` inside strings like URLs, texts or even files easily.
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
@@ -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 \\1. Empty string to remove unresolved variables.
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
- # @return [Boolean] true if filter was added, false if it already exists
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
@@ -1,3 +1,3 @@
1
1
  module CurlyBracketParser
2
- VERSION = '0.9.0'.freeze
2
+ VERSION = '0.9.1'.freeze
3
3
  end
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.0
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-06 00:00:00.000000000 Z
11
+ date: 2021-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucky_case