sprockets-rails 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79800fc588c2c61e6edab3f2eba4a305753f3d1d
4
- data.tar.gz: 38604ce2a233554c6c5562b9640468d0235d8dba
3
+ metadata.gz: f7cda4acb26f13dcaf19f3e20a80a993ce94a51d
4
+ data.tar.gz: 13edbe84e222532d684dd604c704b924ec112dd6
5
5
  SHA512:
6
- metadata.gz: d74ea9be777f07327e05acf7031245bd913d35b1b99afa287196170809e48b79fac6961289ec8cb39243285a74759ddb5b3d0b0c1c3a9fb73c2b0efdb71a07a2
7
- data.tar.gz: 695ebd483f3e8e8a87eb58cf0d429442223090e688a3ca2d66ce16b74fc6310e07cb42b52f44b8b5e1895d88f8e03a0383e0043ebad972a6754a70469954da77
6
+ metadata.gz: 4469943e88ac45ffa9063b0bfa5db8c8875029b9d72a9482b5dbd5b0a9eca6659ea3c295bc5c5835ec698c8586641889d7876c30b882c189eef868590a9b786c
7
+ data.tar.gz: afe0a6f3db89ab3a79b0d2f5f1163ae96a61023b0297c9239d63cd14be6d2b882bc05d1e9908aaa5cea6b3949b1945502d10750e5ccaae60a1ddc21df98c23c2
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Joshua Peek
1
+ Copyright (c) 2012-2014 Joshua Peek
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -37,7 +37,12 @@ You can also redefine the task with the built in task generator.
37
37
 
38
38
  ``` ruby
39
39
  require 'sprockets/rails/task'
40
- Sprockets::Rails::Task.new do |t|
40
+ # clean the old tasks
41
+ Rake::Task["assets:environment"].clear
42
+ Rake::Task["assets:precompile"].clear
43
+ Rake::Task["assets:clean"].clear
44
+ Rake::Task["assets:clobber"].clear
45
+ Sprockets::Rails::Task.new(Rails.application) do |t|
41
46
  t.environment = lambda { Rails.application.assets }
42
47
  t.assets = %w( application.js application.css )
43
48
  t.keep = 5
@@ -55,9 +60,14 @@ Also see [Sprockets::Rails::Task](https://github.com/josh/sprockets-rails/blob/m
55
60
 
56
61
  Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`.
57
62
 
63
+ **`config.assets.raise_runtime_errors`**
64
+
65
+ Set to `true` to enable additional runtime error checking. Recommended in the `development` environment to minimize unexpected behavior when deploying to `production`.
66
+
58
67
  **`config.assets.paths`**
59
68
 
60
- Add additional load paths to this Array. Rails includes `app/assets` and `vendor/assets` for you already. Plugins might want to add their custom paths to to this.
69
+ Add additional load paths to this Array. Rails includes `app/assets`, `lib/assets` and `vendor/assets` for you already. Plugins might want to add their custom paths to this.
70
+
61
71
 
62
72
  **`config.assets.version`**
63
73
 
@@ -73,6 +83,10 @@ config.assets.version = 'v2'
73
83
 
74
84
  Defaults to `/assets`. Changes the directory to compile assets to.
75
85
 
86
+ **`config.assets.manifest`**
87
+
88
+ Defines the full path to be used for the asset precompiler's manifest file. Defaults to using the `config.assets.prefix` directory within the public folder.
89
+
76
90
  **`config.assets.digest`**
77
91
 
78
92
  Link to undigest asset filenames. This option will eventually go away. Unless when `compile` is disabled.
@@ -5,6 +5,39 @@ require 'active_support/core_ext/class/attribute'
5
5
  module Sprockets
6
6
  module Rails
7
7
  module Helper
