cdnget 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/bin/cdnget +30 -38
- data/cdnget.gemspec +1 -1
- data/lib/cdnget.rb +30 -38
- data/test/cdnget_test.rb +13 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 055befc004f39cde2638cf0cc31dc01e4cbc3226
|
4
|
+
data.tar.gz: 694c18db9e4128ee93119f985c66c7d4656aee27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ab7fed7ebd4a61804930cf168deb89e1b30b2326ed9ca3bd609b755236f14d2c905066a24bb39f65b7a090bb4eeffb36b43996550c651d2c6acefdcf6f28b67
|
7
|
+
data.tar.gz: dea35e5ab6ca166933650c0ff670b0e419ebc5e24b906b31ac45c492c87073cc78abd6840b556574519bacfc7881780cae21296532bca988603727fa684cd1d5
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/bin/cdnget
CHANGED
@@ -24,7 +24,7 @@ require 'fileutils'
|
|
24
24
|
module CDNGet
|
25
25
|
|
26
26
|
|
27
|
-
RELEASE = '$Release: 0.
|
27
|
+
RELEASE = '$Release: 0.3.0 $'.split()[1]
|
28
28
|
|
29
29
|
CLASSES = []
|
30
30
|
|
@@ -114,14 +114,20 @@ module CDNGet
|
|
114
114
|
|
115
115
|
def fetch(url, library=nil)
|
116
116
|
begin
|
117
|
-
|
117
|
+
json_str = open(url, 'rb') {|f| f.read() }
|
118
118
|
if library
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
if json_str == "{}"
|
120
|
+
if library.end_with?('js')
|
121
|
+
maybe = library.end_with?('.js') \
|
122
|
+
? library.sub('.js', 'js') \
|
123
|
+
: library.sub(/js$/, '.js')
|
124
|
+
raise CommandError.new("#{library}: Library not found (maybe '#{maybe}'?).")
|
125
|
+
else
|
126
|
+
raise CommandError.new("#{library}: Library not found.")
|
127
|
+
end
|
128
|
+
end
|
123
129
|
end
|
124
|
-
return
|
130
|
+
return json_str
|
125
131
|
rescue OpenURI::HTTPError => ex
|
126
132
|
raise HttpError.new("GET #{url} : #{ex.message}")
|
127
133
|
end
|
@@ -130,53 +136,38 @@ module CDNGet
|
|
130
136
|
|
131
137
|
def list
|
132
138
|
libs = []
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
name = $1 if str =~ /href="\/libraries\/([-.\w]+)">\s*\1\s*<\/a>/
|
137
|
-
desc = $1.strip if str =~ /<div style="display: none;">(.*?)<\/div>/m
|
138
|
-
libs << {name: name, desc: desc} if name
|
139
|
-
end
|
139
|
+
jstr = fetch("https://api.cdnjs.com/libraries?fields=name,description")
|
140
|
+
jdata = JSON.parse(jstr)
|
141
|
+
libs = jdata['results'].collect {|d| {name: d['name'], desc: d['description']} }
|
140
142
|
return libs.sort_by {|d| d[:name] }.uniq
|
141
143
|
end
|
142
144
|
|
143
145
|
def find(library)
|
144
146
|
validate(library, nil)
|
145
|
-
|
146
|
-
|
147
|
-
flagment = flagment.split(/<\/select>/, 2).first
|
148
|
-
versions = []
|
149
|
-
flagment.scan(/<option value="([^"]+)" *(?:selected)?>/) do |ver,|
|
150
|
-
versions << ver
|
151
|
-
end
|
152
|
-
desc = tags = nil
|
153
|
-
if html =~ /<\/p>\s*<p>(.*?)<\/p>\s*<em>(.*?)<\/em>/
|
154
|
-
desc = $1
|
155
|
-
tags = $2
|
156
|
-
end
|
147
|
+
jstr = fetch("https://api.cdnjs.com/libraries/#{library}", library)
|
148
|
+
jdata = JSON.parse(jstr)
|
157
149
|
return {
|
158
150
|
name: library,
|
159
|
-
desc:
|
160
|
-
tags:
|
161
|
-
versions:
|
151
|
+
desc: jdata['description'],
|
152
|
+
tags: (jdata['keywords'] || []).join(", "),
|
153
|
+
versions: jdata['assets'].collect {|d| d['version'] },
|
162
154
|
}
|
163
155
|
end
|
164
156
|
|
165
157
|
def get(library, version)
|
166
158
|
validate(library, version)
|
167
|
-
|
159
|
+
jstr = fetch("https://api.cdnjs.com/libraries/#{library}", library)
|
160
|
+
jdata = JSON.parse(jstr)
|
161
|
+
d = jdata['assets'].find {|d| d['version'] == version } or
|
162
|
+
raise CommandError.new("#{library}/#{version}: Library or version not found.")
|
168
163
|
baseurl = "https://cdnjs.cloudflare.com/ajax/libs/#{library}/#{version}/"
|
169
|
-
basepat = Regexp.escape("#{library}/#{version}")
|
170
|
-
files = []
|
171
|
-
html.scan(%r`>#{basepat}/([^<]+)<\/p>`) do |file,|
|
172
|
-
files << file.gsub(///, '/')
|
173
|
-
end
|
174
|
-
urls = files.collect {|s| baseurl + s }
|
175
164
|
return {
|
176
165
|
name: library,
|
166
|
+
desc: jdata['description'],
|
167
|
+
tags: (jdata['keywords'] || []).join(", "),
|
177
168
|
version: version,
|
178
|
-
urls:
|
179
|
-
files: files,
|
169
|
+
urls: d['files'].collect {|s| baseurl + s },
|
170
|
+
files: d['files'],
|
180
171
|
baseurl: baseurl,
|
181
172
|
}
|
182
173
|
end
|
@@ -503,6 +494,7 @@ END
|
|
503
494
|
else
|
504
495
|
s << "name: #{d[:name]}\n"
|
505
496
|
s << "version: #{d[:version]}\n"
|
497
|
+
s << "desc: #{d[:desc]}\n" if d[:desc]
|
506
498
|
s << "tags: #{d[:tags]}\n" if d[:tags]
|
507
499
|
s << "site: #{d[:site]}\n" if d[:site]
|
508
500
|
s << "snippet: |\n" << d[:snippet].gsub(/^/, ' ') if d[:snippet]
|
data/cdnget.gemspec
CHANGED
data/lib/cdnget.rb
CHANGED
@@ -24,7 +24,7 @@ require 'fileutils'
|
|
24
24
|
module CDNGet
|
25
25
|
|
26
26
|
|
27
|
-
RELEASE = '$Release: 0.
|
27
|
+
RELEASE = '$Release: 0.3.0 $'.split()[1]
|
28
28
|
|
29
29
|
CLASSES = []
|
30
30
|
|
@@ -114,14 +114,20 @@ module CDNGet
|
|
114
114
|
|
115
115
|
def fetch(url, library=nil)
|
116
116
|
begin
|
117
|
-
|
117
|
+
json_str = open(url, 'rb') {|f| f.read() }
|
118
118
|
if library
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
if json_str == "{}"
|
120
|
+
if library.end_with?('js')
|
121
|
+
maybe = library.end_with?('.js') \
|
122
|
+
? library.sub('.js', 'js') \
|
123
|
+
: library.sub(/js$/, '.js')
|
124
|
+
raise CommandError.new("#{library}: Library not found (maybe '#{maybe}'?).")
|
125
|
+
else
|
126
|
+
raise CommandError.new("#{library}: Library not found.")
|
127
|
+
end
|
128
|
+
end
|
123
129
|
end
|
124
|
-
return
|
130
|
+
return json_str
|
125
131
|
rescue OpenURI::HTTPError => ex
|
126
132
|
raise HttpError.new("GET #{url} : #{ex.message}")
|
127
133
|
end
|
@@ -130,53 +136,38 @@ module CDNGet
|
|
130
136
|
|
131
137
|
def list
|
132
138
|
libs = []
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
name = $1 if str =~ /href="\/libraries\/([-.\w]+)">\s*\1\s*<\/a>/
|
137
|
-
desc = $1.strip if str =~ /<div style="display: none;">(.*?)<\/div>/m
|
138
|
-
libs << {name: name, desc: desc} if name
|
139
|
-
end
|
139
|
+
jstr = fetch("https://api.cdnjs.com/libraries?fields=name,description")
|
140
|
+
jdata = JSON.parse(jstr)
|
141
|
+
libs = jdata['results'].collect {|d| {name: d['name'], desc: d['description']} }
|
140
142
|
return libs.sort_by {|d| d[:name] }.uniq
|
141
143
|
end
|
142
144
|
|
143
145
|
def find(library)
|
144
146
|
validate(library, nil)
|
145
|
-
|
146
|
-
|
147
|
-
flagment = flagment.split(/<\/select>/, 2).first
|
148
|
-
versions = []
|
149
|
-
flagment.scan(/<option value="([^"]+)" *(?:selected)?>/) do |ver,|
|
150
|
-
versions << ver
|
151
|
-
end
|
152
|
-
desc = tags = nil
|
153
|
-
if html =~ /<\/p>\s*<p>(.*?)<\/p>\s*<em>(.*?)<\/em>/
|
154
|
-
desc = $1
|
155
|
-
tags = $2
|
156
|
-
end
|
147
|
+
jstr = fetch("https://api.cdnjs.com/libraries/#{library}", library)
|
148
|
+
jdata = JSON.parse(jstr)
|
157
149
|
return {
|
158
150
|
name: library,
|
159
|
-
desc:
|
160
|
-
tags:
|
161
|
-
versions:
|
151
|
+
desc: jdata['description'],
|
152
|
+
tags: (jdata['keywords'] || []).join(", "),
|
153
|
+
versions: jdata['assets'].collect {|d| d['version'] },
|
162
154
|
}
|
163
155
|
end
|
164
156
|
|
165
157
|
def get(library, version)
|
166
158
|
validate(library, version)
|
167
|
-
|
159
|
+
jstr = fetch("https://api.cdnjs.com/libraries/#{library}", library)
|
160
|
+
jdata = JSON.parse(jstr)
|
161
|
+
d = jdata['assets'].find {|d| d['version'] == version } or
|
162
|
+
raise CommandError.new("#{library}/#{version}: Library or version not found.")
|
168
163
|
baseurl = "https://cdnjs.cloudflare.com/ajax/libs/#{library}/#{version}/"
|
169
|
-
basepat = Regexp.escape("#{library}/#{version}")
|
170
|
-
files = []
|
171
|
-
html.scan(%r`>#{basepat}/([^<]+)<\/p>`) do |file,|
|
172
|
-
files << file.gsub(///, '/')
|
173
|
-
end
|
174
|
-
urls = files.collect {|s| baseurl + s }
|
175
164
|
return {
|
176
165
|
name: library,
|
166
|
+
desc: jdata['description'],
|
167
|
+
tags: (jdata['keywords'] || []).join(", "),
|
177
168
|
version: version,
|
178
|
-
urls:
|
179
|
-
files: files,
|
169
|
+
urls: d['files'].collect {|s| baseurl + s },
|
170
|
+
files: d['files'],
|
180
171
|
baseurl: baseurl,
|
181
172
|
}
|
182
173
|
end
|
@@ -503,6 +494,7 @@ END
|
|
503
494
|
else
|
504
495
|
s << "name: #{d[:name]}\n"
|
505
496
|
s << "version: #{d[:version]}\n"
|
497
|
+
s << "desc: #{d[:desc]}\n" if d[:desc]
|
506
498
|
s << "tags: #{d[:tags]}\n" if d[:tags]
|
507
499
|
s << "site: #{d[:site]}\n" if d[:site]
|
508
500
|
s << "snippet: |\n" << d[:snippet].gsub(/^/, ' ') if d[:snippet]
|
data/test/cdnget_test.rb
CHANGED
@@ -69,10 +69,9 @@ END
|
|
69
69
|
|
70
70
|
it "(cdnjs) lists librareis." do
|
71
71
|
actual = CDNGet::Main.new().run("cdnjs")
|
72
|
-
ok {actual} =~ /^jquery #
|
73
|
-
ok {actual} =~ /^angular\.js # framework
|
74
|
-
ok {actual} =~ /^
|
75
|
-
ok {actual} =~ /^ember\.js # ember, ember.js$/
|
72
|
+
ok {actual} =~ /^jquery # JavaScript library for DOM operations$/
|
73
|
+
ok {actual} =~ /^angular\.js # AngularJS is an MVC framework for building web applications\./
|
74
|
+
ok {actual} =~ /^ember\.js # Ember is a JavaScript framework for creating ambitious web applications that eliminates boilerplate and provides a standard application architecture\./
|
76
75
|
end
|
77
76
|
|
78
77
|
it "(google) lists librareis." do
|
@@ -275,6 +274,7 @@ END
|
|
275
274
|
expected = <<END
|
276
275
|
name: jquery
|
277
276
|
version: 2.2.0
|
277
|
+
tags: jquery, library, ajax, framework, toolkit, popular
|
278
278
|
urls:
|
279
279
|
- https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js
|
280
280
|
- https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js
|
@@ -313,14 +313,15 @@ END
|
|
313
313
|
expected = <<END
|
314
314
|
name: jquery-jcrop
|
315
315
|
version: 0.9.12
|
316
|
+
tags: jquery, crop
|
316
317
|
urls:
|
317
318
|
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/Jcrop.gif
|
318
319
|
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.css
|
319
320
|
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css
|
320
|
-
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.js
|
321
|
-
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js
|
322
321
|
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.color.js
|
323
322
|
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.color.min.js
|
323
|
+
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.js
|
324
|
+
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js
|
324
325
|
- https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.min.js
|
325
326
|
END
|
326
327
|
actual = CDNGet::Main.new().run("cdnjs", "jquery-jcrop", "0.9.12")
|
@@ -381,10 +382,10 @@ END
|
|
381
382
|
#{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif ... Done (329 byte)
|
382
383
|
#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css ... Done (3,280 byte)
|
383
384
|
#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css ... Done (2,102 byte)
|
384
|
-
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
|
385
|
-
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
|
386
385
|
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js ... Done (16,142 byte)
|
387
386
|
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js ... Done (6,845 byte)
|
387
|
+
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
|
388
|
+
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
|
388
389
|
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js ... Done (93,068 byte)
|
389
390
|
END
|
390
391
|
begin
|
@@ -394,10 +395,10 @@ END
|
|
394
395
|
ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif" }.file_exist?
|
395
396
|
ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css" }.file_exist?
|
396
397
|
ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css" }.file_exist?
|
397
|
-
ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js" }.file_exist?
|
398
|
-
ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js" }.file_exist?
|
399
398
|
ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js" }.file_exist?
|
400
399
|
ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js" }.file_exist?
|
400
|
+
ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js" }.file_exist?
|
401
|
+
ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js" }.file_exist?
|
401
402
|
ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js" }.file_exist?
|
402
403
|
ok {sout} == expected
|
403
404
|
ensure
|
@@ -428,10 +429,10 @@ END
|
|
428
429
|
#{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif ... Done (329 byte)
|
429
430
|
#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css ... Done (3,280 byte)
|
430
431
|
#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css ... Done (2,102 byte)
|
431
|
-
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
|
432
|
-
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
|
433
432
|
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js ... Done (16,142 byte)
|
434
433
|
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js ... Done (6,845 byte)
|
434
|
+
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
|
435
|
+
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
|
435
436
|
#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js ... Done (93,068 byte)
|
436
437
|
END
|
437
438
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdnget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- makoto kuwata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|