sprockets-rails 2.3.3 → 3.0.0.beta1

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: ce070066edd25fc773120801099deaa44cbab0a8
4
- data.tar.gz: 0ae39779bf56111b665205168d7b4daebd47ea94
3
+ metadata.gz: a7e8197def5c64d991abb7e4c18f4d8a4f0cc6ae
4
+ data.tar.gz: 5f50d295b072faf5d82391d0758b9582be53b3cc
5
5
  SHA512:
6
- metadata.gz: 4032a379c2a1d87b5d28e2be7119c628aaf36814fc0d34c717068fc91b59b69af7ed979107f0c47d37aad0c42e485ade12b688cd8ea562ca2bfbdceb5daa75c4
7
- data.tar.gz: b32fc1c142d819cf55b734fda999b7a55f88d1ce7a164f6417ff6839f3acb15fe00a38004b6507dc867e50ffabcb186ca4e73e80f53be6b5f61068c2a2e3987c
6
+ metadata.gz: 1ec86dc53e523a016d690cb201fe53e7b13d3c37144025059efbbedb311bd54b2c234ae4d159e9b76f600888b772038e0524f2288705ec83b08ede2896f665fa
7
+ data.tar.gz: ce22650daae7b6bfd3ecf93498c08bb064b4c01cb6b770a83acff558e654baf202af8cb8721242f73255a9d7a312eebed669f19d818ff5370e906a75be8bed14
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 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
@@ -89,7 +89,9 @@ Defines the full path to be used for the asset precompiler's manifest file. Defa
89
89
 
90
90
  **`config.assets.digest`**
91
91
 
92
- Link to undigest asset filenames. This option will eventually go away. Unless when `compile` is disabled.
92
+ When enabled, fingerprints will be added to asset filenames.
93
+ If `config.assets.raise_runtime_errors` is also enabled, requests for assets
94
+ will raise an error unless they contain fingerprints.
93
95
 
94
96
  **`config.assets.debug`**
95
97
 
@@ -105,7 +107,7 @@ Invokes block with environment when the environment is initialized. Allows direc
105
107
 
106
108
  ``` ruby
107
109
  config.assets.configure do |env|
108
- env.js_compressor = :uglify # or :closure, :yui
110
+ env.js_compressor = :uglifier # or :closure, :yui
109
111
  env.css_compressor = :sass # or :yui
110
112
 
111
113
  require 'my_processor'
@@ -132,7 +134,7 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
132
134
 
133
135
  * Only compiles digest filenames. Static non-digest assets should simply live in public/.
134
136
  * Unmanaged asset paths and urls fallback to linking to public/. This should make it easier to work with both compiled assets and simple static assets. As a side effect, there will never be any "asset not precompiled errors" when linking to missing assets. They will just link to a public file which may or may not exist.
135
- * JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign `config.assets.js_compressor = :uglify` or `config.assets.css_compressor = :sass` for the standard compressors.
137
+ * JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign `config.assets.js_compressor = :uglifier` or `config.assets.css_compressor = :sass` for the standard compressors.
136
138
  * The manifest file is now in a JSON format. Since it lives in public/ by default, the initial filename is also randomized to obfuscate public access to the resource.
137
139
  * `config.assets.manifest` (if used) must now include the manifest filename, e.g. `Rails.root.join('config/manifest.json')`. It cannot be a directory.
138
140
  * Two cleanup tasks. `rake assets:clean` is now a safe cleanup that only removes older assets that are no longer used. While `rake assets:clobber` nukes the entire `public/assets` directory and clears your filesystem cache. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
@@ -149,22 +151,22 @@ $ bundle install
149
151
  $ bundle exec rake test
150
152
  ```
151
153
 
