Sha256: 744560f98a4f18d3d3c3f272f28e0fda612ae18a772ddd03a3fa208cdb87b735

Contents?: true

Size: 1.58 KB

Versions: 19

Compression:

Stored size: 1.58 KB

Contents

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, branch = "master", working_directory = Dir.pwd)
  download_link = "http://github.com/#{user}/#{project}/zipball/#{branch}"
  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

Version data entries

19 entries across 18 versions & 3 rubygems

Version Path
compass-0.10.0.rc3 examples/downloader.rb
compass-0.10.0.rc2 examples/downloader.rb
compass-0.10.0.rc1 examples/downloader.rb
compass-0.10.0.pre9 examples/downloader.rb
compass-0.10.0.pre8 examples/downloader.rb
compass-0.10.0.pre7 examples/downloader.rb
compass-0.10.0.pre6 examples/downloader.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/compass-0.10.0.pre4/examples/downloader.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/compass-0.10.0.pre5/examples/downloader.rb
compass-0.10.0.pre5 examples/downloader.rb
compass-0.10.0.pre4 examples/downloader.rb
compass-0.10.0.pre3 examples/downloader.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/compass-0.10.0.pre2/examples/downloader.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/compass-0.10.0.pre2/examples/downloader.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/compass-0.10.0.pre2/examples/downloader.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/compass-0.10.0.pre2/examples/downloader.rb
compass-0.10.0.pre2 examples/downloader.rb
compass-0.10.0.pre1 examples/downloader.rb
compass-edge-0.9.5.0 examples/downloader.rb