cakery 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e84a3bb4b2627490d205e70102ab4a11a11b2d6c
4
- data.tar.gz: 9e73535a703ee70c6154e405b2b8d3f13be2b446
3
+ metadata.gz: a5f2fd85093c1a2c603484a085d84a4d6cd437aa
4
+ data.tar.gz: 2b20adf0352b472af21526c5b3b26a9178a9fea4
5
5
  SHA512:
6
- metadata.gz: a0ede44436c29a6afa4698a5ec0fcca588b83f87477fa00e946af55ab6fd5838d4f8a35e823c7c36272933872c7944e410db882082b82b9a61517cf223172e1d
7
- data.tar.gz: fe07bb06a9853d5a5856e46773a836b45b9ec5be33cb68129d9e7b1a650788173b0e9224613a2abdb2c7c54a78d0764cb770f7068f4cf5b31cf173b86ba90e5a
6
+ metadata.gz: 050f3a305833d10fe29ad2035a7b3841f9b4f102baa93f79bddbe63fc232eed2322f2f4b5b665f97ab5b4e3f6e85744de2dbc8f8b25342473ecf6e336d62032b
7
+ data.tar.gz: 8f4578d6be1061b15d0b94998e37477aa49a1b75dca9d03e7ca1166f81a47db2fff49f39d92a3424aecdd5c6dbf65882c1f148d7e1d53e0583617f19de1a1dd9
@@ -28,12 +28,12 @@ module Cakery
28
28
  end
29
29
 
30
30
  def method_missing name, *args, &block
31
- if name =~ /=/
32
- name = ('@'+name.to_s.gsub(/=/, "")).to_sym
33
- self.instance_variable_set(name, args.first)
34
- else
31
+ #if name =~ /=/
32
+ #name = ('@'+name.to_s.gsub(/=/, "")).to_sym
33
+ #self.instance_variable_set(name, args.first)
34
+ #else
35
35
  return CakeERBContextTwoClauseHelper.new(self, name)
36
- end
36
+ #end
37
37
  end
38
38
 
39
39
  def get_binding
@@ -50,6 +50,31 @@ module Cakery
50
50
  @macros = []
51
51
  end
52
52
 
53
+ def <(e)
54
+ vname = ('@'+@name.to_s.gsub(/=/, "")).to_sym
55
+ out = ""
56
+
57
+ #Append all files or it's a macro class
58
+ if e.class == String
59
+ out = e
60
+
61
+ #Run through each macro and run it in the reverse
62
+ #order that we put it in so that
63
+ #r.var << MyMacroA << MyMacroB << "./directory" will execute first MyMacroB and then MyMacroA
64
+ while macro = @macros.pop
65
+ out = macro.new.process(out)
66
+ end
67
+
68
+ @erb_context.instance_variable_set(vname, "") unless @erb_context.instance_variable_defined?(vname)
69
+ v = @erb_context.instance_variable_get(vname)
70
+ out = "\n" + out unless v == ""
71
+ v += out
72
+ @erb_context.instance_variable_set(vname, v)
73
+ else
74
+ raise "< operator needs a string, you passed #{e.inspect}"
75
+ end
76
+ end
77
+
53
78
  def <<(e)
54
79
  vname = ('@'+@name.to_s.gsub(/=/, "")).to_sym
55
80
  out = ""
@@ -72,7 +97,6 @@ module Cakery
72
97
  v = @erb_context.instance_variable_get(vname)
73
98
  v += out
74
99
  @erb_context.instance_variable_set(vname, v)
75
-
76
100
  else
77
101
  #Assume it's a macro, save it onto the stack
78
102
  @macros << e
@@ -1,3 +1,3 @@
1
1
  module Cakery
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -28,14 +28,13 @@ RSpec.describe "Baking" do
28
28
  secret = SecureRandom.hex
29
29
 
30
30
  c = Cakery.new(cp) do |r|
31
- r.secret = secret
31
+ r.secret < secret
32
32
  end
33
33
 
34
34
  c.bake
35
35
  expect(c.src).to eq("#{secret}\n")
