Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created April 3, 2013 11:53
Show Gist options
  • Select an option

  • Save makevoid/5300552 to your computer and use it in GitHub Desktop.

Select an option

Save makevoid/5300552 to your computer and use it in GitHub Desktop.
jsdl - Javascript Libraries Downloader
#! /usr/bin/ruby
# jsdl
#
# download js libraries for you
#
# usage: jsdl jquery
# configs
libs = {
jquery: "http://code.jquery.com/jquery-1.9.1.min.js",
underscore: "http://underscorejs.org/underscore-min.js",
zepto: "http://zeptojs.com/zepto.min.js",
ember: "https://raw.github.com/emberjs/ember.js/release-builds/ember-1.0.0-pre.4.min.js",
jimagesloaded: "https://raw.github.com/desandro/imagesloaded/master/jquery.imagesloaded.min.js",
}
dir = "public/js/vendor"
# main
lib_names = libs.keys.map{|lib| lib.to_s}.join(", ")
lib_name = ARGV[0]
lib_name = if lib_name
lib_name.to_sym
else
puts "Specify a js library, available libs: #{lib_names}"
exit
end
if lib = libs.fetch(lib_name)
`mkdir -p #{dir}`
`wget -O #{dir}/#{lib_name}.js #{lib}`
puts "add the following line at the bottom of layout.haml:\n
%script{ type: \"text/javascript\", src: \"/js/vendor/#{lib_name}.js\" }"
else
puts "Not found a lib name in #{lib_names}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment