general 2.0.2 → 2.0.3

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
  SHA1:
3
- metadata.gz: f3811fd53824c1198a6fda65a7cdcef373f25385
4
- data.tar.gz: b74c9fffde42b92ec0ca6ca768689109852382e5
3
+ metadata.gz: f610cd0c2d52fe794bdfe47dce873c4aa170818e
4
+ data.tar.gz: 8233a86e36c631edf9d030e7017c7177781013a2
5
5
  SHA512:
6
- metadata.gz: aa543b2e2d7ed4be03377a05609cccc99f384de309131e6fabe29ade150d3ee34780eea61d9f043c03b1ef67ff44471c83c41821fdadc2cff5921a6102ae1cbc
7
- data.tar.gz: d904d520a54b247ad76935d8f4330b90de91c76f3833a44ded9f7fdec1c6b3fd71b70e48541a42bbaa2e8201155ff1075502578d527df2dc708e4d841e035d0b
6
+ metadata.gz: e283ae5ffec30b14e89410034c1aef4a7a902563db1459d26cccfafbc9cf244aa99610891afb859e1cfad22e2e4e7b48f36ebb0414574ce5cdb98b242eca9d89
7
+ data.tar.gz: dcb1a5a856a29e2acbb3dee59490d54b6d88bcfb346089129926ba7b9b19ab59506fb2763aaefb5d5cf4bf2b528196f1a754e9a6e56957fd36dbdc228f64916c
@@ -0,0 +1,3 @@
1
+ There once was a bloke named Joe, who hated Joe's Schmoes. He didn't go to Kentucky.
2
+
3
+ Joe drove to the store to get some Joe's Schmoes.
@@ -0,0 +1,11 @@
1
+ General Super Layout
2
+
3
+ Open
4
+
5
+ Sublayout
6
+
7
+ Joe drove to the department store.
8
+
9
+ End of Sublayout
10
+
11
+ Close
@@ -0,0 +1,3 @@
1
+ There once was a bloke named Richard Hammond, who hated beets. He didn't go to Virginia.
2
+
3
+ Richard Hammond drove to the store to get some beets.
@@ -0,0 +1,11 @@
1
+ General Super Layout
2
+
3
+ Open
4
+
5
+ Sublayout
6
+
7
+ Mark Zuckerberg drove to the department store.
8
+
9
+ End of Sublayout
10
+
11
+ Close
@@ -0,0 +1,3 @@
1
+ There once was a bloke named Joe, who hated Joe's Schmoes. He didn't go to Kentucky.
2
+
3
+ Joe drove to the store to get some Joe's Schmoes.
@@ -0,0 +1,11 @@
1
+ General Super Layout
2
+
3
+ Open
4
+
5
+ Sublayout
6
+
7
+ Joe drove to the department store.
8
+
9
+ End of Sublayout
10
+
11
+ Close
@@ -0,0 +1,7 @@
1
+ @@extend sample0
2
+
3
+ Sublayout
4
+
5
+ @@yield
6
+
7
+ End of Sublayout
@@ -0,0 +1,3 @@
1
+ @@include sub/sample_base
2
+
3
+ @(name -> capitalize all) drove to the store to get some @(food).
@@ -0,0 +1,3 @@
1
+ @@extend sample0a
2
+
3
+ @(name: mark zuckerberg -> capitalize all) drove to the department store.
@@ -0,0 +1 @@
1
+ There once was a bloke named @(name: richard hammond -> capitalize all), who hated @(food: beets). He didn't go to @(place -> capitalize).
@@ -29,7 +29,7 @@ module General
29
29
  # Created: 1 - 30 - 2017
30
30
  class GExtend < GPrePartial
31
31
  # Regular expression matches GExtend
32
- REGEX = /\A@@extend\s+(?<filename>\w+)\r?\n/
32
+ REGEX = /\A@@extend\s+(?<filename>\w+(\/\w+)*?)(\r?\n)+/
33
33
 
34
34
  # Read filename
35
35
  attr :filename
@@ -29,7 +29,7 @@ module General
29
29
  # Created: 1 - 30 - 2017
30
30
  class GInclude < GPrePartial
31
31
  # Regular expression matches GInclude
32
- REGEX = /\A@@include\s+(?<filename>\w+)\r?\n/
32
+ REGEX = /\A@@include\s+(?<filename>\w+(\/\w+)*?)\r?\n/
33
33
 
34
34
  # Creates a new GInclude
35
35
  #
@@ -26,9 +26,9 @@ module General
26
26
  # Author: Anshul Kharbanda
27
27
  # Created: 1 - 31 - 2016
28
28
  class GMeta < GTemplate
29
- def self.load filename
29
+ def self.load path
30
30
  # Read file
31
- string = IO.read filename
31
+ string = IO.read path
32
32
 
33
33
  # Prepartial types
