Class: Juicer::Install::YuiCompressorInstaller
- 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
Instance Method Summary collapse
-
#initialize(install_dir = Juicer.home) ⇒ YuiCompressorInstaller
constructor
A new instance of YuiCompressorInstaller.
-
#install(version = nil) ⇒ Object
Install the Yui Compressor.
-
#latest ⇒ Object
Check which version is the most recent.
-
#uninstall(version = nil) ⇒ Object
Uninstalls the given version of YUI Compressor.
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.
14 15 16 17 18 19 20 |
# File 'lib/juicer/install/yui_compressor_installer.rb', line 14 def initialize(install_dir = Juicer.home) super(install_dir) @latest = nil @href = nil @website = 'https://github.com/yui/yuicompressor/downloads' @cdn = 'https://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
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/juicer/install/yui_compressor_installer.rb', line 31 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 |
#latest ⇒ Object
Check which version is the most recent
63 64 65 66 67 68 69 |
# File 'lib/juicer/install/yui_compressor_installer.rb', line 63 def latest return @latest if @latest webpage = Nokogiri::HTML(open(@website, :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).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.
54 55 56 57 58 |
# File 'lib/juicer/install/yui_compressor_installer.rb', line 54 def uninstall(version = nil) super(version) do |dir, version| File.delete(File.join(dir, "bin/yuicompressor-#{version}.jar")) end end |