Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suffix/postfix naming #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ Default value: `'md5'`
Type: `Number`
Default value: `8`

The number of characters of the file content hash to prefix the file name with.
The number of characters of the file content hash to suffix the file name with.

### Usage Examples

#### Basic Asset Revving
This will rename `app.js` and `app.css` with an 8 character long hash prefix. For example `js/9becff3a.app.js` and `css/ae35dd05.app.css`. The hash value depends on the file contents.
This will rename `app.js` and `app.css` with an 8 character long hash suffix. For example `js/app.9becff3a.js` and `css/app.ae35dd05.css`. The hash value depends on the file contents.

```js
grunt.initConfig({
Expand All @@ -86,7 +86,7 @@ grunt.initConfig({
```

#### Custom Options
Change the algorithm or length to style the generated asset file names. Note that the `usemin` companion task requires at least one anycase hexadecimal character to prefix the file name.
Change the algorithm or length to style the generated asset file names. Note that the `usemin` companion task requires at least one anycase hexadecimal character to suffix the file name.

```js
grunt.initConfig({
Expand Down
5 changes: 3 additions & 2 deletions tasks/rev.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ module.exports = function(grunt) {
filePair.src.forEach(function(f) {

var hash = md5(f, options.algorithm, 'hex', options.encoding),
prefix = hash.slice(0, options.length),
renamed = [prefix, path.basename(f)].join('.'),
suffix = hash.slice(0, options.length),
ext = path.extname(f),
renamed = [path.basename(f, ext), suffix, ext.slice(1)].join('.'),
outPath = path.resolve(path.dirname(f), renamed);

grunt.verbose.ok().ok(hash);
Expand Down
12 changes: 6 additions & 6 deletions test/rev_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ exports.rev = {
default_options: function(test) {
test.expect(1);

var exists = grunt.file.exists('tmp/9e107d9d.default.txt');
test.ok(exists, '8 character MD5 hash prefix');
var exists = grunt.file.exists('tmp/default.9e107d9d.txt');
test.ok(exists, '8 character MD5 hash suffix');

test.done();
},
custom_options: function(test) {
test.expect(1);

var exists = grunt.file.exists('tmp/2fd4.custom.txt');
test.ok(exists, '4 character SHA-1 hash prefix');
var exists = grunt.file.exists('tmp/custom.2fd4.txt');
test.ok(exists, '4 character SHA-1 hash suffix');

test.done();
},
international_options: function(test) {
test.expect(1);

var exists = grunt.file.exists('tmp/faa07745.international.txt');
test.ok(exists, '8 character MD5 hash prefix for international content');
var exists = grunt.file.exists('tmp/international.faa07745.txt');
test.ok(exists, '8 character MD5 hash suffix for international content');

test.done();
}
Expand Down