general 1.2.4 → 1.2.5
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/lib/gtemplate.rb +47 -33
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab656ffd2493215af70ca4cd3f055c124dd027a
|
4
|
+
data.tar.gz: 880637049b15f23f04b617dba41ca035463fd2c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18c45c45a642d87b926cdc987a6c243e6d7a36ef5e5deab67b75102669f39d414288fbda8f8dc66dde3594117a5b2992393a369358d2bb6bc4fa362260c5eccd
|
7
|
+
data.tar.gz: 06cce36678474a7e5482b714893d66796ca1bd0c85e86a07ae1fdb317022a368b5ee3ebc46fd1ad4bbf6ce2138621dea0c16fa47cbe401f3cf8e7fbabf6dca0a
|
data/lib/gtemplate.rb
CHANGED
@@ -28,7 +28,7 @@ module General
|
|
28
28
|
PLACEHOLDER = /@\((?<name>[a-zA-Z]\w*)\s*(\:\s*(?<default>.*?))?\s*(->\s*(?<operation>[a-zA-Z]\w*))?\)/
|
29
29
|
|
30
30
|
# Regular expression that matches array placeholders
|
31
|
-
ARRAY_PLACEHOLDER = /@\[(?<name>[a-zA-Z]\w*)\]
|
31
|
+
ARRAY_PLACEHOLDER = /@\[(?<name>[a-zA-Z]\w*)\]( |\n)?(?<text>.*?)( |\n)?@\[(?<delimeter>.+)?\]/m
|
32
32
|
|
33
33
|
# Operations that can be called on placeholder values
|
34
34
|
OPERATIONS = {
|
@@ -79,7 +79,7 @@ module General
|
|
79
79
|
if @array[key]
|
80
80
|
applied_parts[place[:index]] = place[:template].apply_all(value).join(place[:delimeter])
|
81
81
|
else
|
82
|
-
applied_parts[place[:index]] = place[:operation].call(value)
|
82
|
+
applied_parts[place[:index]] = OPERATIONS[place[:operation]].call(value)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
else
|
@@ -121,37 +121,51 @@ module General
|
|
121
121
|
def parse_string string
|
122
122
|
# While there is still a placeholder in string
|
123
123
|
while has_placeholder string
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
124
|
+
# Find locations of next placeholder and next array placeholder
|
125
|
+
next_p = PLACEHOLDER =~ string
|
126
|
+
next_a = ARRAY_PLACEHOLDER =~ string
|
127
|
+
|
128
|
+
# If found at least one
|
129
|
+
if !(next_a.nil? && next_p.nil?)
|
130
|
+
|
131
|
+
# If found only array placeholder (or if found array placeholder before placeholder)
|
132
|
+
# Process placeholder
|
133
|
+
if next_p.nil? && !next_a.nil? || !(next_a.nil? || next_p.nil?) && next_a < next_p
|
134
|
+
# Split match and add parts
|
135
|
+
match = ARRAY_PLACEHOLDER.match string
|
136
|
+
@parts << string[0...match.begin(0)] << match[:name].to_sym
|
137
|
+
string = string[match.end(0)..-1]
|
138
|
+
|
139
|
+
# Get name
|
140
|
+
name = match[:name].to_sym
|
141
|
+
|
142
|
+
# Get delimeter (if any) and parse array template
|
143
|
+
delimeter = match[:delimeter].nil? ? " " : match[:delimeter]
|
144
|
+
template = GTemplate.new(match[:text])
|
145
|
+
|
146
|
+
# Push place and array information
|
147
|
+
push_place name, {index: @parts.length - 1, template: template, delimeter: delimeter}
|
148
|
+
@array[name] = true
|
149
|
+
|
150
|
+
# If found only array placeholder (or if found array placeholder before placeholder)
|
151
|
+
# Process placeholder
|
152
|
+
elsif next_a.nil? && !next_p.nil? || !(next_a.nil? || next_p.nil?) && next_p < next_a
|
153
|
+
# Split match and add parts
|
154
|
+
match = PLACEHOLDER.match string
|
155
|
+
@parts << string[0...match.begin(0)] << match[:name].to_sym
|
156
|
+
string = string[match.end(0)..-1]
|
157
|
+
|
158
|
+
# Get name
|
159
|
+
name = match[:name].to_sym
|
160
|
+
|
161
|
+
# Get operation and arguments (if any)
|
162
|
+
operation = match[:operation].nil? ? :default : match[:operation].to_sym
|
163
|
+
|
164
|
+
# Push place and default information
|
165
|
+
push_place name, {index: @parts.length - 1, operation: operation}
|
166
|
+
@defaults[name] = match[:default] unless @defaults.has_key? name
|
167
|
+
|
168
|
+
end
|
155
169
|
end
|
156
170
|
end
|
157
171
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: general
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anshul Kharbanda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
description: "General is a simple templating system in ruby that allows you to create
|
28
28
|
templates from both \t\t\t\t\t\tpure strings and files (with the extension .general),
|
29
29
|
as well as create new strings and files \t\t\t\t\t\twith these created objects.
|
30
|
-
For more information,
|
30
|
+
For more information, visit the homepage"
|
31
31
|
email: akanshul97@gmail.com
|
32
32
|
executables: []
|
33
33
|
extensions: []
|