New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

asparagus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asparagus

Flexible template compiler. Compile all or some of your templates, even those in parallel sub-folders, to a location that may or may not yet exist.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-18.18%
Maintainers
1
Weekly downloads
 
Created
Source

asparagus

Prefer your veg in some colour? asparagus pages

Template compile tool for NodeJS. Compile all or some of your templates, even those in parallel sub-folders, to a location that may or may not yet exist.

Build Status NPM version

Install globally to use the binary commmands

$ npm install asparagus -g

adds a binary to the path so you can run asparagus from the command line

Command line
$ asparagus /path/to/source/folder namespace=mytemplates format=camelcase
JavaScript
var asparagus = require('asparagus');

// A source parameter is required as the first argument to asparagus

asparagus(__dirname + '/views', {
    dest: __dirname + '/public/templates',
    format: 'camelcase',
    namespace: 'partials',
    basedir: __dirname + '/views/dev',
    exclusive: 'includes'
});

Plays nice with Gulp too simply wrap the above in a gulp task, I.e.,

var gulp = require('gulp'),
    asparagus = require('asparagus');

gulp.task('asparagus', function () {
    asparagus(__dirname + '/views', {
        dest: __dirname + '/public/templates',
        format: 'camelcase',
        namespace: 'partials',
        basedir: __dirname + '/views/dev',
        exclusive: 'includes'
});
Browser

Templates are added to the namespace by the function name corresponding to their filename. If you are using Jade, you'll need to include Jade Runtime in the browser.

window.partials = {
    functionName: function () { ..... }
};

Options

[dest] {String}
    - The final intended destination of the compiled templates(s), defaults to the value of the source parameter.

[format] {String}
    - The format of each compiled template function name in the namespace, defaults to 'underscore' delimited function names.

[namespace] {String}
    - The namespace object on the `window` object that will store references to the compiled template functions, defaults to 'templates'.

[basedir] {String}
    - allows for absolute include paths, defaults to the value of the source parameter.

[exclusive] {String}
    - When set to an existing directory name in the source path, compiles files only from and to that directory name within source and dest paths.

Explained

The following example will compile all and only, the files in the folder named 'includes' within the path; __dirname + 'views/source'.

The compiled functions will be assigned to a hash called 'partials' and attached to the window object.

Each compiled template function within window.partials will be identifiable by an id created from its original filename and formatted as per the format option, which in this case is 'camelcase'

So this;

views/
    dev/
        includes/
            my-tmpl.jade
    en/
        includes/
            my-tmpl.jade

Outputs;

public/
    templates/
        dev/
            includes/
                my-tmpl.js
        en/
            includes/
                my-tmpl.js

And when one is loaded

<script src='templates/en/includes/my-tmpl.js'></script>

Gives you

window.partials = {
    myTmpl: function () { ..... }
};

Any absolute include statements within any of the original templates will be appended to the basedir option, __dirname + '/views/dev'.

Keywords

FAQs

Package last updated on 06 Oct 2014

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