Class: Rake::SprocketsTask
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Rake::TaskLib
|
|
Instance Chain:
self,
Rake::TaskLib
|
|
Inherits: |
Rake::TaskLib
|
Defined in: | lib/rake/sprocketstask.rb |
Overview
Simple Sprockets compilation ::Rake
task macro.
Rake::SprocketsTask.new do |t|
t.environment = Sprockets::Environment.new
t.output = "./public/assets"
t.assets = %w( application.js application.css )
end
Class Method Summary
Instance Attribute Summary
-
#age
rw
Assets created within this age will be kept.
-
#assets
rw
Array of asset logical paths to compile.
-
#environment
rw
Environment
instance used for finding assets. - #environment=(value) rw
-
#keep
rw
Minimum number of old assets to keep.
-
#log_level
rw
Returns logger level Integer.
-
#log_level=(level)
rw
Set logger level with constant or symbol.
-
#logger
rw
Logger to use during rake tasks.
-
#manifest
rw
Manifest
instance used for already compiled assets. - #manifest=(value) rw
-
#name
rw
Name of the task.
-
#output
rw
Directory to write compiled assets too.
Instance Method Summary
-
#cached
(also: #index)
Returns cached cached environment.
-
#define
Define tasks.
-
#index
Alias for #cached.
-
#with_logger
private
Sub out environment logger with our rake task logger that writes to stderr.
Constructor Details
.new(name = :assets) {|_self| ... } ⇒ SprocketsTask
# File 'lib/rake/sprocketstask.rb', line 102
def initialize(name = :assets) @name = name @environment = lambda { Sprockets::Environment.new(Dir.pwd) } @manifest = lambda { Sprockets::Manifest.new(cached, output) } @logger = Logger.new($stderr) @logger.level = Logger::INFO @keep = 2 @age = 3600 yield self if block_given? define end
Instance Attribute Details
#age (rw)
Assets created within this age will be kept. See Sprockets::Manifest#clean for more information.
# File 'lib/rake/sprocketstask.rb', line 76
attr_accessor :age
#assets (rw)
Array of asset logical paths to compile.
t.assets = %w( application.js jquery.js application.css )
# File 'lib/rake/sprocketstask.rb', line 70
attr_accessor :assets
#environment (rw)
Environment
instance used for finding assets.
You’ll most likely want to reassign environment
to your own.
Rake::SprocketsTask.new do |t|
t.environment = Foo::Assets
end
#environment=(value) (rw)
[ GitHub ]# File 'lib/rake/sprocketstask.rb', line 39
attr_writer :environment
#keep (rw)
Minimum number of old assets to keep. See Sprockets::Manifest#clean for more information.
# File 'lib/rake/sprocketstask.rb', line 73
attr_accessor :keep
#log_level (rw)
Returns logger level Integer.
# File 'lib/rake/sprocketstask.rb', line 85
def log_level @logger.level end
#log_level=(level) (rw)
[ GitHub ]# File 'lib/rake/sprocketstask.rb', line 94
def log_level=(level) if level.is_a?(Integer) @logger.level = level else @logger.level = Logger.const_get(level.to_s.upcase) end end
#logger (rw)
Logger to use during rake tasks. Defaults to using stderr.
t.logger = Logger.new($stdout)
# File 'lib/rake/sprocketstask.rb', line 82
attr_accessor :logger
#manifest (rw)
Manifest
instance used for already compiled assets.
Will be created by default if an environment and output directory are given
#manifest=(value) (rw)
[ GitHub ]# File 'lib/rake/sprocketstask.rb', line 58
attr_writer :manifest
#name (rw)
Name of the task. Defaults to “assets”.
The name will also be used to suffix the clean and clobber tasks, “clean_assets” and “clobber_assets”.
# File 'lib/rake/sprocketstask.rb', line 22
attr_accessor :name
#output (rw)
Directory to write compiled assets too. As well as the manifest file.
t.output = "./public/assets"
# File 'lib/rake/sprocketstask.rb', line 64
attr_accessor :output
Instance Method Details
#cached Also known as: #index
Returns cached cached environment
# File 'lib/rake/sprocketstask.rb', line 42
def cached @cached ||= environment.cached if environment end
#define
Define tasks
# File 'lib/rake/sprocketstask.rb', line 117
def define desc name == :assets ? "Compile assets" : "Compile #{name} assets" task name do with_logger do manifest.compile(assets) end end desc name == :assets ? "Remove all assets" : "Remove all #{name} assets" task "clobber_#{name}" do with_logger do manifest.clobber end end task clobber: ["clobber_#{name}"] desc name == :assets ? "Clean old assets" : "Clean old #{name} assets" task "clean_#{name}" do with_logger do manifest.clean(keep, age) end end task clean: ["clean_#{name}"] end
#index
Alias for #cached.
# File 'lib/rake/sprocketstask.rb', line 45
alias_method :index, :cached
#with_logger (private)
Sub out environment logger with our rake task logger that writes to stderr.
# File 'lib/rake/sprocketstask.rb', line 147
def with_logger if env = manifest.environment old_logger = env.logger env.logger = @logger end yield ensure env.logger = old_logger if env end