Sha256: 1e4d0176a7b503b22622e83410be2ae20df99aa0ead1a49abf64b17ed14aa1e7

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

require 'rake'
require 'rake/sprocketstask'
require 'sprockets'

module Sprockets
  module Rails
    class Task < Rake::SprocketsTask
      attr_accessor :app

      def initialize(app = nil)
        self.app = app
        super()
      end

      def environment
        if app
          app.assets
        else
          super
        end
      end

      def output
        if app
          File.join(app.root, 'public', app.config.assets.prefix)
        else
          super
        end
      end

      def assets
        if app
          app.config.assets.precompile
        else
          super
        end
      end

      def cache_path
        if app
          "#{app.config.root}/tmp/cache/assets"
        else
          @cache_path
        end
      end
      attr_writer :cache_path

      def define
        namespace :assets do
          # Override this task change the loaded dependencies
          desc "Load asset compile environment"
          task :environment do
            # Load full Rails environment by default
            Rake::Task['environment'].invoke
          end

          desc "Compile all the assets named in config.assets.precompile"
          task :precompile => :environment do
            with_logger do
              manifest.compile(assets)
            end
          end

          desc "Remove old compiled assets"
          task :clean => :environment do
            with_logger do
              manifest.clean(keep)
            end
          end

          desc "Remove compiled assets"
          task :clobber => :environment do
            with_logger do
              manifest.clobber
              rm_rf cache_path if cache_path
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
sprockets-rails-2.0.0.backport1 lib/sprockets/rails/task.rb
challah-1.0.0 vendor/bundle/gems/sprockets-rails-2.0.0/lib/sprockets/rails/task.rb
sprockets-rails-2.0.0 lib/sprockets/rails/task.rb