8
+ class << self
9
+ attr_accessor :precompile, :assets, :raise_runtime_errors
10
+ end
11
+
12
+ def precompile
13
+ Sprockets::Rails::Helper.precompile
14
+ end
15
+
16
+ def assets
17
+ Sprockets::Rails::Helper.assets
18
+ end
19
+
20
+ def raise_runtime_errors
21
+ Sprockets::Rails::Helper.raise_runtime_errors
22
+ end
23
+
24
+ class DependencyError < StandardError
25
+ def initialize(path, dep)
26
+ msg = "Asset depends on '#{dep}' to generate properly but has not declared the dependency\n"
27
+ msg << "Please add: `//= depend_on_asset \"#{dep}\"` to '#{path}'"
28
+ super msg
29
+ end
30
+ end
31
+
32
+ class AssetFilteredError < StandardError
33
+ def initialize(source)
34
+ msg = "Asset filtered out and will not be served: " <<
35
+ "add `config.assets.precompile += %w( #{source} )` " <<
36
+ "to `config/application.rb` and restart your server"
37
+ super(msg)
38
+ end
39
+ end
40
+
8
41
  if defined? ActionView::Helpers::AssetUrlHelper
9
42
  include ActionView::Helpers::AssetUrlHelper
10
43
  include ActionView::Helpers::AssetTagHelper
@@ -37,6 +70,9 @@ module Sprockets
37
70
  end
38
71
 
39
72
  def compute_asset_path(path, options = {})
73
+ # Check if we are inside Sprockets context before calling check_dependencies!.
74
+ check_dependencies!(path) if defined?(_dependency_assets)
75
+
40
76
  if digest_path = asset_digest_path(path)
41
77
  path = digest_path if digest_assets
42
78
  path += "?body=1" if options[:debug]
@@ -46,6 +82,21 @@ module Sprockets
46
82
  end
47
83
  end
48
84
 
85
+ # Computes the full URL to a asset in the public directory. This
86
+ # method checks for errors before returning path.
87
+ def asset_path(source, options = {})
88
+ check_errors_for(source)
89
+ path_to_asset(source, options)
90
+ end
91
+ alias :path_to_asset_with_errors :asset_path
92
+
93
+ # Computes the full URL to a asset in the public directory. This
94
+ # will use +asset_path+ internally, so most of their behaviors
95
+ # will be the same.
96
+ def asset_url(source, options = {})
97
+ path_to_asset_with_errors(source, options.merge(:protocol => :request))
98
+ end
99
+
49
100
  # Get digest for asset path.
50
101
  #
51
102
  # path - String path
@@ -88,6 +139,7 @@ module Sprockets
88
139
 
89
140
  if options["debug"] != false && request_debug_assets?
90
141
  sources.map { |source|
142
+ check_errors_for(source)
91
143
  if asset = lookup_asset_for_path(source, :type => :javascript)
92
144
  asset.to_a.map do |a|
93
145
  super(path_to_javascript(a.logical_path, :debug => true), options)
@@ -107,9 +159,9 @@ module Sprockets
107
159
  # Eventually will be deprecated and replaced by source maps.
108
160
  def stylesheet_link_tag(*sources)
109
161
  options = sources.extract_options!.stringify_keys
110
-
111
162
  if options["debug"] != false && request_debug_assets?
112
163
  sources.map { |source|
164
+ check_errors_for(source)
113
165
  if asset = lookup_asset_for_path(source, :type => :stylesheet)
114
166
  asset.to_a.map do |a|
115
167
  super(path_to_stylesheet(a.logical_path, :debug => true), options)
@@ -125,6 +177,33 @@ module Sprockets
125
177
  end
126
178
 
127
179
  protected
180
+ # Checks if the asset is included in the dependencies list.
181
+ def check_dependencies!(dep)
182
+ if raise_runtime_errors && !_dependency_assets.detect { |asset| asset.include?(dep) }
183
+ raise DependencyError.new(self.pathname, dep)
184
+ end
185
+ end
186
+
187
+ # Raise errors when source does not exist or is not in the precompiled list
188
+ def check_errors_for(source)
189
+ source = source.to_s
190
+ return source if !self.raise_runtime_errors || source.blank? || source =~ URI_REGEXP
191
+ asset = lookup_asset_for_path(source)
192
+
193
+ if asset && asset_needs_precompile?(source, asset.pathname.to_s)
194
+ raise AssetFilteredError.new(source)
195
+ end
196
+ end
197
+
198
+ # Returns true when an asset will not be available after precompile is run
199
+ def asset_needs_precompile?(source, filename)
200
+ if assets_environment && assets_environment.send(:matches_filter, precompile || [], source, filename)
201
+ false
202
+ else
203
+ true
204
+ end
205
+ end
206
+
128
207
  # Enable split asset debugging. Eventually will be deprecated
129
208
  # and replaced by source maps in Sprockets 3.x.
130
209
  def request_debug_assets?
@@ -21,8 +21,7 @@ module Sprockets
21
21
  source = compute_asset_path(source, options)
22
22
  end
23
23
 
24
- relative_url_root = (defined?(config.relative_url_root) && config.relative_url_root) ||
25
- (respond_to?(:request) && request.try(:script_name))
24
+ relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
26
25
  if relative_url_root
27
26
  source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
28
27
  end
@@ -1,6 +1,7 @@
1
1
  require 'rake'
2
2
  require 'rake/sprocketstask'
3
3
  require 'sprockets'
4
+ require 'action_view/base'
4
5
 
5
6
  module Sprockets
6
7
  module Rails
@@ -50,6 +50,7 @@ module Sprockets
50
50
  config.assets._blocks = []
51
51
  config.assets.paths = []
52
52
  config.assets.prefix = "/assets"
53
+ config.assets.manifest = nil
53
54
  config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
54
55
  config.assets.version = ""
55
56
  config.assets.debug = false
@@ -64,10 +65,18 @@ module Sprockets
64
65
  config.after_initialize do |app|
65
66
  config = app.config
66
67
 
67
- manifest_path = File.join(app.root, 'public', config.assets.prefix)
68
+ manifest_path = config.assets.manifest || File.join(config.paths['public'].first, config.assets.prefix)
68
69
 
69
- unless config.assets.version.blank?
70
- app.assets.version += "-#{config.assets.version}"
70
+ # Configuration options that should invalidate
71
+ # the Sprockets cache when changed.
72
+ version_fragments = [
73
+ config.assets.version,
74
+ config.action_controller.relative_url_root,
75
+ config.action_controller.asset_host
76
+ ].compact.join('-')
77
+
78
+ if version_fragments.present?
79
+ app.assets.version += "-#{version_fragments}"
71
80
  end
72
81
 
73
82
  # Copy config.assets.paths to Sprockets
@@ -75,7 +84,7 @@ module Sprockets
75
84
  app.assets.append_path path
76
85
  end
77
86
 
78
- ActionView::Base.instance_eval do
87
+ ActiveSupport.on_load(:action_view) do
79
88
  include Sprockets::Rails::Helper
80
89
 
81
90
  # Copy relevant config to AV context
@@ -113,6 +122,11 @@ module Sprockets
113
122
  app.assets = app.assets.index
114
123
  end
115
124
 
125
+
126
+ Sprockets::Rails::Helper.precompile ||= app.config.assets.precompile
127
+ Sprockets::Rails::Helper.assets ||= app.assets
128
+ Sprockets::Rails::Helper.raise_runtime_errors = app.config.assets.raise_runtime_errors
129
+
116
130
  if config.assets.compile
117
131
  if app.routes.respond_to?(:prepend)
118
132
  app.routes.prepend do
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Peek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-16 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '4.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '4.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description:
@@ -72,14 +72,14 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
+ - LICENSE
75
76
  - README.md
77
+ - lib/sprockets/rails.rb
76
78
  - lib/sprockets/rails/helper.rb
77
79
  - lib/sprockets/rails/legacy_asset_tag_helper.rb
78
80
  - lib/sprockets/rails/legacy_asset_url_helper.rb
79
81
  - lib/sprockets/rails/task.rb
80
- - lib/sprockets/rails.rb
81
82
  - lib/sprockets/railtie.rb
82
- - LICENSE
83
83
  homepage: https://github.com/rails/sprockets-rails
84
84
  licenses:
85
85
  - MIT
@@ -90,17 +90,17 @@ require_paths:
90
90
  - lib
91
91
  required_ruby_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - '>='
98
+ - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.0.6
103
+ rubygems_version: 2.2.2
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Sprockets Rails integration