Bootstrap download the yui plugin for the examples.

This commit is contained in:
Chris Eppstein 2009-08-29 15:52:21 -07:00
parent d4971fcfaa
commit 3b7637f1e5
4 changed files with 66 additions and 48 deletions

View File

@ -108,8 +108,10 @@ task :examples do
next unless File.directory?(example) next unless File.directory?(example)
puts "\nCompiling #{example}" puts "\nCompiling #{example}"
puts "=" * "Compiling #{example}".length puts "=" * "Compiling #{example}".length
bootstrap_file = File.join(example, "bootstrap.rb") Dir.chdir example do
load bootstrap_file if File.exists?(bootstrap_file) load "bootstrap.rb" if File.exists?("bootstrap.rb")
Compass::Exec::Compass.new(["--force"]).run!
end
# compile any haml templates to html # compile any haml templates to html
FileList["#{example}/**/*.haml"].each do |haml_file| FileList["#{example}/**/*.haml"].each do |haml_file|
basename = haml_file[0..-6] basename = haml_file[0..-6]
@ -119,9 +121,6 @@ task :examples do
output.write(engine.render) output.write(engine.render)
output.close output.close
end end
Dir.chdir example do
Compass::Exec::Compass.new(["--force"]).run!
end
end end
end end

57
examples/downloader.rb Normal file
View File

@ -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

View File

@ -1,45 +1,4 @@
require 'net/http' require File.join(File.dirname(__FILE__), '..', 'downloader')
require 'fileutils'
require 'rubygems'
require 'zip/zip'
extdir = File.join(File.dirname(__FILE__),'extensions') install_from_github('chriseppstein', 'compass-960-plugin', 'ninesixty')
download_link = "http://github.com/chriseppstein/compass-960-plugin/zipball/master"
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

View File

@ -0,0 +1,3 @@
require File.join(File.dirname(__FILE__), '..', 'downloader')
install_from_github('chriseppstein', 'yui-compass-plugin', 'yui')