sprockets-rails 2.0.0.rc1 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/sprockets/rails/helper.rb +2 -3
- data/lib/sprockets/rails/task.rb +7 -0
- data/lib/sprockets/railtie.rb +50 -32
- metadata +4 -4
data/README.md
CHANGED
@@ -31,7 +31,7 @@ Nuke `public/assets` and clear the Sprockets file system cache.
|
|
31
31
|
|
32
32
|
#### Customize
|
33
33
|
|
34
|
-
If the basic tasks don't do all that you need,
|
34
|
+
If the basic tasks don't do all that you need, it's straight forward to redefine them and replace them with something more specific to your app.
|
35
35
|
|
36
36
|
You can also redefine the task with the built in task generator.
|
37
37
|
|
@@ -44,6 +44,8 @@ Sprockets::Rails::Task.new do |t|
|
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
47
|
+
Each asset task will invoke `assets:environment` first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment.
|
48
|
+
|
47
49
|
Also see [Sprockest::Rails::Task](https://github.com/josh/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/sstephenson/sprockets/blob/master/lib/rake/sprocketstask.rb).
|
48
50
|
|
49
51
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'action_view'
|
2
2
|
require 'sprockets'
|
3
|
-
|
4
3
|
require 'active_support/core_ext/class/attribute'
|
5
4
|
|
6
5
|
module Sprockets
|
@@ -95,7 +94,7 @@ module Sprockets
|
|
95
94
|
else
|
96
95
|
super(source, options)
|
97
96
|
end
|
98
|
-
}.join("\n").html_safe
|
97
|
+
}.flatten.uniq.join("\n").html_safe
|
99
98
|
else
|
100
99
|
sources.push(options)
|
101
100
|
super(*sources)
|
@@ -117,7 +116,7 @@ module Sprockets
|
|
117
116
|
else
|
118
117
|
super(source, options)
|
119
118
|
end
|
120
|
-
}.join("\n").html_safe
|
119
|
+
}.flatten.uniq.join("\n").html_safe
|
121
120
|
else
|
122
121
|
sources.push(options)
|
123
122
|
super(*sources)
|
data/lib/sprockets/rails/task.rb
CHANGED
@@ -9,6 +9,13 @@ module Sprockets
|
|
9
9
|
|
10
10
|
def define
|
11
11
|
namespace :assets do
|
12
|
+
# Override this task change the loaded dependencies
|
13
|
+
desc "Load asset compile environment"
|
14
|
+
task :environment do
|
15
|
+
# Load full Rails environment by default
|
16
|
+
Rake::Task['environment'].invoke
|
17
|
+
end
|
18
|
+
|
12
19
|
desc "Compile all the assets named in config.assets.precompile"
|
13
20
|
task :precompile => :environment do
|
14
21
|
with_logger do
|
data/lib/sprockets/railtie.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'rails/railtie'
|
3
3
|
require 'action_controller/railtie'
|
4
|
+
require 'active_support/core_ext/module/remove_method'
|
4
5
|
require 'sprockets'
|
5
6
|
require 'sprockets/rails/helper'
|
6
7
|
|
@@ -9,46 +10,29 @@ module Rails
|
|
9
10
|
# Hack: We need to remove Rails' built in config.assets so we can
|
10
11
|
# do our own thing.
|
11
12
|
class Configuration
|
12
|
-
|
13
|
-
undef_method :assets
|
14
|
-
end
|
13
|
+
remove_possible_method :assets
|
15
14
|
end
|
16
15
|
|
16
|
+
# Undefine Rails' assets method before redefining it, to avoid warnings.
|
17
|
+
remove_possible_method :assets
|
18
|
+
remove_possible_method :assets=
|
19
|
+
|
17
20
|
# Returns Sprockets::Environment for app config.
|
18
21
|
def assets
|
19
22
|
return @assets if defined? @assets
|
20
23
|
|
21
24
|
@assets = Sprockets::Environment.new(root.to_s) do |env|
|
22
|
-
env.version = ::Rails.env
|
25
|
+
env.version = ::Rails.env
|
23
26
|
|
24
27
|
path = "#{config.root}/tmp/cache/assets/#{::Rails.env}"
|
25
28
|
env.cache = Sprockets::Cache::FileStore.new(path)
|
26
29
|
|
27
|
-
config.assets.paths.each do |path|
|
28
|
-
env.append_path(path)
|
29
|
-
end
|
30
|
-
|
31
|
-
env.js_compressor = config.assets.js_compressor
|
32
|
-
env.css_compressor = config.assets.css_compressor
|
33
|
-
|
34
30
|
env.context_class.class_eval do
|
35
31
|
include ::Sprockets::Rails::Helper
|
36
32
|
end
|
37
|
-
env.context_class.assets_prefix = config.assets.prefix
|
38
|
-
env.context_class.digest_assets = config.assets.digest
|
39
|
-
env.context_class.config = config.action_controller
|
40
|
-
|
41
|
-
config.assets._blocks.each do |block|
|
42
|
-
block.call env
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
if config.cache_classes
|
47
|
-
@assets = @assets.index
|
48
33
|
end
|
49
|
-
|
50
|
-
@assets
|
51
34
|
end
|
35
|
+
attr_writer :assets
|
52
36
|
end
|
53
37
|
end
|
54
38
|
|
@@ -69,7 +53,7 @@ module Sprockets
|
|
69
53
|
config.assets.paths = []
|
70
54
|
config.assets.prefix = "/assets"
|
71
55
|
config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
|
72
|
-
config.assets.version =
|
56
|
+
config.assets.version = ""
|
73
57
|
config.assets.debug = false
|
74
58
|
config.assets.compile = true
|
75
59
|
config.assets.digest = false
|
@@ -86,16 +70,34 @@ module Sprockets
|
|
86
70
|
end
|
87
71
|
|
88
72
|
config.after_initialize do |app|
|
89
|
-
|
73
|
+
config = app.config
|
74
|
+
|
75
|
+
manifest_path = File.join(app.root, 'public', config.assets.prefix)
|
76
|
+
|
77
|
+
unless config.assets.version.blank?
|
78
|
+
app.assets.version += "-#{config.assets.version}"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Copy config.assets.paths to Sprockets
|
82
|
+
config.assets.paths.each do |path|
|
83
|
+
app.assets.append_path path
|
84
|
+
end
|
90
85
|
|
91
86
|
ActiveSupport.on_load(:action_view) do
|
92
87
|
include Sprockets::Rails::Helper
|
93
88
|
|
94
|
-
|
95
|
-
self.
|
96
|
-
self.
|
89
|
+
# Copy relevant config to AV context
|
90
|
+
self.debug_assets = config.assets.debug
|
91
|
+
self.digest_assets = config.assets.digest
|
92
|
+
self.assets_prefix = config.assets.prefix
|
93
|
+
|
94
|
+
# Copy over to Sprockets as well
|
95
|
+
context = app.assets.context_class
|
96
|
+
context.assets_prefix = config.assets.prefix
|
97
|
+
context.digest_assets = config.assets.digest
|
98
|
+
context.config = config.action_controller
|
97
99
|
|
98
|
-
if
|
100
|
+
if config.assets.compile
|
99
101
|
self.assets_environment = app.assets
|
100
102
|
self.assets_manifest = Sprockets::Manifest.new(app.assets, manifest_path)
|
101
103
|
else
|
@@ -103,10 +105,26 @@ module Sprockets
|
|
103
105
|
end
|
104
106
|
end
|
105
107
|
|
106
|
-
|
108
|
+
app.assets.js_compressor = config.assets.js_compressor
|
109
|
+
app.assets.css_compressor = config.assets.css_compressor
|
110
|
+
|
111
|
+
# Run app.assets.configure blocks
|
112
|
+
config.assets._blocks.each do |block|
|
113
|
+
block.call app.assets
|
114
|
+
end
|
115
|
+
|
116
|
+
# No more configuration changes at this point.
|
117
|
+
# With cache classes on, Sprockets won't check the FS when files
|
118
|
+
# change. Preferable in production when the FS only changes on
|
119
|
+
# deploys when the app restarts.
|
120
|
+
if config.cache_classes
|
121
|
+
app.assets = app.assets.index
|
122
|
+
end
|
123
|
+
|
124
|
+
if config.assets.compile
|
107
125
|
if app.routes.respond_to?(:prepend)
|
108
126
|
app.routes.prepend do
|
109
|
-
mount app.assets =>
|
127
|
+
mount app.assets => config.assets.prefix
|
110
128
|
end
|
111
129
|
end
|
112
130
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
@@ -88,7 +88,7 @@ files:
|
|
88
88
|
- lib/sprockets/rails/task.rb
|
89
89
|
- lib/sprockets/rails.rb
|
90
90
|
- lib/sprockets/railtie.rb
|
91
|
-
homepage: https://github.com/
|
91
|
+
homepage: https://github.com/rails/sprockets-rails
|
92
92
|
licenses: []
|
93
93
|
post_install_message:
|
94
94
|
rdoc_options: []
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: 1.3.1
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 1.8.
|
111
|
+
rubygems_version: 1.8.23
|
112
112
|
signing_key:
|
113
113
|
specification_version: 3
|
114
114
|
summary: Sprockets Rails integration
|