Skip to content

Commit 961e82b

Browse files
committed
Pass app reference to rake task
1 parent 6e342e7 commit 961e82b

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

lib/sprockets/rails/task.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,45 @@
55
module Sprockets
66
module Rails
77
class Task < Rake::SprocketsTask
8-
attr_accessor :cache_path
8+
attr_accessor :app
9+
10+
def initialize(app = nil)
11+
self.app = app
12+
super()
13+
end
14+
15+
def environment
16+
if app
17+
app.assets
18+
else
19+
super
20+
end
21+
end
22+
23+
def output
24+
if app
25+
File.join(app.root, 'public', app.config.assets.prefix)
26+
else
27+
super
28+
end
29+
end
30+
31+
def assets
32+
if app
33+
app.config.assets.precompile
34+
else
35+
super
36+
end
37+
end
38+
39+
def cache_path
40+
if app
41+
"#{app.config.root}/tmp/cache/assets"
42+
else
43+
@cache_path
44+
end
45+
end
46+
attr_writer :cache_path
947

1048
def define
1149
namespace :assets do

lib/sprockets/railtie.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,7 @@ def configure(&block)
5858

5959
rake_tasks do |app|
6060
require 'sprockets/rails/task'
61-
62-
Sprockets::Rails::Task.new do |t|
63-
t.environment = lambda { app.assets }
64-
t.output = File.join(app.root, 'public', app.config.assets.prefix)
65-
t.assets = app.config.assets.precompile
66-
t.cache_path = "#{app.config.root}/tmp/cache/assets"
67-
end
61+
Sprockets::Rails::Task.new(app)
6862
end
6963

7064
config.after_initialize do |app|

0 commit comments

Comments
 (0)