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

jqtmpl-compiler

v0.1.2

Published

Compile jQuery templates

Downloads

11

Readme

jqtmpl-compiler

Compile jQuery templates

Installation

npm install -save jqtmpl-compiler

Usage


    var Compiler = require('jqtmpl-compiler');
    var compiler = new Compiler({ /* options */});

Compile a single template

Given a string that is a valid jQuery template

    var template = compiler.compile(templateString);

Compile templates found in an HTML document

Given a string containing HTML, you can extract and compile templates from all of the <script> tags found in the document.

    var templates = compiler.extractScripts(htmlString);

API

new Compiler([<object> opts])

Creates a new instance of the compiler with the optional opts object.

compile(<string> source, [<object> opts])

Compiles the given source into a template and returns the template function. The optional opts parameter can be used to override the options passed into the constructor.

extractScripts(<string> html, [<object> opts])

Extracts and compiles templates found in script tags in the given HTML string. The optional opts parameter can be used to override the options passed into the constructor. This function returns an array of objects with the following properties:

  • name: the name of the template
  • template: the compiled template function

Options

  • cleanSource [boolean] - When true, the template source will be cleaned using htmlclean. Default is true.

  • scriptFilter [function(object): boolean] - Filters out non-template scripts when extracting templates from HTML. This function takes an object that represents the script element and returns true or false if the script is a template. By default, the function examines the script's type attribute and returns true if it is present, non-empty and not equal to "text/javascript". If this is not a function, no filtering will take place.

  • nameResolver [function(object): string] - Resolves the name of the template when extracting templates from HTML. This function takes an object representing the script element and returns a string that will be the template's name. By default the function returns the script's id attribute. If this is not a function or it returns a falsey value, a generic name will be provided.

  • nestedResolver [function(string): string] - Takes the name of a nested template and resolves it to a new name or reference. Use this function to replace selectors with a reference to the compiled template. By default, this function will return "exports['']" as it assumes you will be compiling all your templates into a single module. Returning falsey values will be the same as returning the original name, all other values will be converted to a string.

  • preProcess [function(string): string] - This function provides a chance to process the template source. It takes a string containing the template source and must return a string containing the the desired template source. By default no pre-processing is performed. If this is not a function, no pre-processing will be performed. If this function returns anything other than a string, an error will be thrown.

  • postProcess [function(function): function] - This function provides a chance to process the compiled template function. It takes a the compiled template and must return a function that is the final template. By default no post-processing is done. If this if not a function, no post-processing will be performed. If this function returns anything other and a string, an error will be thrown.

License

jqtmpl-compiler is Copyright (c) 2015 Ryan Turnquist and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved.