Class: Rake::SprocketsTask

### Home Classes Methods

### In Files

- lib/rake/sprocketstask.rb

### Parent

Rake::TaskLib

### Methods

- ::new
- #define
- #environment
- #index
- #log_level
- #log_level=
- #manifest

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::AssetAttributes
- Sprockets::Base
- Sprockets::BundledAsset
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Caching
- Sprockets::CharsetNormalizer
- Sprockets::CircularDependencyError
- Sprockets::ClosureCompressor
- Sprockets::Compressing
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::DirectiveProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsTemplate
- Sprockets::EncodingError
- Sprockets::EngineError
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::Manifest
- Sprockets::Mime
- Sprockets::NotImplementedError
- Sprockets::Paths
- Sprockets::ProcessedAsset
- Sprockets::ProcessedAsset::DependencyFile
- Sprockets::Processing
- Sprockets::Processor
- Sprockets::SafetyColons
- Sprockets::SassCacheStore
- Sprockets::SassCompressor
- Sprockets::SassFunctions
- Sprockets::SassImporter
- Sprockets::SassTemplate
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::StaticAsset
- Sprockets::UglifierCompressor
- Sprockets::UnserializeError
- Sprockets::Utils
- Sprockets::YUICompressor
- Rake
- Rake::SprocketsTask

No matching classes.

# Rake::SprocketsTask

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

### Attributes

assets[RW]

Array of asset logical paths to compile.

    t.assets = %w( application.js jquery.js application.css )

environment[W]
keep[RW]

Number of old assets to keep.

logger[RW]

Logger to use during rake tasks. Defaults to using stderr.

    t.logger = Logger.new($stdout)

manifest[W]
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".

output[RW]

Directory to write compiled assets too. As well as the manifest file.

    t.output = "./public/assets"

### Public Class Methods

new(name = :assets) click to toggle source

    # File lib/rake/sprocketstask.rb, line 97
    def initialize(name = :assets)
      @name         = name
      @environment  = lambda { Sprockets::Environment.new(Dir.pwd) }
      @manifest     = lambda { Sprockets::Manifest.new(index, output) }
      @logger       = Logger.new($stderr)
      @logger.level = Logger::INFO
      @keep         = 2

      yield self if block_given?

      define
    end

### Public Instance Methods

define() click to toggle source

Define tasks

    # File lib/rake/sprocketstask.rb, line 111
    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

environment() click to toggle source

`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

    # File lib/rake/sprocketstask.rb, line 31
    def environment
      if !@environment.is_a?(Sprockets::Base) && @environment.respond_to?(:call)
        @environment = @environment.call
      else
        @environment
      end
    end

index() click to toggle source

Returns cached indexed environment

    # File lib/rake/sprocketstask.rb, line 41
    def index
      @index ||= environment.index if environment
    end

log_level() click to toggle source

Returns logger level Integer.

    # File lib/rake/sprocketstask.rb, line 80
    def log_level
      @logger.level
    end

log_level=(level) click to toggle source

Set logger level with constant or symbol.

    t.log_level = Logger::INFO
    t.log_level = :debug

    # File lib/rake/sprocketstask.rb, line 89
    def log_level=(level)
      if level.is_a?(Integer)
        @logger.level = level
      else
        @logger.level = Logger.const_get(level.to_s.upcase)
      end
    end

manifest() click to toggle source

`Manifest` instance used for already compiled assets.

Will be created by default if an environment and output directory are given

    # File lib/rake/sprocketstask.rb, line 49
    def manifest
      if !@manifest.is_a?(Sprockets::Manifest) && @manifest.respond_to?(:call)
        @manifest = @manifest.call
      else
        @manifest
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.