fingerprintless-assets 1.0.pre → 1.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,9 +27,9 @@ Rails plugins can require this gem and set these options in an initializer, maki
27
27
  The Problem With Fingerprinting
28
28
  -------------------------------
29
29
 
30
- Fingerprinting is used to improve caching of assets by including a version-specific fingerprint in the asset filename. From the [Asset Pipeline Rails Guide](http://ryanbigg.com/guides/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care):
30
+ Fingerprinting is used to improve caching of assets by including a version-specific fingerprint in the asset filename. From the [Asset Pipeline Rails Guide](http://edgeguides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care):
31
31
 
32
- > When a filename is unique and based on its content, http headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep there own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as cachebusting.
32
+ > When a filename is unique and based on its content, HTTP headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep their own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as cachebusting.
33
33
 
34
34
  In the Rails asset pipeline (in production mode), the MD5 hash of the file contents is inserted into the filename, e.g. `application-d41d8cd98f00b204e9800998ecf8427e.js`. This requires that the relevant `asset_url` helpers are used when referencing assets in your HTML, JavaScript or CSS (or CoffeeScript, SASS, etc).
35
35
 
@@ -2,10 +2,8 @@ require "sprockets"
2
2
  require 'sprockets/base'
3
3
 
4
4
  require "fingerprintless_assets/monkey_patches/configuration"
5
+ require "fingerprintless_assets/monkey_patches/asset"
5
6
  require "fingerprintless_assets/monkey_patches/environment"
6
7
  require "fingerprintless_assets/monkey_patches/index"
7
- require "fingerprintless_assets/monkey_patches/server"
8
- require "fingerprintless_assets/monkey_patches/static_compilation"
9
- require "fingerprintless_assets/monkey_patches/utils"
10
8
 
11
9
  require "fingerprintless_assets/railtie" if defined?(Rails)
@@ -0,0 +1,13 @@
1
+ Sprockets::Asset.class_eval do
2
+ alias_method :original_digest_path, :digest_path
3
+
4
+ # If fingerprinting is enabled for this asset, return the logical path
5
+ # with digest spliced in. Otherwise return the logical path only.
6
+ def digest_path
7
+ if environment.fingerprint_path?(logical_path)
8
+ original_digest_path
9
+ else
10
+ logical_path
11
+ end
12
+ end
13
+ end
@@ -32,6 +32,16 @@ module FingerprintlessAssets
32
32
  def exclude_path_from_fingerprinting?(logical_path)
33
33
  fingerprinting_exclusions.any? { |path| match_path?(logical_path, path) }
34
34
  end
35
+
36
+ def match_path?(path, match)
37
+ if match.is_a?(Regexp)
38
+ # Match path against `Regexp`
39
+ match.match(path)
40
+ else
41
+ # Otherwise use fnmatch glob syntax
42
+ File.fnmatch(match.to_s, path)
43
+ end
44
+ end
35
45
  end
36
46
  end
37
47
 
@@ -1,3 +1,5 @@
1
+ require 'sprockets/railtie'
2
+
1
3
  module FingerprintlessAssets
2
4
  class Railtie < ::Rails::Railtie
3
5
  initializer :setup_configuration, :before => :load_environment_config do |app|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fingerprintless-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.pre
4
+ version: 1.0.pre2
5
5
  prerelease: 4
6
6
  platform: ruby
7
7
  authors:
@@ -9,20 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-03 00:00:00.000000000 +09:30
13
- default_executable:
12
+ date: 2011-08-29 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: sprockets
17
- requirement: &2153060000 !ruby/object:Gem::Requirement
16
+ requirement: &70250046326420 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
21
20
  - !ruby/object:Gem::Version
22
- version: 2.0.0.beta.12
21
+ version: 2.0.0.beta.15
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2153060000
24
+ version_requirements: *70250046326420
26
25
  description: Adds asset fingerprinting configuration options to Rails and Sprockets
27
26
  so that paths can be excluded from fingerprinting.
28
27
  email: sam@sampohlenz.com
@@ -32,14 +31,11 @@ extra_rdoc_files: []
32
31
  files:
33
32
  - README.md
34
33
  - lib/fingerprintless-assets.rb
34
+ - lib/fingerprintless_assets/monkey_patches/asset.rb
35
35
  - lib/fingerprintless_assets/monkey_patches/configuration.rb
36
36
  - lib/fingerprintless_assets/monkey_patches/environment.rb
37
37
  - lib/fingerprintless_assets/monkey_patches/index.rb
38
- - lib/fingerprintless_assets/monkey_patches/server.rb
39
- - lib/fingerprintless_assets/monkey_patches/static_compilation.rb
40
- - lib/fingerprintless_assets/monkey_patches/utils.rb
41
38
  - lib/fingerprintless_assets/railtie.rb
42
- has_rdoc: true
43
39
  homepage:
44
40
  licenses: []
45
41
  post_install_message:
@@ -60,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
56
  version: 1.3.1
61
57
  requirements: []
62
58
  rubyforge_project:
63
- rubygems_version: 1.6.2
59
+ rubygems_version: 1.8.6
64
60
  signing_key:
65
61
  specification_version: 3
66
62
  summary: Fingerprinting controls for the Rails 3.1 asset pipeline.
@@ -1,9 +0,0 @@
1
- module FingerprintlessAssets
2
- module Server
3
- def path(logical_path, _ignored_fingerprint = true, prefix = nil)
4
- super(logical_path, fingerprint_path?(logical_path), prefix)
5
- end
6
- end
7
- end
8
-
9
- Sprockets::Base.send(:include, FingerprintlessAssets::Server)
@@ -1,38 +0,0 @@
1
- module FingerprintlessAssets
2
- module StaticCompilation
3
- def precompile(*paths)
4
- raise "missing static root" unless static_root
5
-
6
- paths.each do |path|
7
- files.each do |logical_path|
8
- next unless match_path?(logical_path, path)
9
-
10
- if asset = find_asset(logical_path)
11
- precompile_asset(asset)
12
- end
13
- end
14
- end
15
- end
16
-
17
- def precompile_asset(asset)
18
- if fingerprint_path?(asset.logical_path)
19
- attributes = attributes_for(asset.logical_path)
20
- digest_path = attributes.path_with_fingerprint(asset.digest)
21
- filename = static_root.join(digest_path)
22
- else
23
- filename = static_root.join(asset.logical_path)
24
- end
25
-
26
- # Ensure directory exists
27
- FileUtils.mkdir_p filename.dirname
28
-
29
- # Write file
30
- asset.write_to(filename)
31
-
32
- # Write compressed file if its a bundled asset like .js or .css
33
- asset.write_to("#{filename}.gz") if asset.is_a?(Sprockets::BundledAsset)
34
- end
35
- end
36
- end
37
-
38
- Sprockets::Base.send(:include, FingerprintlessAssets::StaticCompilation)
@@ -1,15 +0,0 @@
1
- module FingerprintlessAssets
2
- module Utils
3
- def match_path?(path, match)
4
- if match.is_a?(Regexp)
5
- # Match path against `Regexp`
6
- match.match(path)
7
- else
8
- # Otherwise use fnmatch glob syntax
9
- File.fnmatch(match.to_s, path)
10
- end
11
- end
12
- end
13
- end
14
-
15
- Sprockets::Base.send(:include, FingerprintlessAssets::Utils)