cdnio 0.1.0 → 0.2.0
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.
- data/README.md +39 -2
- data/lib/cdnio.rb +11 -4
- data/lib/cdnio/providers.rb +1 -12
- data/lib/cdnio/providers/cdnjs.rb +9 -8
- data/lib/cdnio/providers/google.rb +10 -7
- data/lib/cdnio/version.rb +1 -1
- data/web/Gemfile +2 -0
- data/web/app.rb +19 -8
- data/web/public/favicon.ico +0 -0
- data/web/views/index.haml +21 -0
- data/web/views/latest.haml +22 -0
- data/web/views/layout.haml +34 -0
- metadata +5 -1
data/README.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# CDN.io
|
2
2
|
|
3
|
-
CDN.io is there to always give you get the latest version of hosted JavaScript libraries on public CDNs.
|
3
|
+
CDN.io is there to always give you get the latest version of hosted JavaScript libraries on public CDNs, programatically.
|
4
|
+
|
5
|
+
## Why could this be useful?
|
6
|
+
|
7
|
+
I.e., to be used in template generators. In that way we can always rest assured that the user will get the latest version of their CDNed library and we don't have to worry about updating helpers anymore.
|
8
|
+
|
9
|
+
## Why did I even bother?
|
10
|
+
|
11
|
+
Because CDN services don't offer an API to access their list of hosted libraries!
|
12
|
+
|
13
|
+
|
14
|
+
|
4
15
|
|
5
16
|
## Installation
|
6
17
|
|
@@ -18,7 +29,32 @@ Or install it yourself as:
|
|
18
29
|
|
19
30
|
## Usage
|
20
31
|
|
21
|
-
|
32
|
+
### As a library
|
33
|
+
|
34
|
+
```
|
35
|
+
require 'cdnio'
|
36
|
+
|
37
|
+
cdn = CDNio::CDN.new
|
38
|
+
|
39
|
+
# Get all instances of jquery in any provider
|
40
|
+
cdn.latest(:jquery)
|
41
|
+
|
42
|
+
# ...only from google!
|
43
|
+
cdn.latest(:jquery, :google)
|
44
|
+
|
45
|
+
# And a list from all providers and all libraries?
|
46
|
+
cdn.libraries
|
47
|
+
|
48
|
+
# But I just wanted Cdnjs! Noo problem :)
|
49
|
+
cdn.libraries(:cdnjs)
|
50
|
+
```
|
51
|
+
|
52
|
+
### As a Web Service
|
53
|
+
|
54
|
+
Go to ```http://cdnio.uxtemple.com``` for the full API description.
|
55
|
+
|
56
|
+
I'll update this later on.
|
57
|
+
|
22
58
|
|
23
59
|
## Contributing
|
24
60
|
|
@@ -38,3 +74,4 @@ TODO: Write usage instructions here
|
|
38
74
|
* Add funky selectors such as \*.
|
39
75
|
* Add the ability to get more than one library at a time.
|
40
76
|
* Add the ability to choose a bunch of providers too.
|
77
|
+
* Refresh providers after a while?
|
data/lib/cdnio.rb
CHANGED
@@ -32,11 +32,18 @@ module CDNio
|
|
32
32
|
def libraries(provider = :all)
|
33
33
|
provider = provider.to_sym
|
34
34
|
raise UnsupportedProviderException, provider unless (PROVIDERS.include?(provider) || provider == :all)
|
35
|
-
|
35
|
+
if provider == :all
|
36
|
+
get_missing
|
37
|
+
|
38
|
+
Hash[*PROVIDERS.map do |prov|
|
39
|
+
libraries = @providers[prov].libraries
|
40
|
+
[prov, libraries] unless libraries.empty?
|
41
|
+
end.flatten(1).compact]
|
42
|
+
else
|
43
|
+
get_provider(provider)
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
end.flatten.compact]
|
45
|
+
@providers[provider].libraries
|
46
|
+
end
|
40
47
|
end
|
41
48
|
|
42
49
|
private
|
data/lib/cdnio/providers.rb
CHANGED
@@ -8,19 +8,8 @@ module CDNio
|
|
8
8
|
|
9
9
|
def libraries
|
10
10
|
fetch unless @libraries
|
11
|
-
@libraries
|
11
|
+
@libraries
|
12
12
|
end
|
13
|
-
|
14
|
-
private
|
15
|
-
def fetch(url)
|
16
|
-
return unless block_given?
|
17
|
-
|
18
|
-
require 'nokogiri'
|
19
|
-
require 'open-uri'
|
20
|
-
yield Nokogiri::HTML(open(url))
|
21
|
-
|
22
|
-
self
|
23
|
-
end
|
24
13
|
end # Base
|
25
14
|
end # Providers
|
26
15
|
end # CDNio
|
@@ -1,19 +1,20 @@
|
|
1
1
|
module CDNio
|
2
2
|
module Providers
|
3
3
|
class Cdnjs < Base
|
4
|
-
URL = 'http://cdnjs.com'
|
4
|
+
URL = 'http://cdnjs.com/packages.json'
|
5
|
+
BASE_URL = '//cdnjs.cloudflare.com/ajax/libs'
|
5
6
|
|
6
7
|
private
|
7
8
|
def fetch
|
8
|
-
|
9
|
-
|
10
|
-
tds = library.css('td')
|
9
|
+
require 'open-uri'
|
10
|
+
require 'json'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
@libraries = JSON.parse(open(URL).read)['packages'].map do |package|
|
13
|
+
{:name => package['name'],
|
14
|
+
:latest_version => package['version'],
|
15
|
+
:url => "#{BASE_URL}/#{package['name']}/#{package['version']}/#{package['filename']}"}
|
16
16
|
end
|
17
|
+
self
|
17
18
|
end
|
18
19
|
end # Cdnjs
|
19
20
|
end # Providers
|
@@ -5,15 +5,18 @@ module CDNio
|
|
5
5
|
|
6
6
|
private
|
7
7
|
def fetch
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
require 'nokogiri'
|
9
|
+
require 'open-uri'
|
10
|
+
doc = Nokogiri::HTML(open(URL))
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
@libraries = doc.css('table dl dd a').map do |library_link|
|
13
|
+
libDiv = doc.css(library_link[:href])
|
14
|
+
|
15
|
+
{:name => library_link[:href].gsub('#', ''),
|
16
|
+
:latest_version => libDiv.at_css('span.versions').text.split(', ').first,
|
17
|
+
:url => Nokogiri::HTML(libDiv.at_css('code.snippet').text).at_css('script')[:src]}
|
16
18
|
end
|
19
|
+
self
|
17
20
|
end
|
18
21
|
end # Google
|
19
22
|
end # Providers
|
data/lib/cdnio/version.rb
CHANGED
data/web/Gemfile
CHANGED
data/web/app.rb
CHANGED
@@ -1,24 +1,35 @@
|
|
1
1
|
require 'sinatra'
|
2
|
+
require 'haml'
|
2
3
|
require 'json'
|
3
4
|
require 'cdnio'
|
4
5
|
|
5
6
|
module CDNio
|
6
7
|
class WebApp < Sinatra::Application
|
7
8
|
set :cdn, CDN.new
|
9
|
+
set :layout, :layout
|
10
|
+
set :format, :html5
|
8
11
|
|
9
|
-
get '/', :provides => :json do
|
10
|
-
|
12
|
+
get '/', :provides => [:json, :html] do
|
13
|
+
if content_type =~ /json/
|
14
|
+
settings.cdn.libraries(params.include?('provider') ? params['provider'] : :all).to_json
|
15
|
+
elsif content_type =~ /html/
|
16
|
+
haml :index
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
|
-
get '/latest/:library', :provides => :json do
|
14
|
-
|
15
|
-
|
20
|
+
get '/latest/:library', :provides => [:json, :html] do
|
21
|
+
if content_type =~ /json/
|
22
|
+
library = params[:library]
|
23
|
+
provider = params.include?('provider') ? params['provider'] : :all
|
16
24
|
|
17
|
-
|
25
|
+
latest = settings.cdn.latest(library, provider)
|
18
26
|
|
19
|
-
|
27
|
+
halt 404, {:error => "Couldn't find #{library} #{provider == :all ? 'at all' : %{in #{provider}}}."}.to_json if latest.nil?
|
20
28
|
|
21
|
-
|
29
|
+
latest.to_json
|
30
|
+
elsif content_type =~ /html/
|
31
|
+
haml :latest
|
32
|
+
end
|
22
33
|
end
|
23
34
|
|
24
35
|
# Start the server if ruby file executed directly
|
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
%h2 GET '/'
|
2
|
+
%h3 Params
|
3
|
+
%ul
|
4
|
+
%li
|
5
|
+
%strong provider (optional):
|
6
|
+
%ul
|
7
|
+
%li all (default)
|
8
|
+
%li cdnjs
|
9
|
+
%li google
|
10
|
+
%li microsoft
|
11
|
+
|
12
|
+
%p Gets the latest library for a provider. If there's none, it will throw a 404.
|
13
|
+
|
14
|
+
%h3 Example
|
15
|
+
%code ➜ curl http://cdnio.uxtemple.com -H "Accept: application/json" -H "Content-type: application/json"
|
16
|
+
|
17
|
+
%p Response:
|
18
|
+
%code
|
19
|
+
{"cdnjs":"1140","960gs":"ace","alloy-ui":"amplifyjs","angular.js":"async","augment.js":"backbone-localstorage.js","backbone-relational":"backbone.eventbinder","backbone.js":"backbone.layoutmanager","backbone.marionette":"backbone.modelbinder","backbone.paginator":"backbone.syphon","backbone.validation":"backbone.wreqr","benchmark":"bonsai","bootstrap-growl":"bootstrap-lightbox","camanjs":"can.js","cannon.js":"chosen","chrome-frame":"coffee-script","cookiejar":"crafty","crossroads":"css3finalize","css3pie":"cufon","d3":"dancer.js","dat-gui":"datatables","datatables-fixedheader":"datejs","davis.js":"dd_belatedpng","documentup":"dojo","dollar.js":"dropbox.js","dygraph":"embedly-jquery","ember-data.js":"ember.js","enquire.js":"epiceditor","es5-shim":"eve.js","eventmaster":"ext-core","fancybox":"file-uploader","firebug-lite":"fitvids","flexie":"flot","font-awesome":"foundation","galleria":"garlic.js","gas":"geo-location-javascript","gmaps.js":"gmaps4rails","graphael":"handlebars.js","hashgrid":"headjs","highcharts":"highlight.js","hinclude":"history.js","hogan.js":"html5shiv","humane-js":"ICanHaz.js","impress.js":"jade","javascript-state-machine":"jo","jplayer":"jqModal","jquery":"jquery-ui","jquery-cookie":"jquery-countdown","jquery-easing":"jquery-gamequery","jquery-hashchange":"jquery-history","jquery-infinitescroll":"jquery-jcrop","jquery-migrate":"jquery-mobile","jquery-mockjax":"jquery-mousewheel","jquery-nivoslider":"jquery-noty","jquery-powertip":"jquery-scrollTo","jquery-sparklines":"jquery-textext","jquery-throttle-debounce":"jquery-timeago","jquery-tools":"jquery-url-parser","jquery-validate":"jquery.activity-indicator","jquery.address":"jquery.ba-bbq","jquery.caroufredsel":"jquery.colorbox","jquery.cycle":"jquery.form","jquery.formalize":"jquery.imagesloaded","jquery.lazyload":"jquery.lifestream","jquery.nanoscroller":"jquery.selectboxit","jquery.socialshareprivacy":"jquery.SPServices","jquery.tablesorter":"jquery.touchswipe","jquery.transit":"jqueryui","jqueryui-touch-punch":"js-signals","js-url":"jScrollPane","json2":"json3","jsoneditor":"jStorage","jsxgraph":"kerning.js","kineticjs":"kiwi","knockout":"knockout.mapping","labjs":"lazyload","leaflet":"less.js","lodash.js":"log4javascript","masonry":"meyer-reset","mo":"mobilizejs","modernizr":"moment.js","mootools":"prototype","morris.js":"mousetrap","mustache.js":"ninjaui","noisy":"normalize","numeral.js":"ocanvas","openajax-hub":"openlayers","oz.js":"pagedown","paper.js":"path.js","pie":"piwik","placeholder-shiv":"platform","postal.js":"prefixfree","prettify":"processing.js","prototype":"psd.js","pubnub":"punycode","pusher":"qooxdoo","qtip2":"qunit","rainbow":"raphael","raven.js":"remoteStorage","require-cs":"require-domReady","require-i18n":"require-jquery","require-text":"require.js","respond.js":"ResponsiveSlides.js","retina.js":"reveal.js","rickshaw":"sammy.js","scion":"script.js","scriptaculous":"swfobject","select2":"selectivizr","showdown":"shred","simplecartjs":"sizzle","socket.io":"sockjs-client","sopa":"spin.js","spinejs":"stacktrace.js","stapes":"stats.js","stellar.js":"store.js","string.js":"string_score","sugar":"swfobject","swipe":"sylvester","SyntaxHighlighter":"thorax","three.js":"tinycon","tinyscrollbar":"treesaver","tweenjs":"tweet","twitter-bootstrap":"twitterlib.js","underscore.js":"underscore.string","URI.js":"use.js","vertx":"visibility.js","waypoints":"webfont","wysihtml5":"xregexp","xuijs":"yepnope","yui":"zepto","zxcvbn":"google","angularjs":"chrome-frame","dojo":"ext-core","webfont":"microsoft"}
|
20
|
+
|
21
|
+
= haml :latest
|
@@ -0,0 +1,22 @@
|
|
1
|
+
%h2 GET '/latest/:library'
|
2
|
+
%h3 Params
|
3
|
+
%ul
|
4
|
+
%li
|
5
|
+
%strong library:
|
6
|
+
whatever library you want to get.
|
7
|
+
%ul
|
8
|
+
%li
|
9
|
+
%strong provider (optional):
|
10
|
+
%ul
|
11
|
+
%li all (default)
|
12
|
+
%li cdnjs
|
13
|
+
%li google
|
14
|
+
%li microsoft
|
15
|
+
|
16
|
+
%p Gets the latest library for a provider. If there's none, it will throw a 404.
|
17
|
+
|
18
|
+
%h3 Example
|
19
|
+
%code ➜ curl http://cdnio.uxtemple.com/latest/jquery -H "Accept: application/json" -H "Content-type: application/json"
|
20
|
+
|
21
|
+
%p Response:
|
22
|
+
%code {"cdnjs":{"name":"jquery","latest_version":"1.9.0","url":"//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"},"google":{"name":"jquery","latest_version":"1.9.0","url":"//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"}}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
-# encoding: utf-8
|
2
|
+
!!! 5
|
3
|
+
%html{:lang => :en}
|
4
|
+
%head
|
5
|
+
%meta{:charset => 'utf-8'}
|
6
|
+
%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
|
7
|
+
%meta{:name => :viewport, :content => 'width=device-width, initial-scale=1.0'}
|
8
|
+
%meta{:name => :description, :content => ""}
|
9
|
+
%meta{:name => :author, :content => ""}
|
10
|
+
%title CDN.io
|
11
|
+
|
12
|
+
%link{:rel => 'shortcut icon', :href => '/favicon.ico'}
|
13
|
+
-# %link{:rel => :stylesheet, :href => '/normalise.css'}
|
14
|
+
-# %link{:rel => :stylesheet, :href => '/main.css'}
|
15
|
+
|
16
|
+
%body
|
17
|
+
%h1 CDN.io
|
18
|
+
|
19
|
+
=yield
|
20
|
+
|
21
|
+
%footer
|
22
|
+
%p
|
23
|
+
%a{:href => 'https://github.com/dariocravero/cdnio', :title => 'Source Code'} Source Code @ Github
|
24
|
+
|
25
|
+
:javascript
|
26
|
+
var _gaq = _gaq || [];
|
27
|
+
_gaq.push(['_setAccount', 'UA-38029800-1']);
|
28
|
+
_gaq.push(['_trackPageview']);
|
29
|
+
|
30
|
+
(function() {
|
31
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
32
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
33
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
34
|
+
})();
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdnio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -51,6 +51,10 @@ files:
|
|
51
51
|
- web/README.md
|
52
52
|
- web/app.rb
|
53
53
|
- web/config.ru
|
54
|
+
- web/public/favicon.ico
|
55
|
+
- web/views/index.haml
|
56
|
+
- web/views/latest.haml
|
57
|
+
- web/views/layout.haml
|
54
58
|
homepage: https://github.com/dariocravero/cdnio
|
55
59
|
licenses: []
|
56
60
|
post_install_message:
|