# gem install vendorer # vendorer require 'zip' vendor_js = 'vendor/assets/javascripts/' vendor_css = 'vendor/assets/stylesheets/' vendor_img = 'vendor/assets/images/' vendor_tmp = 'vendor/assets/' def get to, form, rm = true FileUtils.rm to if rm && File.exist?(to) file to, form end def get_zip to, url get "#{to}.zip", url, false Zip::File.open("#{to}.zip").each do |f| f_path = File.join(to, f.name) FileUtils.mkdir_p File.dirname(f_path) f.extract(f_path) unless File.exist?(f_path) end end def cp_img to, from, clear = true FileUtils.mkdir_p to FileUtils.rm Dir.glob("#{to}/*") if clear Dir["#{from}/*"].select{ |f| /\.(eot|svg|ttf|woff|gif|png|jpe?g)$/ =~ f }.each do |f| FileUtils.cp f, "#{to}/#{File.basename f}" end end # semantic-ui get_zip "#{vendor_tmp}semantic", 'http://semantic-ui.com/build/semantic.zip' FileUtils.cp "#{vendor_tmp}semantic/packaged/css/semantic.min.css", "#{vendor_css}semantic.scss" FileUtils.cp "#{vendor_tmp}semantic/packaged/javascript/semantic.min.js", "#{vendor_js}semantic.js" cp_img "#{vendor_img}semantic", "#{vendor_tmp}semantic/packaged/images" cp_img "#{vendor_img}semantic", "#{vendor_tmp}semantic/packaged/fonts", false body = File.read("#{vendor_css}semantic.scss").gsub(/url\([^\)]+\)/){ |s| filename = s.gsub(/url\(..\/(images|fonts)\//, '').gsub(')', '') "image-url(\"semantic/#{filename}\")" } File.open("#{vendor_css}semantic.scss", 'w') do |f| f.write body end FileUtils.rm "#{vendor_tmp}semantic.zip" FileUtils.remove_dir "#{vendor_tmp}semantic" # jquery get "#{vendor_js}jquery/1.8.js", 'http://code.jquery.com/jquery-1.8.3.min.js' get "#{vendor_js}jquery/1.9.js", 'http://code.jquery.com/jquery-1.9.1.min.js' get "#{vendor_js}jquery/1.10.js", 'http://code.jquery.com/jquery-1.11.0.min.js' get "#{vendor_js}jquery/2.0.js", 'http://code.jquery.com/jquery-2.1.0.min.js' # jquery cookie get "#{vendor_js}jquery.cookie.js", 'https://rawgithub.com/carhartl/jquery-cookie/master/jquery.cookie.js' # jquery validate version = '1.11.1' get "#{vendor_js}jquery.validate.js", "http://ajax.aspnetcdn.com/ajax/jquery.validate/#{version}/jquery.validate.min.js" # jquery fileupload version = '9.5.6' get "#{vendor_js}jquery.fileupload.js", "https://rawgithub.com/blueimp/jQuery-File-Upload/#{version}/js/jquery.fileupload.js" get "#{vendor_js}jquery.iframe-transport.js", "https://rawgithub.com/blueimp/jQuery-File-Upload/#{version}/js/jquery.iframe-transport.js" # jquery pnotify version = '1.2.0' get "#{vendor_js}jquery.pnotify.js", "https://rawgithub.com/sciactive/pnotify/#{version}/jquery.pnotify.min.js" get "#{vendor_css}jquery.pnotify.css", "https://rawgithub.com/sciactive/pnotify/#{version}/jquery.pnotify.default.css" # jquery lazyload get "#{vendor_js}jquery.lazyload.js", 'https://rawgithub.com/tuupola/jquery_lazyload/master/jquery.lazyload.min.js' # bootstrap get_zip "#{vendor_tmp}bootstrap", 'http://getbootstrap.com/2.3.2/assets/bootstrap.zip' FileUtils.cp "#{vendor_tmp}bootstrap/bootstrap/js/bootstrap.min.js", "#{vendor_js}bootstrap.js" FileUtils.cp "#{vendor_tmp}bootstrap/bootstrap/css/bootstrap.min.css", "#{vendor_css}bootstrap.scss" FileUtils.cp "#{vendor_tmp}bootstrap/bootstrap/css/bootstrap-responsive.min.css", "#{vendor_css}bootstrap.responsive.css" body = File.read("#{vendor_css}bootstrap.scss").gsub(/url\([^\)]+\)/){ |s| filename = s.gsub('url("../img/', '').gsub('")', '') "image-url(\"bootstrap/#{filename}\")" } File.open("#{vendor_css}bootstrap.scss", 'w') do |f| f.write body end cp_img "#{vendor_img}bootstrap", "#{vendor_tmp}bootstrap/bootstrap/img" FileUtils.rm "#{vendor_tmp}bootstrap.zip" FileUtils.remove_dir "#{vendor_tmp}bootstrap" # bootstrap3 version = '3.1.1' get_zip "#{vendor_tmp}bootstrap3", "https://github.com/twbs/bootstrap/releases/download/v#{version}/bootstrap-#{version}-dist.zip" FileUtils.cp "#{vendor_tmp}bootstrap3/bootstrap-#{version}-dist/js/bootstrap.min.js", "#{vendor_js}bootstrap3.js" FileUtils.cp "#{vendor_tmp}bootstrap3/bootstrap-#{version}-dist/css/bootstrap.min.css", "#{vendor_css}bootstrap3.scss" body = File.read("#{vendor_css}bootstrap3.scss").gsub(/url\([^\)]+\)/){ |s| filename = s.gsub("url('../fonts/", '').gsub("')", '') "image-url(\"bootstrap3/#{filename}\")" } File.open("#{vendor_css}bootstrap3.scss", 'w') do |f| f.write body end cp_img "#{vendor_img}bootstrap3", "#{vendor_tmp}bootstrap3/bootstrap-#{version}-dist/fonts" FileUtils.rm "#{vendor_tmp}bootstrap3.zip" FileUtils.remove_dir "#{vendor_tmp}bootstrap3" # sammy get "#{vendor_js}sammy.js", 'https://rawgithub.com/quirkey/sammy/master/lib/min/sammy-latest.min.js' # lazyload version = '2.0.3' get "#{vendor_js}lazyload.js", "https://github.com/rgrove/lazyload/raw/release-#{version}/lazyload-min.js" # zepto get "#{vendor_js}zepto.js", 'http://zeptojs.com/zepto.min.js' version = '1.1.3' FileUtils.rm Dir.glob("#{vendor_js}zepto/*") %w(assets data selector touch gesture stack).each do |name| get "#{vendor_js}zepto/#{name}.js", "https://rawgithub.com/madrobby/zepto/v#{version}/src/#{name}.js" end # jQuery-ujs get "#{vendor_js}jquery.ujs.js", 'https://raw.github.com/indirect/jquery-rails/master/vendor/assets/javascripts/jquery_ujs.js' list = `git grep -n sourceMappingURL`.split("\n") list.delete_at 0 list.each do |path| p path file = path[/^[^:]+/] line = path[/:[0-9]+/].gsub(':', '').to_i body = File.readlines(file) body.delete_at(line - 1) File.open(file, 'w') do |f| f.write body.join('') end end