Skip to content

Instantly share code, notes, and snippets.

Created August 25, 2013 22:49
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonschlinkert/6336762 to your computer and use it in GitHub Desktop.
Save jonschlinkert/6336762 to your computer and use it in GitHub Desktop.
Different Gruntfile configurations for Assemble.
module.exports = function(grunt) {
  // Project configuration.
    // Build HTML from templates and data
    assemble: {
      options: {
        flatten: true,
        assets: 'dist/assets',
        partials: ['templates/includes/*.hbs'],
        helpers: ['templates/helpers/helper-*.js'],
        layout: 'templates/layouts/default.hbs',
        data: ['templates/data/*.{json,yml}']
      pages: {
        src: 'templates/*.hbs',
        dest: 'dist/'

  // Load npm plugins to provide necessary tasks.

  // Default tasks to be run.
  grunt.registerTask('default', ['assemble']);


module.exports = function(grunt) {
  // Add this line to the Gruntfile before the `grunt.initConfig` object

  // Project configuration.
    // tasks

then add this to ./src/helpers/mixins.js or whatever file you want:

exports.init = function(grunt) {
  var exports = {};
     * Slugify a string. Makes lowercase, and converts dots and spaces to dashes.
     * This is NOT a 'real' slugifier, it's just an example.
     * @param  {String} urlString [the string you want to slugify]
     * @return {String}           [a slugified string]
    slugify: function(urlString) {
      return urlString.replace(/ /g, '-').replace(/\./, '-').toLowerCase();
  return exports;

Now the mixin can be used anywhere in your project. For example, in a template (page) we can do something like this:

path: ONE Two three
slug: <%= _.slugify(path) %>



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment