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
# File 'lib/juicer/install/yui_compressor_installer.rb', line 13

def initialize(install_dir = Juicer.home)
  super(install_dir)
  @latest = nil
  @href = nil
  @website = "http://yuilibrary.com/downloads/"
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



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

def install(version = nil)
  version = super(version)
  base = "yuicompressor-#{version}"
  filename = download(@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



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

def latest
  return @latest if @latest
  webpage = Nokogiri::HTML(open(@website))
  a = (webpage / "h3#yuicompressor + ul li a:last")[0]
  @href = a["href"]
  @latest = a.text.match(/(\d\.\d\.\d)/)[1]
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.



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

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