152
- [![Build Status](https://secure.travis-ci.org/rails/sprockets-rails.png)](http://travis-ci.org/rails/sprockets-rails)
154
+ [![Build Status](https://travis-ci.org/rails/sprockets-rails.svg?branch=master)](https://travis-ci.org/rails/sprockets-rails)
153
155
 
154
156
 
155
157
  ## Releases
156
158
 
157
- sprockets-rails 2.x will primarily target sprockets 2.x with future compatibility for 3.x. Consider upgrading to sprockets-rails 3.x to take full advantage of 3.x features.
159
+ sprockets-rails 2.x will primarily target sprockets 2.x. And future versions will target the corresponding sprockets release line.
158
160
 
159
161
  The minor and patch version will be updated according to [semver](http://semver.org/).
160
162
 
161
163
  * Any new APIs or config options that don't break compatibility will be in a minor release
162
- * Any time the sprockets dependency is bumped, there will be a new minor release
164
+ * Any time the sprockets depedency is bumped, there will be a new minor release
163
165
  * Simple bug fixes will be patch releases
164
166
 
165
167
 
166
168
  ## License
167
169
 
168
- Copyright © 2014 Joshua Peek.
170
+ Copyright © 2012 Joshua Peek.
169
171
 
170
172
  Released under the MIT license. See `LICENSE` for details.
@@ -0,0 +1,39 @@
1
+ require 'sprockets'
2
+ require 'sprockets/rails/helper'
3
+
4
+ module Sprockets
5
+ module Rails
6
+ class Environment < Sprockets::Environment
7
+ class NoDigestError < StandardError
8
+ def initialize(asset)
9
+ msg = "Assets should not be requested directly without their digests: " <<
10
+ "Use the helpers in ActionView::Helpers to request #{asset}"
11
+ super(msg)
12
+ end
13
+ end
14
+
15
+ def call(env)
16
+ if Sprockets::Rails::Helper.raise_runtime_errors && context_class.digest_assets
17
+ path = unescape(env['PATH_INFO'].to_s.sub(/^\//, ''))
18
+
19
+ if fingerprint = path_fingerprint(path)
20
+ path = path.sub("-#{fingerprint}", '')
21
+ else
22
+ raise NoDigestError.new(path)
23
+ end
24
+
25
+ asset = find_asset(path)
26
+ if asset && asset.digest != fingerprint
27
+ asset_path = File.join(context_class.assets_prefix || "/", asset.digest_path)
28
+ asset_path += '?' + env['QUERY_STRING'] if env['QUERY_STRING']
29
+ [302, {"Location" => asset_path}, []]
30
+ else
31
+ super(env)
32
+ end
33
+ else
34
+ super(env)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -38,15 +38,8 @@ module Sprockets
38
38
  end
39
39
  end
40
40
 
41
- if defined? ActionView::Helpers::AssetUrlHelper
42
- include ActionView::Helpers::AssetUrlHelper
43
- include ActionView::Helpers::AssetTagHelper
44
- else
45
- require 'sprockets/rails/legacy_asset_tag_helper'
46
- require 'sprockets/rails/legacy_asset_url_helper'
47
- include LegacyAssetTagHelper
48
- include LegacyAssetUrlHelper
49
- end
41
+ include ActionView::Helpers::AssetUrlHelper
42
+ include ActionView::Helpers::AssetTagHelper
50
43
 
51
44
  VIEW_ACCESSORS = [:assets_environment, :assets_manifest,
52
45
  :assets_prefix, :digest_assets, :debug_assets]
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Rails
3
- VERSION = "2.3.3"
3
+ VERSION = "3.0.0.beta1"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require 'rails/railtie'
3
3
  require 'action_controller/railtie'
4
4
  require 'active_support/core_ext/module/remove_method'
5
5
  require 'sprockets'
6
+ require 'sprockets/rails/environment'
6
7
  require 'sprockets/rails/helper'
7
8
  require 'sprockets/rails/version'
8
9
 
@@ -18,9 +19,9 @@ module Rails
18
19
  remove_possible_method :assets
19
20
  remove_possible_method :assets=
20
21
 
21
- # Returns Sprockets::Environment for app config.
22
+ # Returns Sprockets::Rails::Environment for app config.
22
23
  def assets
23
- @assets ||= Sprockets::Environment.new(root.to_s) do |env|
24
+ @assets ||= Sprockets::Rails::Environment.new(root.to_s) do |env|
24
25
  env.version = ::Rails.env
25
26
 
26
27
  path = "#{config.root}/tmp/cache/assets/#{::Rails.env}"
@@ -32,26 +33,6 @@ module Rails
32
33
  end
33
34
  end
34
35
  attr_writer :assets
35
-
36
- # Returns Sprockets::Manifest for app config.
37
- attr_accessor :assets_manifest
38
- end
39
-
40
- class Engine < Railtie
41
- # Skip defining append_assets_path on Rails <= 4.2
42
- unless initializers.find { |init| init.name == :append_assets_path }
43
- initializer :append_assets_path, :group => :all do |app|
44
- if paths["app/assets"].respond_to?(:existent_directories)
45
- app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
46
- app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
47
- app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
48
- else
49
- app.config.assets.paths.unshift(*paths["vendor/assets"].paths.select { |d| File.directory?(d) })
50
- app.config.assets.paths.unshift(*paths["lib/assets"].paths.select { |d| File.directory?(d) })
51
- app.config.assets.paths.unshift(*paths["app/assets"].paths.select { |d| File.directory?(d) })
52
- end
53
- end
54
- end
55
36
  end
56
37
  end
57
38
 
@@ -86,6 +67,8 @@ module Sprockets
86
67
  config.after_initialize do |app|
87
68
  config = app.config
88
69
 
70
+ manifest_assets_path = File.join(config.paths['public'].first, config.assets.prefix)
71
+
89
72
  # Configuration options that should invalidate
90
73
  # the Sprockets cache when changed.
91
74
  app.assets.version = [
@@ -101,31 +84,6 @@ module Sprockets
101
84
  app.assets.append_path path
102
85
  end
103
86
 
104
- # Run app.assets.configure blocks
105
- config.assets._blocks.each do |block|
106
- block.call app.assets
107
- end
108
-
109
- # Set compressors after the configure blocks since they can
110
- # define new compressors and we only accept existent compressors.
111
- app.assets.js_compressor = config.assets.js_compressor
112
- app.assets.css_compressor = config.assets.css_compressor
113
-
114
- # No more configuration changes at this point.
115
- # With cache classes on, Sprockets won't check the FS when files
116
- # change. Preferable in production when the FS only changes on
117
- # deploys when the app restarts.
118
- if config.cache_classes
119
- app.assets = app.assets.index
120
- end
121
-
122
- manifest_assets_path = File.join(config.paths['public'].first, config.assets.prefix)
123
- if config.assets.compile
124
- app.assets_manifest = Sprockets::Manifest.new(app.assets, manifest_assets_path, config.assets.manifest)
125
- else
126
- app.assets_manifest = Sprockets::Manifest.new(manifest_assets_path, config.assets.manifest)
127
- end
128
-
129
87
  ActiveSupport.on_load(:action_view) do
130
88
  include Sprockets::Rails::Helper
131
89
 
@@ -140,19 +98,38 @@ module Sprockets
140
98
  context.digest_assets = config.assets.digest
141
99
  context.config = config.action_controller
142
100
 
143
- self.assets_environment = app.assets if config.assets.compile
144
- self.assets_manifest = app.assets_manifest
101
+ if config.assets.compile
102
+ self.assets_environment = app.assets
103
+ self.assets_manifest = Sprockets::Manifest.new(app.assets, manifest_assets_path, config.assets.manifest)
104
+ else
105
+ self.assets_manifest = Sprockets::Manifest.new(manifest_assets_path, config.assets.manifest)
106
+ end
107
+ end
108
+
109
+ app.assets.js_compressor = config.assets.js_compressor
110
+ app.assets.css_compressor = config.assets.css_compressor
111
+
112
+ # Run app.assets.configure blocks
113
+ config.assets._blocks.each do |block|
114
+ block.call app.assets
115
+ end
116
+
117
+ # No more configuration changes at this point.
118
+ # With cache classes on, Sprockets won't check the FS when files
119
+ # change. Preferable in production when the FS only changes on
120
+ # deploys when the app restarts.
121
+ if config.cache_classes
122
+ app.assets = app.assets.index
145
123
  end
146
124
 
125
+
147
126
  Sprockets::Rails::Helper.precompile ||= app.config.assets.precompile
148
127
  Sprockets::Rails::Helper.assets ||= app.assets
149
128
  Sprockets::Rails::Helper.raise_runtime_errors = app.config.assets.raise_runtime_errors
150
129
 
151
130
  if config.assets.compile
152
- if app.routes.respond_to?(:prepend)
153
- app.routes.prepend do
154
- mount app.assets => config.assets.prefix
155
- end
131
+ app.routes.prepend do
132
+ mount app.assets => config.assets.prefix
156
133
  end
157
134
  end
158
135
  end
metadata CHANGED
@@ -1,77 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 3.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Peek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2014-08-19 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
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '4.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '2.8'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '4.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: actionpack
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - ">="
38
32
  - !ruby/object:Gem::Version
39
- version: '3.0'
33
+ version: '4.0'
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: '3.0'
40
+ version: '4.0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: activesupport
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: '3.0'
47
+ version: '4.0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - ">="
59
53
  - !ruby/object:Gem::Version
60
- version: '3.0'
61
- - !ruby/object:Gem::Dependency
62
- name: railties
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '3.0'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '3.0'
54
+ version: '4.0'
75
55
  - !ruby/object:Gem::Dependency
76
56
  name: rake
77
57
  requirement: !ruby/object:Gem::Requirement
@@ -87,33 +67,19 @@ dependencies:
87
67
  - !ruby/object:Gem::Version
88
68
  version: '0'
89
69
  - !ruby/object:Gem::Dependency
90
- name: sass
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: '0'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- - !ruby/object:Gem::Dependency
104
- name: uglifier
70
+ name: railties
105
71
  requirement: !ruby/object:Gem::Requirement
106
72
  requirements:
107
73
  - - ">="
108
74
  - !ruby/object:Gem::Version
109
- version: '0'
75
+ version: '4.0'
110
76
  type: :development
111
77
  prerelease: false
112
78
  version_requirements: !ruby/object:Gem::Requirement
113
79
  requirements:
114
80
  - - ">="
115
81
  - !ruby/object:Gem::Version
116
- version: '0'
82
+ version: '4.0'
117
83
  description:
118
84
  email: josh@joshpeek.com
119
85
  executables: []
@@ -123,9 +89,8 @@ files:
123
89
  - LICENSE
124
90
  - README.md
125
91
  - lib/sprockets/rails.rb
92
+ - lib/sprockets/rails/environment.rb
126
93
  - lib/sprockets/rails/helper.rb
127
- - lib/sprockets/rails/legacy_asset_tag_helper.rb
128
- - lib/sprockets/rails/legacy_asset_url_helper.rb
129
94
  - lib/sprockets/rails/task.rb
130
95
  - lib/sprockets/rails/version.rb
131
96
  - lib/sprockets/railtie.rb
@@ -144,12 +109,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
109
  version: '0'
145
110
  required_rubygems_version: !ruby/object:Gem::Requirement
146
111
  requirements:
147
- - - ">="
112
+ - - ">"
148
113
  - !ruby/object:Gem::Version
149
- version: '0'
114
+ version: 1.3.1
150
115
  requirements: []
151
116
  rubyforge_project:
152
- rubygems_version: 2.4.7
117
+ rubygems_version: 2.3.0
153
118
  signing_key:
154
119
  specification_version: 4
155
120
  summary: Sprockets Rails integration
@@ -1,32 +0,0 @@
1
- require 'sprockets'
2
-
3
- module Sprockets
4
- module Rails
5
- # Backports of AssetTagHelper methods for Rails 2.x and 3.x.
6
- module LegacyAssetTagHelper
7
- include ActionView::Helpers::TagHelper
8
-
9
- def javascript_include_tag(*sources)
10
- options = sources.extract_options!.stringify_keys
11
- sources.uniq.map { |source|
12
- tag_options = {
13
- "src" => path_to_javascript(source)
14
- }.merge(options)
15
- content_tag(:script, "", tag_options)
16
- }.join("\n").html_safe
17
- end
18
-
19
- def stylesheet_link_tag(*sources)
20
- options = sources.extract_options!.stringify_keys
21
- sources.uniq.map { |source|
22
- tag_options = {
23
- "rel" => "stylesheet",
24
- "media" => "screen",
25
- "href" => path_to_stylesheet(source)
26
- }.merge(options)
27
- tag(:link, tag_options)
28
- }.join("\n").html_safe
29
- end
30
- end
31
- end
32
- end
@@ -1,133 +0,0 @@
1
- require 'sprockets'
2
-
3
- module Sprockets
4
- module Rails
5
- # Backports of AssetUrlHelper methods for Rails 2.x and 3.x.
6
- module LegacyAssetUrlHelper
7
- URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}
8
-
9
- def asset_path(source, options = {})
10
- source = source.to_s
11
- return "" unless source.present?
12
- return source if source =~ URI_REGEXP
13
-
14
- tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, '')
15
-
16
- if extname = compute_asset_extname(source, options)
17
- source = "#{source}#{extname}"
18
- end
19
-
20
- if source[0] != ?/
21
- source = compute_asset_path(source, options)
22
- end
23
-
24
- relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
25
- if relative_url_root
26
- source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
27
- end
28
-
29
- if host = compute_asset_host(source, options)
30
- source = "#{host}#{source}"
31
- end
32
-
33
- "#{source}#{tail}"
34
- end
35
- alias_method :path_to_asset, :asset_path
36
-
37
- def asset_url(source, options = {})
38
- path_to_asset(source, options.merge(:protocol => :request))
39
- end
40
-
41
- ASSET_EXTENSIONS = {
42
- :javascript => '.js',
43
- :stylesheet => '.css'
44
- }
45
-
46
- def compute_asset_extname(source, options = {})
47
- return if options[:extname] == false
48
- extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
49
- extname if extname && File.extname(source) != extname
50
- end
51
-
52
- ASSET_PUBLIC_DIRECTORIES = {
53
- :audio => '/audios',
54
- :font => '/fonts',
55
- :image => '/images',
56
- :javascript => '/javascripts',
57
- :stylesheet => '/stylesheets',
58
- :video => '/videos'
59
- }
60
-
61
- def compute_asset_path(source, options = {})
62
- dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
63
- File.join(dir, source)
64
- end
65
-
66
- def compute_asset_host(source = "", options = {})
67
- request = self.request if respond_to?(:request)
68
-
69
- if defined? config
70
- host = config.asset_host
71
- elsif defined? ActionController::Base.asset_host
72
- host = ActionController::Base.asset_host
73
- end
74
-
75
- host ||= request.base_url if request && options[:protocol] == :request
76
- return unless host
77
-
78
- if host.respond_to?(:call)
79
- arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
80
- args = [source]
81
- args << request if request && (arity > 1 || arity < 0)
82
- host = host.call(*args)
83
- elsif host =~ /%d/
84
- host = host % (Zlib.crc32(source) % 4)
85
- end
86
-
87
- if host =~ URI_REGEXP
88
- host
89
- else
90
- protocol = options[:protocol] || (request ? :request : :relative)
91
- case protocol
92
- when :relative
93
- "//#{host}"
94
- when :request
95
- "#{request.protocol}#{host}"
96
- else
97
- "#{protocol}://#{host}"
98
- end
99
- end
100
- end
101
-
102
- def javascript_path(source, options = {})
103
- path_to_asset(source, {:type => :javascript}.merge(options))
104
- end
105
- alias_method :path_to_javascript, :javascript_path
106
-
107
- def stylesheet_path(source, options = {})
108
- path_to_asset(source, {:type => :stylesheet}.merge(options))
109
- end
110
- alias_method :path_to_stylesheet, :stylesheet_path
111
-
112
- def image_path(source, options = {})
113
- path_to_asset(source, {:type => :image}.merge(options))
114
- end
115
- alias_method :path_to_image, :image_path
116
-
117
- def video_path(source, options = {})
118
- path_to_asset(source, {:type => :video}.merge(options))
119
- end
120
- alias_method :path_to_video, :video_path
121
-
122
- def audio_path(source, options = {})
123
- path_to_asset(source, {:type => :audio}.merge(options))
124
- end
125
- alias_method :path_to_audio, :audio_path
126
-
127
- def font_path(source, options = {})
128
- path_to_asset(source, {:type => :font}.merge(options))
129
- end
130
- alias_method :path_to_font, :font_path
131
- end
132
- end
133
- end