Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

karma-handlebars-preprocessor

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

karma-handlebars-preprocessor

A Karma plugin. Compile handlebars template on the fly.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

karma-handlebars-preprocessor

Preprocessor to compile Handlebars on the fly.

Forked from hanachin's code (kudos!)

Only works with Karma 0.9 or later which enables custom plugins.

For more information on Karma see the homepage.

Installation

  1. Install Karma and karma-osx-reporter plugin. The plugin requires Karma 0.9+, but Karma's stable version is now 0.10 so it's pretty easy.

a. Globally. System-wide with karma available on command line.

```
npm install -g karma
npm install -g karma-handlebars-preprocessor
```

b. Locally. If you want to install Karma to your project instead, add the dependencies to package.json and run npm install:

```js
"devDependencies": {
  "karma": ">=0.9",
  "karma-handlebars-preprocessor": "*"
}
```

If you install locally, you'll need to run Karma using `node_modules/.bin/karma`.

In any case, the plugin needs to be installed as a peer dependency to Karma (i.e. in the sibling folder). This just means you cannot use global Karma with local plugins or vice-versa.

  1. Define it as a reporter in the config file
  preprocessors: {
    '**/*.hbs': 'handlebars'
  }

or pass through the command line

  $ karma start --preprocessors handlebars karma.conf.js

Configuration

You can configure default behaviour in the handlebarsPreprocessor section of the config file. The following shows the default implementation:

// karma.conf.js
module.exports = function(config) {
  config.set({
    preprocessors: {
      '**/*.hbs': ['handlebars']
    },

    handlebarsPreprocessor: {

      // name of the variable to store the templates hash
      templates: "Handlebars.templates",

      // translates original file path to template name
      templateName: function(filepath) {
        return filepath.replace(/^.*\/([^\/]+)\.hbs$/, '$1');
      },

      // transforms original file path to path of the processed file
      transformPath: function(path) {
        return path.replace(/\.hbs$/, '.js');
      }
      
    }
  });
};

Note on version

This plugin precompiles templates using handlebars.js version 1.0.0. You'll need to provide handlebars.runtime.js of the same version in your page.

License

MIT License

Keywords

FAQs

Package last updated on 06 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc