drudje 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/drudje.rb +28 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d18f1710e19364a61e8fbf2d1b5a63bf7b85617
4
- data.tar.gz: e6ed2dcb60ee5894f00fe3af0c479ea30c07b652
3
+ metadata.gz: 09a241d58388c291a9137422a90a555bfb43556f
4
+ data.tar.gz: e21845df3a912f89dfdf3a57b0b9277ec618f9c7
5
5
  SHA512:
6
- metadata.gz: cfb544a364727d2fed4c1b62b573c83aad27f24c58ea5e10c0b680bff80d47454014f734e3f65d18a9e878e44443ab4798671bd8330634e819812e9eef7ff50f
7
- data.tar.gz: c918cd58c6c3613041c9be1fb06dc2365d73ffc6520967dc9ecf86786cb089c5c31493012c8a04f36a85e93ab3af5f1bbc8e538bcaf8cebabdba1c9740fc121f
6
+ metadata.gz: 7cfec2ac4b4a73f75dd5f41a90c9d65391c07adb1f769719f63c3774c270e787786fc5d6bd583f5e83d463da5741dde83265103b74aa6f523add5b1b9cd7e4ac
7
+ data.tar.gz: 3426059e0b3011ecb2e28fd1dd3ec744bb3361cc115b15f933212615e45c779c8dee359a1a4b8ab14a7e82948684b9a16d2b5eeff786813f698023fe91be0561
@@ -87,8 +87,35 @@ class Drudje
87
87
  render template, args
88
88
  end
89
89
 
90
+ def find_call_loc(str, cstart = 0, cend = str.length)
91
+ group_start = str.index('[[', cstart)
92
+ group_end = str.rindex(']]', cend)
93
+ return nil if !group_start || !group_end
94
+
95
+ # We want group_end to point to the last ], not the first
96
+ group_end = group_end + 1
97
+
98
+ call_start = group_start + 2
99
+ call_end = group_end - 2
100
+ length = call_end - call_start + 1
101
+ substr = str[call_start, length]
102
+ # Make sure the substring doesn't have more calls nested
103
+ if substr =~ /\[\[/
104
+ find_call_loc(str, call_start, group_end)
105
+ elsif substr =~ /\]\]/
106
+ find_call_loc(str, group_start, call_end)
107
+ else
108
+ [group_start, group_end]
109
+ end
110
+ end
111
+
90
112
  def process_pass(str)
91
- str.gsub(/\[\[([^\[\]]+)\]\]/){ expand($1) }
113
+ call_loc = find_call_loc(str)
114
+ return str if !call_loc
115
+ before = str[0, call_loc[0]]
116
+ during = str[call_loc[0]+2..call_loc[1]-2]
117
+ after = str[call_loc[1]+1,str.length]
118
+ before + expand(during) + after
92
119
  end
93
120
 
94
121
  def process(str)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drudje
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian DeJong