Class: Rake::AssetTasks
- Inherits:
-
TaskLib
- Object
- TaskLib
- Rake::AssetTasks
- Defined in:
- lib/rake/asset_tasks.rb
Overview
Constant Summary collapse
- DEFINED_TASKS =
proc do namespace :assets do desc 'precompile assets' task :precompile do with_logger do manifest.compile(assets) end end desc 'Remove all assets' task :clobber do with_logger do manifest.clobber end end desc 'Clean old assets' task :clean do with_logger do manifest.clean(keep) end end end end
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#keep ⇒ Object
readonly
Returns the value of attribute keep.
-
#logger ⇒ Object
Logger to use during rake tasks.
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #assets ⇒ Object
-
#define ⇒ Object
Define tasks.
-
#initialize {|_self| ... } ⇒ AssetTasks
constructor
A new instance of AssetTasks.
-
#log_level ⇒ Object
Returns logger level Integer.
-
#log_level=(level) ⇒ Object
Set logger level with constant or symbol.
Constructor Details
#initialize {|_self| ... } ⇒ AssetTasks
Returns a new instance of AssetTasks.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rake/asset_tasks.rb', line 73 def initialize @environment = Flatrack.assets @logger = Logger.new($stderr) @logger.level = Logger::INFO @output = './public/assets' yield self if block_given? @index = environment.index @manifest = Sprockets::Manifest.new(index, output) @keep = 2 define end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
13 14 15 |
# File 'lib/rake/asset_tasks.rb', line 13 def environment @environment end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
14 15 16 |
# File 'lib/rake/asset_tasks.rb', line 14 def index @index end |
#keep ⇒ Object (readonly)
Returns the value of attribute keep.
16 17 18 |
# File 'lib/rake/asset_tasks.rb', line 16 def keep @keep end |
#logger ⇒ Object
Logger to use during rake tasks. Defaults to using stderr.
t.logger = Logger.new($stdout)
53 54 55 |
# File 'lib/rake/asset_tasks.rb', line 53 def logger @logger end |
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
15 16 17 |
# File 'lib/rake/asset_tasks.rb', line 15 def manifest @manifest end |
#output ⇒ Object
Returns the value of attribute output.
12 13 14 |
# File 'lib/rake/asset_tasks.rb', line 12 def output @output end |
Instance Method Details
#assets ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rake/asset_tasks.rb', line 85 def assets files = paths.reduce([]) do |ary, path| ary + Dir[File.join path, '**', '*'] end files.map do |file| file_basename = File.basename file parts = file_basename.split('.').size file = file.split('.').tap(&:pop).join('.') if parts > 2 File.(file).sub(/(#{environment.paths.join('|')})\//, '') end end |
#define ⇒ Object
Define tasks
98 99 100 |
# File 'lib/rake/asset_tasks.rb', line 98 def define instance_eval(&DEFINED_TASKS) end |
#log_level ⇒ Object
Returns logger level Integer.
56 57 58 |
# File 'lib/rake/asset_tasks.rb', line 56 def log_level @logger.level end |
#log_level=(level) ⇒ Object
Set logger level with constant or symbol.
t.log_level = Logger::INFO
t.log_level = :debug
65 66 67 68 69 70 71 |
# File 'lib/rake/asset_tasks.rb', line 65 def log_level=(level) if level.is_a?(Integer) @logger.level = level else @logger.level = Logger.const_get(level.to_s.upcase) end end |