Class: Yui
Defined Under Namespace
Classes: NoInputFileException
Constant Summary collapse
- MAJOR =
0
- MINOR =
0
- RELEASE =
3
- YUI_ROOT =
File.join(File.dirname(__FILE__),'..','..')
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#inpath ⇒ Object
readonly
Returns the value of attribute inpath.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.clobber(path, suffix, type) ⇒ Object
Clobber *.SUFFIX.(js|css).
-
.compress(inpath, options = {}) ⇒ Boolean
Compresses inpath with options.
- .version ⇒ Object
Instance Method Summary collapse
-
#bundle ⇒ String|nil
Bundles a set of files to #href=":out_path">options/bundle.#href=":suffix">options.#href=":type">options.
-
#clobber ⇒ Object
Clobbers files with the right suffix/type in the outpath outpath defaults to inpath.
-
#initialize(inpath, options = {}) ⇒ Yui
constructor
Grabs a glob of files inpath + options will create a glob, directory structure will be replicated in outputh.
- #minify ⇒ Object (also: #compress)
- #outpath ⇒ Object
Constructor Details
#initialize(inpath, options = {}) ⇒ Yui
Grabs a glob of files inpath + options will create a glob,
directory structure will be replicated in outputh
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-yui/yui.rb', line 30 def initialize(inpath,={}) @inpath = inpath @options = Yui.defaults.merge() glob_path = File.join(@inpath,"**","*.#{@options[:type]}") @files = Dir.glob(glob_path) #Dont compress ruby-yui files. @files.delete_if {|file| file =~ /#{@options[:suffix]}/} self.clobber if @options[:clobber] end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
41 42 43 |
# File 'lib/ruby-yui/yui.rb', line 41 def files @files end |
#inpath ⇒ Object (readonly)
Returns the value of attribute inpath.
42 43 44 |
# File 'lib/ruby-yui/yui.rb', line 42 def inpath @inpath end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
43 44 45 |
# File 'lib/ruby-yui/yui.rb', line 43 def @options end |
Class Method Details
.clobber(path, suffix, type) ⇒ Object
Clobber *.SUFFIX.(js|css)
128 129 130 131 132 133 134 |
# File 'lib/ruby-yui/yui.rb', line 128 def Yui.clobber(path,suffix,type) files = Dir.glob(File.join(path,"**","*.#{suffix}.#{type}")) files.each do |file| puts "Clobbering #{file}..." FileUtils.rm file end end |
Instance Method Details
#bundle ⇒ String|nil
Bundles a set of files to
#{@options[:out_path]}/bundle.#{@options[:suffix]}.#{@options[:type]}
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ruby-yui/yui.rb', line 61 def bundle if @files.empty? raise NoInputFileException, "Nothing to do, check input path." end bundle_data = "" successful_compressions = 0 @files.each do |file| cmd = Yui.gen_cmd(file,@options) stdin, stdout, stderr = popen3(cmd.join(' ')) bundle_tmp = stdout.read if stderr.read.empty? puts "Bundling: #{file}" bundle_data += "\n#{bundle_tmp}" successful_compressions += 1 else puts "Failed to bundle: #{file}" end end if successful_compressions == @files.length bundle_file_name = "bundle.#{@options[:suffix]}.#{@options[:type]}" bundle_path = File.join(outpath,bundle_file_name) File.open(bundle_path,'w'){|f| f.write(bundle_data)} return bundle_path else return nil end end |
#clobber ⇒ Object
Clobbers files with the right suffix/type in the outpath
outpath defaults to inpath
51 52 53 |
# File 'lib/ruby-yui/yui.rb', line 51 def clobber Yui.clobber(outpath,@options[:suffix],@options[:type]) end |
#minify ⇒ Object Also known as: compress
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ruby-yui/yui.rb', line 92 def minify if @files.empty? raise NoInputFileException, "Nothing to do, check input path." end successful_compressions = 0 @files.each do |file| out_file = file.split('.') # split on '.' out_file.pop # pop off file extension out_file.push @options[:suffix] # add yui min suffix out_file.push @options[:type] # add extension back on out_file = out_file.join('.') # put it all together out_file.sub!(@inpath,outpath) if @options[:out_path] cmd = Yui.gen_cmd(file,@options) cmd << "-o #{out_file}" FileUtils.mkdir_p File.dirname(out_file) puts "Compressing:\n\t #{file} =>\n\t #{out_file}" stdin, stdout, stderr = popen3(cmd.join(' ')) if stdout.read.empty? && stderr.read.empty? successful_compressions += 1 else puts "Failed to compress: #{file}" end end return (successful_compressions == @files.length) end |
#outpath ⇒ Object
45 46 47 |
# File 'lib/ruby-yui/yui.rb', line 45 def outpath @options[:out_path] || @inpath end |