36
36
  end
37
37
 
38
-
39
38
  it "can use a directory append" do
40
39
  cp = cakery_path "test2"
41
40
 
@@ -106,6 +105,38 @@ RSpec.describe "Baking" do
106
105
  expect(c.src).to eq("goodbye world 1\ngoodbye world 2\n\n")
107
106
  end
108
107
 
108
+ it "supports macros via <" do
109
+ cp = cakery_path "test4"
110
+
111
+ class MyMacro < Cakery::Macro
112
+ def process str
113
+ out = ""
114
+ str.split("\n").each do |line|
115
+ if line =~ /hello/
116
+ out += line.gsub(/hello/, "goodbye")
117
+ else
118
+ out += line
119
+ end
120
+
121
+ out += "\n"
122
+ end
123
+ out
124
+ end
125
+ end
126
+
127
+ c = Cakery.new(cp) do |r|
128
+ r.secret << MyMacro < "hello world 1\ngoodbye world 2\n"
129
+ end
130
+
131
+ cd_proj "test4" do
132
+ c.bake
133
+ end
134
+
135
+ #Started out with hello world 1, goodbye world 2 -> goodbye world 1, goodbye world 2
136
+ expect(c.src).to eq("goodbye world 1\ngoodbye world 2\n\n")
137
+ end
138
+
139
+
109
140
  #it "supports stacked macros" do
110
141
  #cp = cakery_path "test4"
111
142
 
@@ -139,17 +170,65 @@ RSpec.describe "Baking" do
139
170
  #expect(c.src).to eq("fuck_you world 1\nfuck_you world 2\n\n")
140
171
  #end
141
172
 
142
- #it "supports two dir sources to one variable" do
143
- #cp = cakery_path "test5"
173
+ it "supports stacked macros" do
174
+ cp = cakery_path "test4"
144
175
 
145
- #c = Cakery.new(cp) do |r|
146
- #r.secret << "./secret1/*"
147
- #r.secret << "./secret2/*"
148
- #end
176
+ class MyMacro < Cakery::Macro
177
+ def process str
178
+ out = ""
179
+ str.split("\n").each do |line|
180
+ if line =~ /hello/
181
+ out += line.gsub(/hello/, "goodbye")
182
+ elsif line =~ /goodbye/
183
+ out += line.gsub(/goodbye/, "fuck_you")
184
+ else
185
+ out += line
186
+ end
187
+
188
+ out += "\n"
189
+ end
190
+ out
191
+ end
192
+ end
193
+
194
+ c = Cakery.new(cp) do |r|
195
+ r.secret << MyMacro << MyMacro < "hello world 1\ngoodbye world 2\n\n"
196
+ end
197
+
198
+ cd_proj "test4" do
199
+ c.bake
200
+ end
201
+
202
+ #Started out with hello world 1, goodbye world 2 -> goodbye world 1, goodbye world 2
203
+ expect(c.src).to eq("fuck_you world 1\nfuck_you world 2\n\n")
204
+ end
205
+
206
+ it "supports two dir sources to one variable" do
207
+ cp = cakery_path "test5"
208
+
209
+ c = Cakery.new(cp) do |r|
210
+ r.secret << "./secret1/*"
211
+ r.secret << "./secret2/*"
212
+ end
213
+
214
+ cd_proj "test5" do
215
+ c.bake
216
+ end
217
+ expect(c.src).to eq("hello world\ngoodbye world\n\n")
218
+ end
219
+
220
+ it "supports two string sources to one variable" do
221
+ cp = cakery_path "test5"
222
+
223
+ c = Cakery.new(cp) do |r|
224
+ r.secret < "hello"
225
+ r.secret < "world"
226
+ end
227
+
228
+ cd_proj "test5" do
229
+ c.bake
230
+ end
231
+ expect(c.src).to eq("hello\nworld\n")
232
+ end
149
233
 
150
- #cd_proj "test5" do
151
- #c.bake
152
- #end
153
- #expect(c.src).to eq("hello world\ngoodbye world\n\n")
154
- #end
155
234
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cakery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo