This repository has been archived by the owner on Jun 10, 2018. It is now read-only.
forked from rails/sprockets
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move fingerprint utils out of Pathname
- Loading branch information
Showing
9 changed files
with
41 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'pathname' | ||
|
||
module Sprockets | ||
# TODO: Junk drawer | ||
module Utils | ||
def path_fingerprint(path) | ||
pathname = Pathname.new(path) | ||
extensions = pathname.basename.to_s.scan(/\.[^.]+/).join | ||
pathname.basename(extensions).to_s =~ /-([0-9a-f]{7,40})$/ ? $1 : nil | ||
end | ||
module_function :path_fingerprint | ||
|
||
def path_with_fingerprint(path, digest) | ||
pathname = Pathname.new(path) | ||
extensions = pathname.basename.to_s.scan(/\.[^.]+/).join | ||
|
||
if pathname.basename(extensions).to_s =~ /-([0-9a-f]{7,40})$/ | ||
path.sub($1, digest) | ||
else | ||
basename = "#{pathname.basename(extensions)}-#{digest}#{extensions}" | ||
pathname.dirname.to_s == '.' ? basename : pathname.dirname.join(basename).to_s | ||
end | ||
end | ||
module_function :path_with_fingerprint | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters