general 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +166 -20
  3. data/Rakefile +11 -2
  4. data/exp/expected/applied1.txt +1 -0
  5. data/exp/expected/applied2.txt +3 -0
  6. data/exp/expected/applied3.txt +9 -0
  7. data/exp/expected/default1.txt +1 -0
  8. data/exp/expected/default2.txt +3 -0
  9. data/exp/expected/default3.txt +9 -0
  10. data/exp/out/sample1.txt +1 -0
  11. data/exp/out/sample2.txt +3 -0
  12. data/exp/out/sample3.txt +9 -0
  13. data/exp/templates/sample0.general +7 -0
  14. data/exp/templates/sample1.general +1 -0
  15. data/exp/templates/sample2.general +3 -0
  16. data/exp/templates/sample3.general +4 -0
  17. data/exp/templates/sampleE0.general +7 -0
  18. data/exp/templates/sampleE1.general +3 -0
  19. data/exp/templates/sampleE2.general +3 -0
  20. data/exp/templates/sampleE3.general +7 -0
  21. data/lib/general.rb +3 -3
  22. data/lib/gerror.rb +33 -0
  23. data/lib/goperations.rb +95 -27
  24. data/lib/gpartials/garrayplaceholder.rb +87 -0
  25. data/lib/gpartials/gfullplaceholder.rb +63 -0
  26. data/lib/gpartials/gpartial.rb +11 -1
  27. data/lib/gpartials/gplaceholder.rb +1 -52
  28. data/lib/gpartials/gspecial.rb +81 -0
  29. data/lib/gpartials/gtext.rb +5 -33
  30. data/lib/gprepartials/gextend.rb +42 -0
  31. data/lib/gprepartials/ginclude.rb +47 -0
  32. data/lib/gprepartials/gprepartial.rb +45 -0
  33. data/lib/gprepartials/gpretext.rb +33 -0
  34. data/lib/gprepartials/gyield.rb +33 -0
  35. data/lib/{templates → gtemplates}/gbasetemplate.rb +46 -3
  36. data/lib/gtemplates/gio.rb +143 -0
  37. data/lib/gtemplates/gmeta.rb +106 -0
  38. data/lib/{templates → gtemplates}/gtemplate.rb +10 -30
  39. data/lib/{templates → gtemplates}/gtimeformat.rb +6 -12
  40. data/spec/gdothash_spec.rb +6 -10
  41. data/spec/goperations_spec.rb +112 -82
  42. data/spec/gpartial_garrayplaceholder_spec.rb +165 -0
  43. data/spec/gpartial_gfullplaceholder_spec.rb +82 -0
  44. data/spec/gpartial_gplaceholder_spec.rb +237 -0
  45. data/spec/gpartial_gspecial_spec.rb +88 -0
  46. data/spec/gpartial_gtext_spec.rb +87 -0
  47. data/spec/gtamplate_gtemplate_spec.rb +266 -0
  48. data/spec/gtemplate_gio_spec.rb +147 -0
  49. data/spec/gtemplate_gtimeformat_spec.rb +77 -0
  50. data/spec/spec_require.rb +7 -4
  51. metadata +41 -13
  52. data/exp/future.general +0 -11
  53. data/exp/out.txt +0 -1
  54. data/exp/sample.general +0 -1
  55. data/lib/templates/gio.rb +0 -68
  56. data/spec/garrayplaceholder_spec.rb +0 -163
  57. data/spec/gplaceholder_spec.rb +0 -300
  58. data/spec/gtemplates_spec.rb +0 -480
  59. data/spec/gtext_spec.rb +0 -150
