class Rake::SprocketsTask
end
t.assets = %w( application.js application.css )
t.output = “./public/assets”
t.environment = Sprockets::Environment.new
Rake::SprocketsTask.new do |t|
Simple Sprockets compilation Rake task macro.
def cached
def cached @cached ||= environment.cached if environment end
def define
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) end end task clean: ["clean_#{name}"] end
def environment
end
t.environment = Foo::Assets
Rake::SprocketsTask.new do |t|
You'll most likely want to reassign `environment` to your own.
`Environment` instance used for finding assets.
def environment if !@environment.is_a?(Sprockets::Base) && @environment.respond_to?(:call) @environment = @environment.call else @environment end end
def initialize(name = :assets)
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 yield self if block_given? define end
def log_level
def log_level @logger.level end
def log_level=(level)
t.log_level = :debug
t.log_level = Logger::INFO
Set logger level with constant or symbol.
def log_level=(level) if level.is_a?(Integer) @logger.level = level else @logger.level = Logger.const_get(level.to_s.upcase) end end
def manifest
Will be created by default if an environment and output
`Manifest` instance used for already compiled assets.
def manifest if !@manifest.is_a?(Sprockets::Manifest) && @manifest.respond_to?(:call) @manifest = @manifest.call else @manifest end end
def with_logger
Sub out environment logger with our rake task logger that
def with_logger if env = manifest.environment old_logger = env.logger env.logger = @logger end yield ensure env.logger = old_logger if env end