Class: Rake::CompileTask
- Inherits:
-
TaskLib
- Object
- TaskLib
- Rake::CompileTask
- Defined in:
- lib/jquery_plugin_gen/compiletask.rb
Overview
Create a compiling task that will build the project into distributable files (e.g a single and a packed js file with compression).
The CompileTask will create the following targets:
- :compile
-
Create all the requested package files.
- :clobber_compile
-
Delete all the package files. This target is automatically added to the main clobber target.
- :recompile
-
Rebuild the package files from scratch, even if they are not out of date.
Example:
JqueryPluginGen::CompileTask.new('query.plugin') do |p|
p.js_files.include("src/**/*.js")
p.css_files.include("src/css/**/*.css")
p.image_files.include("src/images/**/*.*")
p.js_dir = "src"
p.images_dir = "images"
p.css_dir = "css"
p.package_files.include("README.txt", "HISTORY.txt")
p.package_dir = "build"
end
Instance Attribute Summary collapse
-
#css_dir ⇒ Object
Directory used to store the package files (default is ‘css’).
-
#css_files ⇒ Object
List of files to be included in the package.
-
#image_files ⇒ Object
List of files to be included in the package.
-
#images_dir ⇒ Object
Directory used to store the package files (default is ‘images’).
-
#js_files ⇒ Object
List of files to be included in the package.
-
#name ⇒ Object
Name of the plugin files (don’t add .js, eg ‘jquery.mywidget’).
-
#need_packer ⇒ Object
True if the single js file is compressed using PACKER (default is true).
-
#need_sed ⇒ Object
True if the single js file is compiled using SED (default is true).
-
#package_dir ⇒ Object
Directory used to store the package files (default is ‘build’).
-
#package_files ⇒ Object
List of files to be included in the package.
Instance Method Summary collapse
-
#define ⇒ Object
Create the tasks defined by this task library.
-
#init(name) ⇒ Object
Initialization that bypasses the “yield self” and “define” step.
-
#initialize(name) {|_self| ... } ⇒ CompileTask
constructor
Create a Compile Task.
- #package_css_path ⇒ Object
- #package_dir_path ⇒ Object
- #package_images_path ⇒ Object
- #package_js ⇒ Object
- #packed_js ⇒ Object
- #packer_command ⇒ Object
- #sed_command ⇒ Object
Constructor Details
#initialize(name) {|_self| ... } ⇒ CompileTask
Create a Compile Task
75 76 77 78 79 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 75 def initialize(name) init(name) yield self if block_given? define unless name.nil? end |
Instance Attribute Details
#css_dir ⇒ Object
Directory used to store the package files (default is ‘css’).
51 52 53 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 51 def css_dir @css_dir end |
#css_files ⇒ Object
List of files to be included in the package.
69 70 71 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 69 def css_files @css_files end |
#image_files ⇒ Object
List of files to be included in the package.
72 73 74 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 72 def image_files @image_files end |
#images_dir ⇒ Object
Directory used to store the package files (default is ‘images’).
48 49 50 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 48 def images_dir @images_dir end |
#js_files ⇒ Object
List of files to be included in the package.
66 67 68 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 66 def js_files @js_files end |
#name ⇒ Object
Name of the plugin files (don’t add .js, eg ‘jquery.mywidget’).
45 46 47 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 45 def name @name end |
#need_packer ⇒ Object
True if the single js file is compressed using PACKER (default is true).
60 61 62 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 60 def need_packer @need_packer end |
#need_sed ⇒ Object
True if the single js file is compiled using SED (default is true).
57 58 59 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 57 def need_sed @need_sed end |
#package_dir ⇒ Object
Directory used to store the package files (default is ‘build’).
54 55 56 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 54 def package_dir @package_dir end |
#package_files ⇒ Object
List of files to be included in the package.
63 64 65 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 63 def package_files @package_files end |
Instance Method Details
#define ⇒ Object
Create the tasks defined by this task library.
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 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 100 def define fail "Name required (or :noversion)" if @name.nil? @name = nil if :noname == @name desc "Build all the packages" task :compile => :pack do [images_dir, css_dir].each { |dir| mkdir_p("#{package_dir_path}/#{dir}") } FileUtils.cp(image_files, package_images_path) FileUtils.cp(css_files, package_css_path) FileUtils.cp(package_files, package_dir_path) end desc "Force a rebuild of the package files" task :recompile => [:clobber_compile, :compile] desc "Remove compile products" task :clobber_compile do FileUtils.rm_r(package_dir_path) rescue nil end desc "Merge js files into one" task :merge do FileUtils.mkdir(package_dir_path) rescue nil `#{sed_command}` end desc "Compress js files to min" task :pack => :merge do `#{packer_command}` end task :clobber => [:clobber_compile] self end |
#init(name) ⇒ Object
Initialization that bypasses the “yield self” and “define” step.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 82 def init(name) @name = name @package_files = Rake::FileList["README.txt", "HISTORY.txt"] @package_dir = 'build' @need_sed = true @need_packer = true @images_dir = 'images' @css_dir = 'css' @js_dir = 'src' @js_files = Rake::FileList.new @js_files.include("#{@js_dir}/**/*.js") @image_files = Rake::FileList.new @image_files.include("#{@js_dir}/#{@image_dir}/**/*.*") @css_files = Rake::FileList.new @css_files.include("#{@js_dir}/#{@css_dir}/**/*.css") end |
#package_css_path ⇒ Object
140 141 142 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 140 def package_css_path "#{package_dir_path}/#{css_dir}" end |
#package_dir_path ⇒ Object
136 137 138 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 136 def package_dir_path "#{package_dir}" end |
#package_images_path ⇒ Object
144 145 146 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 144 def package_images_path "#{package_dir_path}/#{images_dir}" end |
#package_js ⇒ Object
148 149 150 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 148 def package_js "#{package_dir_path}/#{name}.js" end |
#packed_js ⇒ Object
152 153 154 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 152 def packed_js "#{package_dir_path}/#{name}.min.js" end |
#packer_command ⇒ Object
160 161 162 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 160 def packer_command "perl -I #{File.dirname(__FILE__)}/../packer #{File.dirname(__FILE__)}/../packer/jsPacker.pl -i #{package_js} -o #{packed_js} -e62" end |
#sed_command ⇒ Object
156 157 158 |
# File 'lib/jquery_plugin_gen/compiletask.rb', line 156 def sed_command "sed -e '1 s/^\xEF\xBB\xBF//' #{js_files} > #{package_js}" end |