Class: UnifiedAssets::Tasks
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- UnifiedAssets::Tasks
- Defined in:
- lib/unified_assets/tasks.rb
Instance Attribute Summary collapse
-
#assets ⇒ Object
Returns the value of attribute assets.
-
#minify ⇒ Object
Returns the value of attribute minify.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #define ⇒ Object
- #define_clear_task ⇒ Object
- #define_create_task ⇒ Object
- #define_server_task ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Tasks
constructor
A new instance of Tasks.
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Tasks
Returns a new instance of Tasks.
11 12 13 14 15 16 17 |
# File 'lib/unified_assets/tasks.rb', line 11 def initialize( = {}) @assets = [:assets] @minify = [:minify] @server = [:server] || {} yield(self) if block_given? define end |
Instance Attribute Details
#assets ⇒ Object
Returns the value of attribute assets.
7 8 9 |
# File 'lib/unified_assets/tasks.rb', line 7 def assets @assets end |
#minify ⇒ Object
Returns the value of attribute minify.
8 9 10 |
# File 'lib/unified_assets/tasks.rb', line 8 def minify @minify end |
#server ⇒ Object
Returns the value of attribute server.
9 10 11 |
# File 'lib/unified_assets/tasks.rb', line 9 def server @server end |
Instance Method Details
#define ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/unified_assets/tasks.rb', line 19 def define namespace :assets do define_clear_task define_create_task define_server_task end end |
#define_clear_task ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/unified_assets/tasks.rb', line 27 def define_clear_task desc "clear unified asset files" task :clear do assets.keys.each do |asset| Dir[asset, Minifier.minified_name(asset)].each {|f| File.delete(f) if File.exists?(f) } end end end |
#define_create_task ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/unified_assets/tasks.rb', line 36 def define_create_task desc "create unified asset files" task :create do Rake::Task["assets:clear"].invoke assets.keys.each do |asset| UnifiedAssets.build(assets[asset], asset, :minify => minify) end end end |
#define_server_task ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/unified_assets/tasks.rb', line 46 def define_server_task desc "simple webserver that auto-regenerates assets if they are out of date" task :server do |t, args| require 'rack' require 'unified_assets/server' = { :root => ENV['ROOT'] || server[:root] || '.', :port => ENV['PORT'] || server[:port] || 3000, :debug => ENV['DEBUG'] || server[:debug] || true, :assets => assets } app = Rack::Builder.new do use Rack::CommonLogger use Rack::ShowExceptions use Rack::Lint use UnifiedAssets::Server, run Rack::File.new([:root]) end.to_app handler = Rack::Handler.get(ENV['HANDLER'] || server[:handler]) handler ||= begin; Rack::Handler::Thin; rescue LoadError; end handler ||= begin; Rack::Handler::Mongrel; rescue LoadError; end handler ||= Rack::Handler::WEBrick handler.run(app, :Port => [:port]) end end |