Class: Juicer::Install::YuiCompressorInstaller

Inherits:
Base
  • Object
show all
Defined in:
lib/juicer/install/yui_compressor_installer.rb

Overview

Install and uninstall routines for the YUI Compressor. Installation downloads the YUI Compressor distribution, unzips it and storesthe jar file on disk along with the license.

Instance Attribute Summary

Attributes inherited from Base

#install_dir

Instance Method Summary collapse

Methods inherited from Base

#bin_path, #dependencies, #dependency, #download, #installed?, #log, #name, #path

Constructor Details

#initialize(install_dir = Juicer.home) ⇒ YuiCompressorInstaller

Returns a new instance of YuiCompressorInstaller.



13
14
15
16
17
18
19
# File 'lib/juicer/install/yui_compressor_installer.rb', line 13

def initialize(install_dir = Juicer.home)
  super(install_dir)
  @latest = nil
  @href = nil
  @website = 'https://github.com/yui/yuicompressor/downloads'
  @cdn = 'http://cloud.github.com'
end

Instance Method Details

#install(version = nil) ⇒ Object

Install the Yui Compressor. Downloads the distribution and keeps the jar file inside PATH/yui_compressor/bin and the README and CHANGELOG in PATH/yui_compressor/x.y.z/ where x.y.z is the version, most recent if not specified otherwise.

Path defaults to environment variable $JUICER_HOME or default Juicer home



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/juicer/install/yui_compressor_installer.rb', line 30

def install(version = nil)
  version = super(version)
  base = "yuicompressor-#{version}"
  filename = download(@cdn+@href)
  target = File.join(@install_dir, path)

  Zip::ZipFile.open(filename) do |file|
    file.extract("#{base}/doc/README", File.join(target, version, "README"))
    file.extract("#{base}/doc/CHANGELOG", File.join(target, version, "CHANGELOG"))
    file.extract("#{base}/build/#{base}.jar", File.join(target, "bin", "#{base}.jar"))
  end
end

#latestObject

Check which version is the most recent



62
63
64
65
66
67
68
# File 'lib/juicer/install/yui_compressor_installer.rb', line 62

def latest
  return @latest if @latest
  webpage = Nokogiri::HTML(open(@website).read)
  a = webpage.css('#manual_downloads h4 a').first
  @href = a['href']
  @latest = a.text.match(/\d\.\d\.\d/)[0]
end

#uninstall(version = nil) ⇒ Object

Uninstalls the given version of YUI Compressor. If no location is provided the environment variable $JUICER_HOME or Juicers default home directory is used.

If no version is provided the most recent version is assumed.

If there are no more files left in INSTALLATION_PATH/yui_compressor, the whole directory is removed.



53
54
55
56
57
# File 'lib/juicer/install/yui_compressor_installer.rb', line 53

def uninstall(version = nil)
  super(version) do |dir, version|
    File.delete(File.join(dir, "bin/yuicompressor-#{version}.jar"))
  end
end