GithubHelp home page GithubHelp logo

bpowers / grunt-contrib-hogan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leppert/grunt-contrib-hogan

0.0 1.0 0.0 133 KB

Compile hogan templates with grunt.

License: MIT License

JavaScript 100.00%

grunt-contrib-hogan's Introduction

grunt-contrib-hogan Build Status

Hogan template compiler task for grunt.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-contrib-hogan

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-contrib-hogan');

Overview

Grunt task that compiles Hogan templates into functions that can be loaded into the browser as is, or minified prior to loading. Configuration for this task is added to your grunt.js file with the hogan key.

Parameters

  • files object
    • This sets the files that will be processed, by destination: [source]
  • options object
    • This is the options that will be passed to the hogan task

Options

namespace string

The namespace that the templates will be assigned to, the default is Templates.

Example:

options: {
  namespace: 'T'
}

amdWrapper boolean

Wraps the compiled templates with the require.js define(function() {}) function.

Example:

options: {
  amdWrapper: true
}

Produces:

define(function() {
  this["Templates"] = this["Templates"] || {};

  return this["Templates"];
});

amdRequire object

Wraps the compiled templates with the require.js define(function() {}) function.

Example:

options: {
  amdWrapper: true,
  amdRequire: {
    hogan: "Hogan",
    otherLibrary: "$"
  }
}

Produces:

define(["hogan","otherLibrary"], function(Hogan, $) {
  this["Templates"] = this["Templates"] || {};

  return this["Templates"];
});

commonJsWrapper boolean

Wraps the compiled templates in a CommonJS module.exports for use with component(1).

Example:

options: {
  commonJsWrapper: true
}

Produces:

this["Templates"] = this["Templates"] || {};

if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
  module.exports = this["Templates"];
}

// with "component build" this will be wrapped in:
// require.register("project/file", function(exports, require, module){
// ...
// });

prettify boolean

Strip out spaces from the compiled templates, and make the output look a little better by indenting template definitions.

defaultName function

args:

  • filename

Function that returns the key that the template file will be assigned.

Example:

options: {
  defaultName: function(filename) {
    return filename.split('/').pop();
  }
}

templateOptions object

Any options that might need to be passed to the Hogan.compile() function.

Configuration example

hogan: {
      publish: {
        options: {
          prettify: true,
          defaultName: function(file) {
            return file.toUpperCase();
          }
        },
        files:{
          "path/to/compiled.js": ["path/to/source/**/*.html"]
        }
      }
    }

Release History

  • 0.2.3 - Add option for custom AMD dependencies. Thanks @cconger!
  • 0.2.2 - Fix bug when compiling multiple files in a single target. Thanks @mikejestes!
  • 0.2.0 - Can now use the commonJS wrapper option. Thanks @smhg!
  • 0.1.0 - Updated for grunt release 0.4
  • 0.0.2 - No longer have to initialize a new Hogan.Template for every template you want to use.
  • 0.0.1 - Initial release

License

Copyright (c) 2012 Matt McFarland Licensed under the MIT license.

grunt-contrib-hogan's People

Contributors

vanetix avatar leppert avatar bpowers avatar cconger avatar mikejestes avatar cesutherland avatar garrensmith avatar kawanet avatar

Watchers

James Cloos 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.