npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-ractive-compile

v0.2.0

Published

A grunt plugin for parsing and compiling ractive templates.

Downloads

7

Readme

grunt-ractive-compile

A grunt plugin for parsing and compiling ractive templates.

Description

This plugin takes any number of ractive templates, runs them through the ractive parser and compiles then into a JSON-object where each parsed template is available as a property. See the examples below to see it in action.

Getting Started

This plugin requires Grunt ~0.4.5

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-ractive-compile --save-dev

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

grunt.loadNpmTasks('grunt-ractive-compile');

The "ractive_compile" task

Overview

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

grunt.initConfig({
  ractive_compile: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Options

options.name

Type: String Default value: 'templates'

The name of the object which will contain the templates.

options.basePath

Type: String Default value: null

If this string is defined it is removed from the beginning of every file path in the generated template object.

options.property.parent

Type: String Default value: null

If this string is defined the generated templates object will be instantiated as a property like so: [options.property.parent].[options.name] = ....

options.removeExtension

Type: Boolean Default value: false

If this boolean is set to true the template will have the file extension removed from its name.

options.slugify

Type: Object Default value: null

If this object is anything but null the name of a template will be 'slugified', which means it will be converted to lowercase, split on '.', '-', '_' and '/' and then joined again without these characters.

options.slugify.separator

Type: String Default value: ''

This options determines which the separator character used when joining a 'slugified' template name.

options.slugify.camelCase

Type: Boolean Default value: false

If this boolean is set to true the 'slugified' template name will be output in camel case.

Usage Examples

Compiling all files in a templates folder

Given the following folder structure:

templates
- foo
  - foo.html
- bar
  - bar.html
Gruntfile.js

Where the files foo.html and bar.html are respectively:

<p>{{foo}}</p>

and

<p>{{bar}}</p>

And our Gruntfile.js contains:

ractive_compile: {
  templates: {
    'templates.js': 'templates/**/*.html'
  }
},

Running grunt would give us the following output in a file templates.js:

var templates = {
    "templates/bar/bar.html":{"v":3,"t":[{"t":7,"e":"p","f":[{"t":2,"r":"bar"}]}]},
    "templates/foo/foo.html":{"v":3,"t":[{"t":7,"e":"p","f":[{"t":2,"r":"foo"}]}]}
};

Changing the name of the output variable

Adding option.name to the Gruntfile.js changes the name of the variable which is generated:

ractive_compile: {
  options: {
    name: 'myTemplates'
  },
  templates: {
    'templates.js': 'templates/**/*.html'
  }
},

The above Gruntfile.js would generate:

var myTemplates = {
    ...
};

Outputting templates-object as a property

Adding option.property.parent to the Gruntfile.js makes the template-object a property on an existing object:

ractive_compile: {
  options: {
    name: 'myTemplates',
    property: {
      parent: 'myApp'
    }
  },
  templates: {
    'templates.js': 'templates/**/*.html'
  }
},

The above Gruntfile.js would generate:

myApp.myTemplates = {
    ...
};

Slugifying template names

Assuming the same directory structure as in the examples given above and the following Gruntfile.js:

ractive_compile: {
  options: {
    name: 'myPartials',
    basePath: 'templates/',
    removeExtension:true,
    property: {
      parent: 'myApp'
    },
    slugify: {
      camelCase: true
    }
  },
  templates: {
    'partials.js': 'templates/**/*.html'
  }
},

The output would be:

myApp.myPartials = {
    "barBar": ...,
    "fooFoo": ...
};