adyen-admin 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGES.md +5 -0
- data/VERSION +1 -1
- data/lib/adyen-admin/skin.rb +89 -87
- data/spec/adyen-admin/skin_spec.rb +9 -11
- data/spec/fixtures/skins/DV3tf95f/skin.yml +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGVjODc0NDA1NzRiN2RlZDYyMDI4OGMwMTY0YWZmMDkxNDY2ODI0Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmExZDNiMGZkMDBhZDU0OGM3M2EwY2VkN2JiZGZkMjViZjViOTkxMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTQxZTYwMjkwODRlY2ZkMTdjMzNiNmVhNTZkM2RlNDlkNTI4OTM5MmYxZWRh
|
10
|
+
NTY1Y2U5MjE3YWEwN2M2ZWE0MjQ1NGYxOWUzYzE3Y2Y2ZDBlNTY2YWYwYTIy
|
11
|
+
OTEyYjMwNzI1NTBkMDFiZmI0YmJlZWUxZjc5NDFkZjBhMzAwZWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTYxNmRmN2VjNjBiZDU0NDA0MDJkMWJhMzNmNjUyMjNmMDg4OTk3NzAwZTQx
|
14
|
+
MGZkMmQyOTViOTQ0OWNjODNiY2EwMmNkMzIwY2FmMDA2YTg4NGU4ZjMzZWQ2
|
15
|
+
OTFiMzUyY2I5NDYzNGM5ZmEzN2YzMTU1ZDQ1NGY3ZDhiMTg0NmI=
|
data/CHANGES.md
CHANGED
@@ -5,6 +5,11 @@
|
|
5
5
|
* add CLI binaries (to compile + upload) -> read from .adyenrc file
|
6
6
|
* make compatible with Live system
|
7
7
|
|
8
|
+
## v0.0.18 - 16-11-2013
|
9
|
+
* include default_data in skin
|
10
|
+
* explicit path or code+name
|
11
|
+
* code cleanup
|
12
|
+
|
8
13
|
## v0.0.17 - 15-11-2013
|
9
14
|
* fixed upload
|
10
15
|
* gem updates
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.18
|
data/lib/adyen-admin/skin.rb
CHANGED
@@ -17,91 +17,99 @@ module Adyen
|
|
17
17
|
attr_reader :code, :name, :path
|
18
18
|
|
19
19
|
def initialize(attributes = {})
|
20
|
-
attributes
|
21
|
-
|
20
|
+
if attributes[:path] && attributes[:code]
|
21
|
+
raise ArgumentError, "Either :path or :code has to be provided"
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
if new_path = attributes[:path]
|
25
|
+
raise ArgumentError, ":path '#{new_path}' is not a valid skin" unless Skin.is_skin_path?(new_path)
|
26
|
+
@path = new_path
|
27
|
+
@code = skin_data[:code] || code_from_path(path)
|
28
|
+
@name = skin_data[:name] || name_from_path(path)
|
29
|
+
else
|
30
|
+
@code = attributes[:code]
|
31
|
+
raise ArgumentError, ":code is not provided" unless code
|
32
|
+
@name = attributes[:name]
|
33
|
+
@path = Skin.path_from_code(code) || Skin.generate_path(code, name)
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
class << self
|
38
|
+
def default_path
|
39
|
+
@default_path || "."
|
40
|
+
end
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
42
|
+
def default_path=(default_path)
|
43
|
+
@default_path = default_path
|
44
|
+
end
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
# union remote and local skins. Local skins are frozen to
|
47
|
+
# indicate no availble remote counter part which avoid update
|
48
|
+
def all
|
49
|
+
@all ||= {}.tap do |hash|
|
50
|
+
if Adyen::Admin.authenticated?
|
51
|
+
all_remote.each do |skin|
|
52
|
+
hash[skin.code] = skin unless hash[skin.code]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
all_local.each do |skin|
|
45
56
|
hash[skin.code] = skin unless hash[skin.code]
|
46
57
|
end
|
58
|
+
end.values
|
59
|
+
end
|
60
|
+
|
61
|
+
# fetch all remote skins
|
62
|
+
def all_remote
|
63
|
+
page = Adyen::Admin.get(SKINS)
|
64
|
+
page.search(".data tbody tr").map do |node|
|
65
|
+
Skin.new({
|
66
|
+
:code => node.search("a")[0].content.strip,
|
67
|
+
:name => node.search("td")[1].content.strip,
|
68
|
+
})
|
47
69
|
end
|
48
|
-
|
49
|
-
hash[skin.code] = skin unless hash[skin.code]
|
50
|
-
end
|
51
|
-
end.values
|
52
|
-
end
|
70
|
+
end
|
53
71
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
:code => node.search("a")[0].content.strip,
|
60
|
-
:name => node.search("td")[1].content.strip,
|
61
|
-
})
|
72
|
+
# fetch all local skins
|
73
|
+
def all_local
|
74
|
+
Dir[File.join(default_path.to_s, "*")].map do |skin_path|
|
75
|
+
Skin.new(:path => skin_path).freeze rescue nil
|
76
|
+
end.compact
|
62
77
|
end
|
63
|
-
end
|
64
78
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
79
|
+
# find a skin within remote + local ones
|
80
|
+
def find(skin_code)
|
81
|
+
all.select do |skin|
|
82
|
+
skin.code == skin_code
|
83
|
+
end.first
|
84
|
+
end
|
71
85
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
skin.code == skin_code
|
76
|
-
end.first
|
77
|
-
end
|
86
|
+
def purge_cache
|
87
|
+
@all = nil
|
88
|
+
end
|
78
89
|
|
79
|
-
|
80
|
-
|
81
|
-
|
90
|
+
def is_skin_path?(skin_path)
|
91
|
+
%w(skin.yml inc css js).any? do |sub_path|
|
92
|
+
File.exists?(File.join(skin_path.to_s, sub_path))
|
93
|
+
end
|
94
|
+
end
|
82
95
|
|
83
|
-
|
96
|
+
def path_from_code(code)
|
97
|
+
Dir[File.join(Skin.default_path, "**/*#{code}*")].first
|
98
|
+
end
|
84
99
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
if !skin_data.empty?
|
89
|
-
self.code = skin_data[:code]
|
90
|
-
self.name = skin_data[:name]
|
91
|
-
else
|
92
|
-
new_code, *new_name = File.basename(new_path).split("-").reverse
|
93
|
-
self.code ||= new_code
|
94
|
-
self.name ||= new_name.reverse.join("-")
|
95
|
-
raise ArgumentError if self.code && self.code != new_code
|
96
|
-
end
|
100
|
+
def generate_path(name, code)
|
101
|
+
dir_name = name.gsub(' ', '-').gsub(/[^a-z0-9-]/i, '')
|
102
|
+
File.expand_path File.join(Skin.default_path, [dir_name, code].compact.join("-"))
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
106
|
+
##################################
|
107
|
+
|
100
108
|
def get_file(filename)
|
101
|
-
if
|
102
|
-
File.join(
|
109
|
+
if path
|
110
|
+
File.join(path, filename).tap do |file|
|
103
111
|
if !File.exists?(file)
|
104
|
-
return File.join(File.dirname(
|
112
|
+
return File.join(File.dirname(path), parent_skin, filename)
|
105
113
|
end
|
106
114
|
end
|
107
115
|
end
|
@@ -140,13 +148,14 @@ module Adyen
|
|
140
148
|
|
141
149
|
def update
|
142
150
|
@skin_data = {
|
143
|
-
:name
|
144
|
-
:code
|
145
|
-
:uploaded_at
|
146
|
-
:version
|
151
|
+
:name => name,
|
152
|
+
:code => code,
|
153
|
+
:uploaded_at => Time.now.iso8601,
|
154
|
+
:version => remote_version,
|
147
155
|
:version_live => remote_version(:live),
|
148
156
|
:version_test => remote_version(:test),
|
149
157
|
:parent_skin => parent_skin,
|
158
|
+
:default_data => default_data,
|
150
159
|
}
|
151
160
|
File.open(skin_data_file, "w") do |file|
|
152
161
|
file.write @skin_data.to_yaml
|
@@ -163,7 +172,7 @@ module Adyen
|
|
163
172
|
|
164
173
|
def decompile(filename, backup = true)
|
165
174
|
# create backup of current, include any files
|
166
|
-
if
|
175
|
+
if path
|
167
176
|
if backup
|
168
177
|
compress(/(zip|lock)$/, ".backup.zip")
|
169
178
|
end
|
@@ -175,7 +184,7 @@ module Adyen
|
|
175
184
|
|
176
185
|
Zip::File.open(filename) do |zip_file|
|
177
186
|
zip_file.each do |file|
|
178
|
-
f_path = File.join(
|
187
|
+
f_path = File.join(path || decompile_path, file.name.gsub("#{code}/", ""))
|
179
188
|
FileUtils.mkdir_p(File.dirname(f_path))
|
180
189
|
if File.directory?(f_path)
|
181
190
|
`mkdir -p #{f_path}`
|
@@ -188,12 +197,12 @@ module Adyen
|
|
188
197
|
self.path ||= decompile_path
|
189
198
|
|
190
199
|
if backup
|
191
|
-
`mv .backup.zip #{File.join(
|
200
|
+
`mv .backup.zip #{File.join(path, ".backup.zip")}`
|
192
201
|
end
|
193
202
|
end
|
194
203
|
|
195
204
|
def compile(output, pattern = /<!-- ### inc\/([a-z]+) -->(.+?)<!-- ### -->/m)
|
196
|
-
raise ArgumentError, "No Path given" unless
|
205
|
+
raise ArgumentError, "No Path given" unless path
|
197
206
|
|
198
207
|
output.scan(pattern) do |name, content|
|
199
208
|
file = File.join(path, "inc/#{name}.txt")
|
@@ -232,7 +241,7 @@ module Adyen
|
|
232
241
|
|
233
242
|
# http://stackoverflow.com/questions/3420587/ruby-mechanize-multipart-form-with-file-upload-to-a-mediawiki
|
234
243
|
def upload
|
235
|
-
file =
|
244
|
+
file = compress
|
236
245
|
|
237
246
|
page = Adyen::Admin.get(UPLOAD_SELECT)
|
238
247
|
page = page.link_with(:href => Regexp.new(Regexp.escape(UPLOAD % code))).click
|
@@ -264,33 +273,26 @@ module Adyen
|
|
264
273
|
end
|
265
274
|
|
266
275
|
def to_s
|
267
|
-
|
276
|
+
code
|
268
277
|
end
|
269
278
|
|
270
279
|
def ==(skin)
|
271
|
-
|
280
|
+
code == skin.code
|
272
281
|
end
|
273
282
|
|
274
|
-
|
275
|
-
def
|
276
|
-
|
283
|
+
private
|
284
|
+
def code_from_path(path)
|
285
|
+
File.basename(path).split("-").last
|
277
286
|
end
|
278
287
|
|
279
|
-
def
|
280
|
-
|
288
|
+
def name_from_path(path)
|
289
|
+
File.basename(path).split("-")[0..-2].join('-')
|
281
290
|
end
|
282
291
|
|
283
292
|
def skin_data_file
|
284
293
|
File.join(path, 'skin.yml')
|
285
294
|
end
|
286
295
|
|
287
|
-
def self.is_skin_path?(skin_path)
|
288
|
-
%w(skin.html.erb skin.yml inc css js).each do |sub_path|
|
289
|
-
return true if File.exists?(File.join(skin_path.to_s, sub_path))
|
290
|
-
end
|
291
|
-
false
|
292
|
-
end
|
293
|
-
|
294
296
|
def nested_subdirectory?(skin_path, file)
|
295
297
|
(file.count("/") - skin_path.count("/")) > 2
|
296
298
|
end
|
@@ -16,6 +16,10 @@ module Adyen::Admin
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
before do
|
20
|
+
Adyen::Admin::Skin.default_path = skin_fixtures
|
21
|
+
end
|
22
|
+
|
19
23
|
describe ".all" do
|
20
24
|
it 'returns all local skins' do
|
21
25
|
Skin.all.should == Skin.all_local
|
@@ -42,7 +46,6 @@ module Adyen::Admin
|
|
42
46
|
end
|
43
47
|
|
44
48
|
it 'sets local path' do
|
45
|
-
Adyen::Admin::Skin.default_path = skin_fixtures
|
46
49
|
Skin.find(skin_code).path.should == "#{skin_fixtures}/example-#{skin_code}"
|
47
50
|
end
|
48
51
|
end
|
@@ -134,11 +137,11 @@ module Adyen::Admin
|
|
134
137
|
let(:skin) { Skin.new(:path => path) }
|
135
138
|
|
136
139
|
it "sets name" do
|
137
|
-
skin.name.should == "
|
140
|
+
skin.name.should == "custom name"
|
138
141
|
end
|
139
142
|
|
140
143
|
it "sets code" do
|
141
|
-
skin.code.should == "
|
144
|
+
skin.code.should == "DV3tf95f"
|
142
145
|
end
|
143
146
|
|
144
147
|
it "sets version_live" do
|
@@ -165,7 +168,7 @@ module Adyen::Admin
|
|
165
168
|
end
|
166
169
|
|
167
170
|
it "sets version_live" do
|
168
|
-
skin.path.should == "#{skin_fixtures}/DV3tf95f"
|
171
|
+
skin.path.should == "#{skin_fixtures}/customCode-DV3tf95f"
|
169
172
|
end
|
170
173
|
end
|
171
174
|
end
|
@@ -173,10 +176,7 @@ module Adyen::Admin
|
|
173
176
|
|
174
177
|
describe "#update" do
|
175
178
|
let(:path) { "#{skin_fixtures}/example-#{skin_code}" }
|
176
|
-
|
177
|
-
before do
|
178
|
-
skin.path = path
|
179
|
-
end
|
179
|
+
let(:skin) { Skin.new(:path => path) }
|
180
180
|
|
181
181
|
after do
|
182
182
|
`rm -f #{path}/skin.yml`
|
@@ -413,9 +413,7 @@ module Adyen::Admin
|
|
413
413
|
end
|
414
414
|
|
415
415
|
context "valid set" do
|
416
|
-
|
417
|
-
skin.path = path
|
418
|
-
end
|
416
|
+
let(:skin) { Skin.new(:path => path) }
|
419
417
|
|
420
418
|
it "increases version" do
|
421
419
|
expect { subject }.to change { skin.send(:remote_version) }.by(1)
|