@@ -0,0 +1,165 @@
1
+ # General is a templating system in ruby
2
+ # Copyright (C) 2016 Anshul Kharbanda
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require_relative "spec_require"
18
+
19
+ # Describe General::GArrayPlaceholder
20
+ #
21
+ # Represents an array placeholder partial in a GTemplate
22
+ #
23
+ # Author: Anshul Kharbanda
24
+ # Created: 7 - 1 - 2016
25
+ describe General::GArrayPlaceholder do
26
+ before :all do
27
+ # -----------DATA-----------
28
+
29
+ @arrayname1 = :arg1
30
+ @arrayname2 = :arg2
31
+ @arrayname3 = :arg3
32
+ @hash = {
33
+ arg1: [
34
+ { subarg: "Eeeeyyy" },
35
+ { subarg: "Oyyyeee" },
36
+ { subarg: "Aaayyyy" }
37
+ ],
38
+ arg2: "Butter Milk Eggs Bacon Cleaner",
39
+ arg3: "Buttered Bacon, Milked Eggs, Cleaning Butter"
40
+ }
41
+
42
+ @delim = "\n"
43
+ @text1 = "Subarg: @(subarg)"
44
+ @text2 = "# @#"
45
+ @operation = :split
46
+ @arguments = [",\s*"]
47
+
48
+ # ---------------------------OUTPUT---------------------------
49
+
50
+ @out1 = @hash[@arrayname1]
51
+ .collect{|e| "Subarg: #{e[:subarg]}"}
52
+ .join(General::GArrayPlaceholder::DEFAULT_DELIMETER)
53
+ @out2 = @hash[@arrayname1]
54
+ .collect{|e| "Subarg: #{e[:subarg]}"}
55
+ .join(@delim)
56
+ @out3 = General::GOperations.send(@operation, @hash[@arrayname2])
57
+ .collect{|e| "# #{e}"}
58
+ .join(@delim)
59
+ @out4 = General::GOperations.send(@operation, @hash[@arrayname3], *@arguments)
60
+ .collect{|e| "# #{e}"}
61
+ .join(@delim)
62
+
63
+ # ------------------------------------------PARTIALS------------------------------------------
64
+
65
+ @partial1 = General::GArrayPlaceholder.new name: @arrayname1,
66
+ text: @text1
67
+ @partial2 = General::GArrayPlaceholder.new name: @arrayname1,
68
+ text: @text1,
69
+ delimeter: @delim
70
+ @partial3 = General::GArrayPlaceholder.new name: @arrayname2,
71
+ text: @text2,
72
+ delimeter: @delim,
73
+ operation: @operation
74
+ @partial4 = General::GArrayPlaceholder.new name: @arrayname3,
75
+ text: @text2,
76
+ delimeter: @delim,
77
+ operation: @operation,
78
+ arguments: @arguments.collect{|a| " \"#{a}\""}.join
79
+
80
+ # -------------------------------------------STRING-------------------------------------------
81
+
82
+ @string1 = "@[#{@arrayname1}] #{@text1} @[#{General::GArrayPlaceholder::DEFAULT_DELIMETER.inspect[1...-1]}]"
83
+ @string2 = "@[#{@arrayname1}] #{@text1} @[#{@delim.inspect[1...-1]}]"
84
+ @string3 = "@[#{@arrayname2} -> #{@operation}] #{@text2} @[#{@delim.inspect[1...-1]}]"
85
+ @string4 = "@[#{@arrayname3} -> #{@operation} #{@arguments.collect{|s| "\"#{s}\""}.join(" ")}] #{@text2} @[#{@delim.inspect[1...-1]}]"
86
+ end
87
+
88
+ # Describe General::GArrayPlaceholder::new
89
+ #
90
+ # Initializes the GPlaceholder with the given match
91
+ #
92
+ # Parameter: match - the match data from the string being parsed
93
+ describe '::new' do
94
+ it 'creates a new GArrayPlaceholder with the given input data' do
95
+ expect(@partial1).to be_an_instance_of General::GArrayPlaceholder
96
+ expect(@partial2).to be_an_instance_of General::GArrayPlaceholder
97
+ expect(@partial3).to be_an_instance_of General::GArrayPlaceholder
98
+ expect(@partial4).to be_an_instance_of General::GArrayPlaceholder
99
+ end
100
+ end
101
+
102
+ # Describe General::GArrayPlaceholder#apply
103
+ #
104
+ # Returns the value of the array placeholder in the given data
105
+ # formatted by the given GArrayPlaceholder and joined by the given delimeter
106
+ #
107
+ # Parameter: data - the data being applied
108
+ #
109
+ # Return: the value of the array placeholder in the given data
110
+ # formatted by the given GArrayPlaceholder and joined by the given delimeter
111
+ describe '#apply' do
112
+ it 'applies the given data array formatted according to the info in the GArrayPlaceholder' do
113
+ expect(@partial1.apply @hash).to eql @out1
114
+ expect(@partial2.apply @hash).to eql @out2
115
+ expect(@partial3.apply @hash).to eql @out3
116
+ expect(@partial4.apply @hash).to eql @out4
117
+ end
118
+ end
119
+
120
+ # Describe General::GArrayPlaceholder#string
121
+ #
122
+ # Returns the string representation of the GArrayPlaceholder
123
+ #
124
+ # Parameter: first - true if the GArrayPlaceholder is the first of it's time
125
+ #
126
+ # Returns: the string representation of the GArrayPlaceholder
127
+ describe '#string' do
128
+ it 'returns the string of the GArrayPlaceholder' do
129
+ expect(@partial1.string).to eql @string1
130
+ expect(@partial2.string).to eql @string2
131
+ expect(@partial3.string).to eql @string3
132
+ expect(@partial4.string).to eql @string4
133
+ expect(@partial1.string true).to eql @string1
134
+ expect(@partial2.string true).to eql @string2
135
+ expect(@partial3.string true).to eql @string3
136
+ expect(@partial4.string true).to eql @string4
137
+ expect(@partial1.string false).to eql @string1
138
+ expect(@partial2.string false).to eql @string2
139
+ expect(@partial3.string false).to eql @string3
140
+ expect(@partial4.string false).to eql @string4
141
+ end
142
+ end
143
+
144
+ # Describe General::GArrayPlaceholder#regex (depricated)
145
+ #
146
+ # Throws TypeError
147
+ #
148
+ # Parameter: first - true if the placeholder is the first of it's kind
149
+ describe '#regex (depricated)' do
150
+ it 'raises TypeError' do
151
+ expect { @partial1.regex }.to raise_error TypeError
152
+ expect { @partial2.regex }.to raise_error TypeError
153
+ expect { @partial3.regex }.to raise_error TypeError
154
+ expect { @partial4.regex }.to raise_error TypeError
155
+ expect { @partial1.regex true }.to raise_error TypeError
156
+ expect { @partial2.regex true }.to raise_error TypeError
157
+ expect { @partial3.regex true }.to raise_error TypeError
158
+ expect { @partial4.regex true }.to raise_error TypeError
159
+ expect { @partial1.regex false }.to raise_error TypeError
160
+ expect { @partial2.regex false }.to raise_error TypeError
161
+ expect { @partial3.regex false }.to raise_error TypeError
162
+ expect { @partial4.regex false }.to raise_error TypeError
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,82 @@
1
+ # General is a templating system in ruby
2
+ # Copyright (C) 2016 Anshul Kharbanda
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require_relative "spec_require"
18
+
19
+ # Inserts the full data value passed into the template
20
+ #
21
+ # Author: Anshul Kharbanda
22
+ # Created: 1 - 19 - 2016
23
+ describe General::GFullPlaceholder do
24
+ before :all do
25
+ @full = General::GFullPlaceholder.new({})
26
+ @data1 = "Hello World!"
27
+ end
28
+
29
+ # Describing General::GFullPlaceholder#new
30
+ #
31
+ # Creates a new GFullPlaceholder with the given match
32
+ #
33
+ # Parameter: match - the match data from the string being parsed
34
+ describe '::new' do
35
+ it 'creates a new GFullPlaceholder' do
36
+ expect(@full).to be_an_instance_of General::GFullPlaceholder
37
+ end
38
+ end
39
+
40
+ # Describing General::GFullPlaceholder#apply
41
+ #
42
+ # Returns a string representation of the given data
43
+ #
44
+ # Parameter: data - the data being applied
45
+ #
46
+ # Returns: a string representation of the given data
47
+ describe '#apply' do
48
+ it 'returns a string representation of the entire data value given' do
49
+ expect(@full.apply @data1).to eql @data1
50
+ end
51
+ end
52
+
53
+ # Describing General::GFullPlaceholder#string
54
+ #
55
+ # Returns a string representation of the GFullPlaceholder
56
+ #
57
+ # Parameter: first - true if this is the first in a given template
58
+ #
59
+ # Returns: a string representation of the GFullPlaceholder
60
+ describe '#string' do
61
+ it 'returns a string reprsentation of the GFullPlaceholder' do
62
+ expect(@full.string).to eql General::GFullPlaceholder::STRING
63
+ expect(@full.string true).to eql General::GFullPlaceholder::STRING
64
+ expect(@full.string false).to eql General::GFullPlaceholder::STRING
65
+ end
66
+ end
67
+
68
+ # Describing General::GFullPlaceholder#regex (depricated)
69
+ #
70
+ # Raises TypeError
71
+ #
72
+ # Parameter: first - true if this is the first in a given template
73
+ #
74
+ # Raises: TypeError
75
+ describe '#regex (depricated)' do
76
+ it 'raises TypeError' do
77
+ expect{@full.regex}.to raise_error TypeError
78
+ expect{@full.regex true}.to raise_error TypeError
79
+ expect{@full.regex false}.to raise_error TypeError
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,237 @@
1
+ # General is a templating system in ruby
2
+ # Copyright (C) 2016 Anshul Kharbanda
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require_relative "spec_require"
18
+
19
+ # Represents a placeholder partial in a GTemplate
20
+ #
21
+ # Author: Anshul Kharbanda
22
+ # Created: 7 - 1 - 2016
23
+ describe General::GPlaceholder do
24
+ before :all do
25
+ # Placename
26
+ @placename1 = :plac1
27
+ @placename2 = :plac2
28
+ @placename3 = :plac3
29
+ @placename4 = :plac4
30
+ @placename5 = :"plac5.subarg"
31
+
32
+ # Hash
33
+ @hash = General::GDotHash.new
34
+ @hash[@placename1] = "foobar"
35
+ @hash[@placename3] = "barbaz"
36
+ @hash[@placename4] = "jujar"
37
+ @hash[@placename5] = "dudar"
38
+
39
+ # Default hash
40
+ @defaults = General::GDotHash.new
41
+
42
+ # ------------PLACEHOLDER------------
43
+ @result1 = @hash[@placename1]
44
+ @partial1 = General::GPlaceholder.new [
45
+ [:name, @placename1]
46
+ ].to_h, @defaults
47
+ @string1 = "@(#{@placename1})"
48
+ @string_first1 = "@(#{@placename1})"
49
+ @regex1 = "\\k<#{@placename1}>"
50
+ @regex_first1 = "(?<#{@placename1}>.*)"
51
+
52
+ # --------------DEFAULT--------------
53
+ @default2 = "foo2"
54
+ @result2 = "foo2"
55
+ @partial2 = General::GPlaceholder.new [
56
+ [:name, @placename2],
57
+ [:default, @default2]
58
+ ].to_h, @defaults
59
+ @string2 = "@(#{@placename2})"
60
+ @string_first2 = "@(#{@placename2}:" \
61
+ + " #{@default2})"
62
+ @regex2 = "\\k<#{@placename2}>"
63
+ @regex_first2 = "(?<#{@placename2}>.*)"
64
+
65
+ # -------------OPERATION-------------
66
+ @operation3 = "capitalize"
67
+ @result3 = General::GOperations.send(
68
+ @operation3.to_sym,
69
+ @hash[@placename3]
70
+ )
71
+ @partial3 = General::GPlaceholder.new [
72
+ [:name, @placename3],
73
+ [:operation, @operation3]
74
+ ].to_h, @defaults
75
+ @string3 = "@(#{@placename3})"
76
+ @string_first3 = "@(#{@placename3}" \
77
+ + " -> #{@operation3})"
78
+ @regex3 = "\\k<#{@placename3}>"
79
+ @regex_first3 = "(?<#{@placename3}>.*)"
80
+
81
+ # -------------ARGUMENTS-------------
82
+ @operation4 = "capitalize"
83
+ @arguments4 = ["all"]
84
+ @result4 = General::GOperations.send(
85
+ @operation4.to_sym,
86
+ @hash[@placename4],
87
+ *@arguments4
88
+ )
89
+ @partial4 = General::GPlaceholder.new [
90
+ [:name, @placename4],
91
+ [:operation, @operation4],
92
+ [:arguments, @arguments4.join(" ")]
93
+ ].to_h, @defaults
94
+ @string4 = "@(#{@placename4})"
95
+ @string_first4 = "@(#{@placename4}" \
96
+ + " -> #{@operation4} " \
97
+ + "#{@arguments4.collect {|s| "\"#{s}\""}.join " "})"
98
+ @regex4 = "\\k<#{@placename4}>"
99
+ @regex_first4 = "(?<#{@placename4}>.*)"
100
+
101
+ # -----------DOT NOTATION------------
102
+ keys = @placename5.to_s.split(".").collect(&:to_sym)
103
+ @result5 = @hash[keys[0]][keys[1]]
104
+ @partial5 = General::GPlaceholder.new [
105
+ [:name, @placename5]
106
+ ].to_h, @defaults
107
+ @string5 = "@(#{@placename5})"
108
+ @string_first5 = "@(#{@placename5})"
109
+ @regex5 = "\\k<#{@placename5}>"
110
+ @regex_first5 = "(?<#{@placename5}>.*)"
111
+ end
112
+
113
+ # Describe General::GPlaceholder::new
114
+ #
115
+ # Initializes the GPlaceholder with the given match
116
+ #
117
+ # Parameter: match - the match data from the string being parsed
118
+ describe '::new' do
119
+ it 'creaes a GPlaceholder with the given data' do
120
+ # -------------------------------------PLACEHOLDER---------------------------------------
121
+ expect(@partial1).to be_an_instance_of General::GPlaceholder
122
+ expect(@partial1.instance_variable_get :@name).to eql @placename1
123
+ expect(@partial1.instance_variable_get :@operation).to be_nil
124
+ expect(@partial1.instance_variable_get :@arguments).to be_empty
125
+
126
+ # ---------------------------------------DEFAULT-----------------------------------------
127
+ expect(@partial2).to be_an_instance_of General::GPlaceholder
128
+ expect(@partial2.instance_variable_get :@name).to eql @placename2
129
+ expect(@partial2.instance_variable_get :@operation).to be_nil
130
+ expect(@partial2.instance_variable_get :@arguments).to be_empty
131
+ expect(@defaults[@placename2]).to eql @default2
132
+
133
+ # --------------------------------------OPERATION----------------------------------------
134
+ expect(@partial3).to be_an_instance_of General::GPlaceholder
135
+ expect(@partial3.instance_variable_get :@name).to eql @placename3
136
+ expect(@partial3.instance_variable_get :@operation).to eql @operation3
137
+ expect(@partial3.instance_variable_get :@arguments).to be_empty
138
+
139
+ # --------------------------------------ARGUMENTS----------------------------------------
140
+ expect(@partial4).to be_an_instance_of General::GPlaceholder
141
+ expect(@partial4.instance_variable_get :@name).to eql @placename4
142
+ expect(@partial4.instance_variable_get :@operation).to eql @operation4
143
+ expect(@partial4.instance_variable_get :@arguments).to eql @arguments4
144
+
145
+ # -------------------------------------DOT NOTATION--------------------------------------
146
+ expect(@partial5).to be_an_instance_of General::GPlaceholder
147
+ expect(@partial5.instance_variable_get :@name).to eql @placename5
148
+ expect(@partial5.instance_variable_get :@operation).to be_nil
149
+ expect(@partial5.instance_variable_get :@arguments).to be_empty
150
+ end
151
+ end
152
+
153
+ # Describe General::GPlaceholder#apply
154
+ #
155
+ # Returns the value of the placeholder in the given data
156
+ # with the given operation performed on it
157
+ #
158
+ # Parameter: data - the data being applied
159
+ #
160
+ # Return: the value of the placeholder in the given data
161
+ # with the given operation performed on it
162
+ describe '#apply' do
163
+ it 'returns the value in the data/default at the name (with operation and arguments applied if given)' do
164
+ expect(@partial1.apply @hash).to eql @result1
165
+ expect(@partial2.apply @hash).to eql @result2
166
+ expect(@partial3.apply @hash).to eql @result3
167
+ expect(@partial4.apply @hash).to eql @result4
168
+ expect(@partial5.apply @hash).to eql @result5
169
+ end
170
+ end
171
+
172
+ # Describe General::GTemplate#string
173
+ #
174
+ # Returns the string representation of the placeholder
175
+ #
176
+ # Parameter: first - true if the placeholder is the first of its kind in the GTemplate
177
+ #
178
+ # Return: the string representation of the placeholder
179
+ describe '#string' do
180
+ # -------------------------------------NO FIRST---------------------------------------
181
+ it 'returns the first string representation of the placeholder by default' do
182
+ expect(@partial1.string).to eql @string_first1
183
+ expect(@partial2.string).to eql @string_first2
184
+ expect(@partial3.string).to eql @string_first3
185
+ expect(@partial4.string).to eql @string_first4
186
+ end
187
+
188
+ # ------------------------------------TRUE FIRST--------------------------------------
189
+ it 'returns the first string representation of the placeholder when first is true' do
190
+ expect(@partial1.string true).to eql @string_first1
191
+ expect(@partial2.string true).to eql @string_first2
192
+ expect(@partial3.string true).to eql @string_first3
193
+ expect(@partial4.string true).to eql @string_first4
194
+ end
195
+
196
+ # -----------------------------------FALSE FIRST--------------------------------------
197
+ it 'returns the string representation of the placeholder when first is false' do
198
+ expect(@partial1.string false).to eql @string1
199
+ expect(@partial2.string false).to eql @string2
200
+ expect(@partial3.string false).to eql @string3
201
+ expect(@partial4.string false).to eql @string4
202
+ end
203
+ end
204
+
205
+ # Describe General::GTemplate#regex (depricated)
206
+ #
207
+ # Returns the string as a regex
208
+ #
209
+ # Parameter: first - true if the placeholder is the first of its kind in the GTemplate
210
+ #
211
+ # Returns: the string as a regex
212
+ describe '#regex (depricated)' do
213
+ # -------------------------------------NO FIRST---------------------------------------
214
+ it 'returns the first regex representation of the placeholder by default' do
215
+ expect(@partial1.regex).to eql @regex_first1
216
+ expect(@partial2.regex).to eql @regex_first2
217
+ expect(@partial3.regex).to eql @regex_first3
218
+ expect(@partial4.regex).to eql @regex_first4
219
+ end
220
+
221
+ # ------------------------------------TRUE FIRST--------------------------------------
222
+ it 'returns the first regex representation of the placeholder when first is true' do
223
+ expect(@partial1.regex true).to eql @regex_first1
224
+ expect(@partial2.regex true).to eql @regex_first2
225
+ expect(@partial3.regex true).to eql @regex_first3
226
+ expect(@partial4.regex true).to eql @regex_first4
227
+ end
228
+
229
+ # -----------------------------------FALSE FIRST--------------------------------------
230
+ it 'returns the regex representation of the placeholder when first is false' do
231
+ expect(@partial1.regex false).to eql @regex1
232
+ expect(@partial2.regex false).to eql @regex2
233
+ expect(@partial3.regex false).to eql @regex3
234
+ expect(@partial4.regex false).to eql @regex4
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,88 @@
1
+ # General is a templating system in ruby
2
+ # Copyright (C) 2016 Anshul Kharbanda
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require_relative "spec_require"
18
+
19
+ # Describe General::GSpecial
20
+ #
21
+ # Represents a special character in a GTemplate
22
+ #
23
+ # Author: Anshul Kharbanda
24
+ # Created: 7 - 1 - 2016
25
+ describe General::GSpecial do
26
+ before :all do
27
+ @key = "at"
28
+ @text = "@"
29
+ @regex = /@/
30
+ @partial = General::GSpecial.new key: @key
31
+ end
32
+
33
+ # Describe General::GSpecial::new
34
+ #
35
+ # Creates the GSpecial with the given match
36
+ #
37
+ # Parameter: match - the match object of the GSpecial
38
+ describe '::new' do
39
+ it 'creates the GSpecial with the given match object' do
40
+ expect(@partial).to be_an_instance_of General::GSpecial
41
+ expect(@partial.name).to eql General::GSpecial::PTNAME
42
+ expect(@partial.instance_variable_get :@text).to eql @text
43
+ end
44
+ end
45
+
46
+ # Describe General::GSpecial#regex
47
+ #
48
+ # Returns the special character
49
+ #
50
+ # Parameter: data - the data to apply to the partial
51
+ #
52
+ # Returns: the special character
53
+ describe '#apply' do
54
+ it 'returns the special character' do
55
+ expect(@partial.apply({})).to eql @text
56
+ end
57
+ end
58
+
59
+ # Describe General::GSpecial#string
60
+ #
61
+ # Returns the string representation of the GSpecial
62
+ #
63
+ # Parameter: first - true if this partial is the first of it's kind in a GTemplate
64
+ #
65
+ # Returns: the string representation of the GSpecial
66
+ describe '#string' do
67
+ it 'returns the string representation of the GSpecial' do
68
+ expect(@partial.string).to eql "@#{@key};"
69
+ expect(@partial.string false).to eql "@#{@key};"
70
+ expect(@partial.string true).to eql "@#{@key};"
71
+ end
72
+ end
73
+
74
+ # Describe General::GSpecial#regex (depricated)
75
+ #
76
+ # Returns the GSpecial as a regex
77
+ #
78
+ # Parameter: first - true if this partial is the first of it's kind in a GTemplate
79
+ #
80
+ # Returns: the GSpecial as a regex
81
+ describe '#regex (depricated)' do
82
+ it 'returns the regex representation of the GSpecial' do
83
+ expect(@partial.regex).to eql @regex
84
+ expect(@partial.regex false).to eql @regex
85
+ expect(@partial.regex true).to eql @regex
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,87 @@
1
+ # General is a templating system in ruby
2
+ # Copyright (C) 2016 Anshul Kharbanda
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require_relative "spec_require"
18
+
19
+ # Describe General::GText
20
+ #
21
+ # Represents a plain text partial in a GTemplate
22
+ #
23
+ # Author: Anshul Kharbanda
24
+ # Created: 7 - 1 - 2016
25
+ describe General::GText do
26
+ before :all do
27
+ @text = "foobar"
28
+ @regex = "foobar"
29
+ @partial = General::GText.new @text
30
+ end
31
+
32
+ # Describe General::GText::new
33
+ #
34
+ # Creates the GText with the given match
35
+ #
36
+ # Parameter: match - the match object of the GText
37
+ describe '::new' do
38
+ it 'creates the GText with the given to_s representable object' do
39
+ expect(@partial).to be_an_instance_of General::GText
40
+ expect(@partial.name).to eql General::GText::PTNAME
41
+ expect(@partial.instance_variable_get :@text).to eql @text
42
+ end
43
+ end
44
+
45
+ # Describe General::GText#apply
46
+ #
47
+ # Returns the text
48
+ #
49
+ # Parameter: data - the data to apply to the partial
50
+ #
51
+ # Returns: the text
52
+ describe '#apply' do
53
+ it 'returns the GText string, given a hash of data' do
54
+ expect(@partial.apply @hash).to eql @text
55
+ end
56
+ end
57
+
58
+ # Describe General::GText#string
59
+ #
60
+ # Returns the text as a string
61
+ #
62
+ # Parameter: first - true if this partial is the first of it's kind in a GTemplate
63
+ #
64
+ # Returns: the text as a string
65
+ describe '#string' do
66
+ it 'returns the string representation of the GText' do
67
+ expect(@partial.string).to eql @text
68
+ expect(@partial.string true).to eql @text
69
+ expect(@partial.string false).to eql @text
70
+ end
71
+ end
72
+
73
+ # Describe General::GText#regex (depricated)
74
+ #
75
+ # Returns the text as a regex
76
+ #
77
+ # Parameter: first - true if this partial is the first of it's kind in a GTemplate
78
+ #
79
+ # Returns: the text as a regex
80
+ describe '#regex (depricated)' do
81
+ it 'returns the regex representation of the GText' do
82
+ expect(@partial.regex).to eql @regex
83
+ expect(@partial.regex true).to eql @regex
84
+ expect(@partial.regex false).to eql @regex
85
+ end
86
+ end
87
+ end