From 3b7637f1e596fd4d8cc66a7dfb1714582f7d846d Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 29 Aug 2009 15:52:21 -0700 Subject: [PATCH] Bootstrap download the yui plugin for the examples. --- Rakefile | 9 +++--- examples/downloader.rb | 57 +++++++++++++++++++++++++++++++++ examples/ninesixty/bootstrap.rb | 45 ++------------------------ examples/yui/bootstrap.rb | 3 ++ 4 files changed, 66 insertions(+), 48 deletions(-) create mode 100644 examples/downloader.rb create mode 100644 examples/yui/bootstrap.rb diff --git a/Rakefile b/Rakefile index 47d77d7d..b53706ce 100644 --- a/Rakefile +++ b/Rakefile @@ -108,8 +108,10 @@ task :examples do next unless File.directory?(example) puts "\nCompiling #{example}" puts "=" * "Compiling #{example}".length - bootstrap_file = File.join(example, "bootstrap.rb") - load bootstrap_file if File.exists?(bootstrap_file) + Dir.chdir example do + load "bootstrap.rb" if File.exists?("bootstrap.rb") + Compass::Exec::Compass.new(["--force"]).run! + end # compile any haml templates to html FileList["#{example}/**/*.haml"].each do |haml_file| basename = haml_file[0..-6] @@ -119,9 +121,6 @@ task :examples do output.write(engine.render) output.close end - Dir.chdir example do - Compass::Exec::Compass.new(["--force"]).run! - end end end diff --git a/examples/downloader.rb b/examples/downloader.rb new file mode 100644 index 00000000..eef35e4e --- /dev/null +++ b/examples/downloader.rb @@ -0,0 +1,57 @@ +require 'net/http' +require 'fileutils' +require 'rubygems' +require 'zip/zip' + + +def fetch(uri_str, limit = 10) + raise ArgumentError, 'HTTP redirect too deep' if limit == 0 + + url = URI.parse(uri_str) + http = Net::HTTP.new(url.host, url.port) + http.open_timeout = 2 + http.read_timeout = 30 + response = http.start do |http| + puts "getting #{url.path}" + http.request_get(url.path) + end + + case response + when Net::HTTPSuccess then response + when Net::HTTPRedirection then fetch(response['location'], limit - 1) + else + response.error! + end +end + +def install_from_github(user, project, ext_name, working_directory = Dir.pwd) + download_link = "http://github.com/#{user}/#{project}/zipball/master" + extdir = File.join(working_directory,'extensions') + + if !File.exists?(extdir) + begin + puts "Downloading the #{ext_name} plugin into #{extdir}." + FileUtils.mkdir(extdir) + zipfile = File.join(extdir, "#{ext_name}.zip") + open(zipfile, "wb") do |tgz| + tgz << fetch(download_link).body + end + puts "Unzipping the #{ext_name} plugin." + Zip::ZipFile::open(zipfile) { |zf| + zf.each { |e| + fpath = File.join(extdir, e.name) + FileUtils.mkdir_p(File.dirname(fpath)) + zf.extract(e, fpath) + } + } + File.unlink(zipfile) + funky_directory = Dir.glob(File.join(extdir,"#{user}-#{project}-*"))[0] + FileUtils.mv(funky_directory, File.join(extdir, ext_name)) + puts "#{ext_name} installed." + rescue Exception => e + FileUtils.rm_rf(extdir) + raise + end + end + +end diff --git a/examples/ninesixty/bootstrap.rb b/examples/ninesixty/bootstrap.rb index 9ed36e28..b2b52d70 100644 --- a/examples/ninesixty/bootstrap.rb +++ b/examples/ninesixty/bootstrap.rb @@ -1,45 +1,4 @@ -require 'net/http' -require 'fileutils' -require 'rubygems' -require 'zip/zip' +require File.join(File.dirname(__FILE__), '..', 'downloader') -extdir = File.join(File.dirname(__FILE__),'extensions') -download_link = "http://github.com/chriseppstein/compass-960-plugin/zipball/master" +install_from_github('chriseppstein', 'compass-960-plugin', 'ninesixty') -def fetch(uri_str, limit = 10) - raise ArgumentError, 'HTTP redirect too deep' if limit == 0 - - response = Net::HTTP.get_response(URI.parse(uri_str)) - case response - when Net::HTTPSuccess then response - when Net::HTTPRedirection then fetch(response['location'], limit - 1) - else - response.error! - end -end - - -if !File.exists?(extdir) - begin - puts "Downloading the ninesixty plugin." - FileUtils.mkdir(extdir) - zipfile = File.join(extdir, "ninesixty.zip") - open(zipfile, "wb") do |tgz| - tgz << fetch(download_link).body - end - puts "Unzipping the ninesixty plugin." - Zip::ZipFile::open(zipfile) { |zf| - zf.each { |e| - fpath = File.join(extdir, e.name) - FileUtils.mkdir_p(File.dirname(fpath)) - zf.extract(e, fpath) - } - } - File.unlink(zipfile) - funky_directory = Dir.glob(File.join(extdir,'chriseppstein-compass-960-plugin-*'))[0] - FileUtils.mv(funky_directory, File.join(extdir,'ninesixty')) - rescue Exception => e - FileUtils.rmdir(extdir) - raise - end -end diff --git a/examples/yui/bootstrap.rb b/examples/yui/bootstrap.rb new file mode 100644 index 00000000..fcc0c7c4 --- /dev/null +++ b/examples/yui/bootstrap.rb @@ -0,0 +1,3 @@ +require File.join(File.dirname(__FILE__), '..', 'downloader') + +install_from_github('chriseppstein', 'yui-compass-plugin', 'yui') \ No newline at end of file