34
34
  ptypes = [
@@ -46,7 +46,9 @@ module General
46
46
  prepart = ptypes.find { |ptype| m = ptype::REGEX.match(string) }
47
47
 
48
48
  # Raise error if no matching prepart can be found
49
- raise GError.new("Unmatched prepartial at #{(string.length <= 5 ? string : string[0..5] + "...").inspect}") if prepart.nil?
49
+ if prepart.nil?
50
+ raise GError.new "Unmatched prepartial at #{(string.length <= 5 ? string : string[0..5] + "...").inspect}"
51
+ end
50
52
 
51
53
  # Add the partial to the array
52
54
  preparts << prepart.new(m)
@@ -63,23 +65,25 @@ module General
63
65
 
64
66
  # Run extend algorithm (throw error if extend is found elsewhere)
65
67
  if extindex == 0
66
- GMeta.load(extindex.filename).gextend(preparts)
68
+ preparts = GMeta.load(preparts[extindex].filename+General::GIO::EXTENSION).gextend(preparts[1..-1])
67
69
  elsif !extindex.nil? && extindex > 0
68
70
  raise GError.new "@@extend prepartial needs to be at beginning of template."
69
71
  end
70
72
 
71
73
  # Check for multiple yields
72
74
  yields = preparts.find_all{ |prepart| prepart.is_a? General::GYield }
73
- raise GError.new "@@yield prepartial can only appear ONCE!" if yields.length > 1
75
+ if yields.length > 1
76
+ raise GError.new "@@yield prepartial can only appear ONCE!"
77
+ end
74
78
 
75
79
  # Find the yield
76
80
  yindex = preparts.index{ |prepart| prepart.is_a? General::GYield }
77
81
 
78
82
  # Return a new meta file if yield is found. Else default is end.
79
83
  unless yindex.nil?
80
- return self.new preparts[0...yindex], preparts[(yindex + 1)..-1], filename
84
+ return self.new preparts[0...yindex], preparts[(yindex + 1)..-1], path
81
85
  else
82
- return self.new preparts, [], filename
86
+ return self.new preparts, [], path
83
87
  end
84
88
  end
85
89
 
@@ -30,19 +30,27 @@ describe General::GIO do
30
30
  @gio1 = General::GIO.load("exp/templates/sample1" + General::GIO::EXTENSION)
31
31
  @gio2 = General::GIO.load("exp/templates/sample2" + General::GIO::EXTENSION)
32
32
  @gio3 = General::GIO.load("exp/templates/sample3" + General::GIO::EXTENSION)
33
+ @gio4 = General::GIO.load("exp/templates/sample4" + General::GIO::EXTENSION)
34
+ @gio5 = General::GIO.load("exp/templates/sample5" + General::GIO::EXTENSION)
33
35
 
34
36
  @out1 = "exp/out/sample1.txt"
35
37
  @out2 = "exp/out/sample2.txt"
36
38
  @out3 = "exp/out/sample3.txt"
39
+ @out4 = "exp/out/sample4.txt"
40
+ @out5 = "exp/out/sample5.txt"
37
41
  @outF = 3
38
42
 
39
43
  @default_text1 = IO.read "exp/expected/default1.txt"
40
44
  @default_text2 = IO.read "exp/expected/default2.txt"
41
45
  @default_text3 = IO.read "exp/expected/default3.txt"
46
+ @default_text4 = IO.read "exp/expected/default4.txt"
47
+ @default_text5 = IO.read "exp/expected/default5.txt"
42
48
 
43
49
  @applied_text1 = IO.read "exp/expected/applied1.txt"
44
50
  @applied_text2 = IO.read "exp/expected/applied2.txt"
45
- @applied_text3 = IO.read "exp/expected/applied3.txt"
51
+ @applied_text3 = IO.read "exp/expected/applied3.txt"
52
+ @applied_text4 = IO.read "exp/expected/applied4.txt"
53
+ @applied_text5 = IO.read "exp/expected/applied5.txt"
46
54
  end
47
55
 
48
56
  # Describe General::GIO::load
@@ -57,6 +65,8 @@ describe General::GIO do
57
65
  expect(@gio1).to be_an_instance_of General::GIO
58
66
  expect(@gio2).to be_an_instance_of General::GIO
59
67
  expect(@gio3).to be_an_instance_of General::GIO
68
+ expect(@gio4).to be_an_instance_of General::GIO
69
+ expect(@gio5).to be_an_instance_of General::GIO
60
70
  end
61
71
 
62
72
  it "cannot load GMeta file (with @@yield defined)" do
@@ -91,26 +101,36 @@ describe General::GIO do
91
101
  @gio1.write @out1, @default_data
92
102
  @gio2.write @out2, @default_data
93
103
  @gio3.write @out3, @default_data
104
+ @gio4.write @out4, @default_data
105
+ @gio5.write @out5, @default_data
94
106
 
95
107
  expect(IO.read @out1).to eql @default_text1
96
108
  expect(IO.read @out2).to eql @default_text2
97
109
  expect(IO.read @out3).to eql @default_text3
110
+ expect(IO.read @out4).to eql @default_text4
111
+ expect(IO.read @out5).to eql @default_text5
98
112
  end
99
113
 
100
114
  it "writes the default data to the given file io" do
101
115
  File.open(@out1, "w+") { |ios| @gio1.write ios, @default_data }
102
116
  File.open(@out2, "w+") { |ios| @gio2.write ios, @default_data }
103
117
  File.open(@out3, "w+") { |ios| @gio3.write ios, @default_data }
118
+ File.open(@out4, "w+") { |ios| @gio4.write ios, @default_data }
119
+ File.open(@out5, "w+") { |ios| @gio5.write ios, @default_data }
104
120
 
105
121
  expect(IO.read @out1).to eql @default_text1
106
122
  expect(IO.read @out2).to eql @default_text2
107
123
  expect(IO.read @out3).to eql @default_text3
124
+ expect(IO.read @out4).to eql @default_text4
125
+ expect(IO.read @out5).to eql @default_text5
108
126
  end
109
127
 
110
128
  it "raises TypeError if target is not string or io" do
111
129
  expect{ @gio1.write @outF, @default_data }.to raise_error TypeError
112
130
  expect{ @gio2.write @outF, @default_data }.to raise_error TypeError
113
131
  expect{ @gio3.write @outF, @default_data }.to raise_error TypeError
132
+ expect{ @gio4.write @outF, @default_data }.to raise_error TypeError
133
+ expect{ @gio5.write @outF, @default_data }.to raise_error TypeError
114
134
  end
115
135
  end
116
136
 
@@ -121,26 +141,36 @@ describe General::GIO do
121
141
  @gio1.write @out1, @applied_data
122
142
  @gio2.write @out2, @applied_data
123
143
  @gio3.write @out3, @applied_data
144
+ @gio4.write @out4, @applied_data
145
+ @gio5.write @out5, @applied_data
124
146
 
125
147
  expect(IO.read @out1).to eql @applied_text1
126
148
  expect(IO.read @out2).to eql @applied_text2
127
149
  expect(IO.read @out3).to eql @applied_text3
150
+ expect(IO.read @out4).to eql @applied_text4
151
+ expect(IO.read @out4).to eql @applied_text4
128
152
  end
129
153
 
130
154
  it "writes the given data to the given file io" do
131
155
  File.open(@out1, "w+") { |ios| @gio1.write ios, @applied_data }
132
156
  File.open(@out2, "w+") { |ios| @gio2.write ios, @applied_data }
133
157
  File.open(@out3, "w+") { |ios| @gio3.write ios, @applied_data }
158
+ File.open(@out4, "w+") { |ios| @gio4.write ios, @applied_data }
159
+ File.open(@out5, "w+") { |ios| @gio5.write ios, @applied_data }
134
160
 
135
161
  expect(IO.read @out1).to eql @applied_text1
136
162
  expect(IO.read @out2).to eql @applied_text2
137
163
  expect(IO.read @out3).to eql @applied_text3
164
+ expect(IO.read @out4).to eql @applied_text4
165
+ expect(IO.read @out5).to eql @applied_text5
138
166
  end
139
167
 
140
168
  it "raises TypeError if target is not string or io" do
141
169
  expect{ @gio1.write @outF, @applied_data }.to raise_error TypeError
142
170
  expect{ @gio2.write @outF, @applied_data }.to raise_error TypeError
143
171
  expect{ @gio3.write @outF, @applied_data }.to raise_error TypeError
172
+ expect{ @gio4.write @outF, @applied_data }.to raise_error TypeError
173
+ expect{ @gio5.write @outF, @applied_data }.to raise_error TypeError
144
174
  end
145
175
  end
146
176
  end
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: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anshul Kharbanda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -39,20 +39,30 @@ files:
39
39
  - exp/expected/applied1.txt
40
40
  - exp/expected/applied2.txt
41
41
  - exp/expected/applied3.txt
42
+ - exp/expected/applied4.txt
43
+ - exp/expected/applied5.txt
42
44
  - exp/expected/default1.txt
43
45
  - exp/expected/default2.txt
44
46
  - exp/expected/default3.txt
47
+ - exp/expected/default4.txt
48
+ - exp/expected/default5.txt
45
49
  - exp/out/sample1.txt
46
50
  - exp/out/sample2.txt
47
51
  - exp/out/sample3.txt
52
+ - exp/out/sample4.txt
53
+ - exp/out/sample5.txt
48
54
  - exp/templates/sample0.general
55
+ - exp/templates/sample0a.general
49
56
  - exp/templates/sample1.general
50
57
  - exp/templates/sample2.general
51
58
  - exp/templates/sample3.general
59
+ - exp/templates/sample4.general
60
+ - exp/templates/sample5.general
52
61
  - exp/templates/sampleE0.general
53
62
  - exp/templates/sampleE1.general
54
63
  - exp/templates/sampleE2.general
55
64
  - exp/templates/sampleE3.general
65
+ - exp/templates/sub/sample_base.general
56
66
  - lib/gdothash.rb
57
67
  - lib/general.rb
58
68
  - lib/gerror.rb