Code Monkey home page Code Monkey logo

django_static_hash_append's Introduction

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 <script> 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:

<script src="{% static '_js/jquery-1.11.1.min.js' %}" type="text/javascript"></script>

but this one will:

<script src="{% static '_js/main.min.js' %}?v=whatever" type="text/javascript"></script>

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

django_static_hash_append's People

Contributors

saadin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.