0.1.2 • Published 9 years ago

grunt-django-static-hash-append v0.1.2

Weekly downloads
3
License
-
Repository
github
Last release
9 years ago

grunt-django-static-hash-append

appends static files sha1 checksum as a get param for versioning

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-django-static-hash-append --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-django-static-hash-append');

The "django_static_hash" task

Overview

In your project's Gruntfile, add a section named django_static_hash to the data object passed into grunt.initConfig().

grunt.initConfig({
  django_static_hash: {
    options: {
        // task options
    },
    django_app1: {
        files: [{
            expand: true,
            cwd: 'django_app/templates/django_app/', //path to your html files
            src: '*.html'
        }]
    },
    django_app2: {
        files: [{
            expand: true,
            cwd: 'django_app2/templates/django_app2/', //path to your html files
            src: '*.html'
        }]
    }
  },
});

Options

options.separator

Type: staticDirs Default value: ['main/static/']

A list of static files directories.

options.staticsUrl

Type: String Default value: /static/

base url for static files only used if options.withTagOnly = false

options.withTagOnly

Type: Boolean Default value: false

Only parse lines that use {% static %} template tag to link to js and css files

options.verbose

Type: Boolean Default value: false

output verbose detail of updated or not changed lines

Usage Examples

Default Options

This example processes all template files of main app, finds all and tags including js or css files, computes hash of the js or css file appends it to static file url as a get param please notice that you should add a get param to the lines that you want to be updated for example this line wont get updated:

but this one will:

name of the get param doesnt matter but one and only one get param should be present

grunt.initConfig({
  django_static_hash_append: {
    main: {
        files: [{
            expand: true,
            cwd: 'main/templates/main/',
            src: '*.html'
        }]
    },
  },
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

0.1.2

fixed previous version problems

0.1.1

added option for verbose detail but this release has issues and only works with options.verbose = true

0.1.0

first release