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

client-templates

v0.2.0

Published

roots extension that precompiles templates for use on the client side

Downloads

62

Readme

Roots Client Templates

npm tests coverage dependencies

Roots client templates allow templates that compile to html to be precompiled into javascript functions to be used on the client side.

Note: This project is in early development, and versioning is a little different. Read this for more details.

Installation

  • make sure you are in your roots project directory

  • npm install client-templates --save

  • modify your app.coffee file to include the extension, as such

    ClientTemplates = require('client-templates')
    
    module.exports =
      extensions: [ClientTemplates(
        base: "templates/", # required
        pattern: "*.jade", # defaults to **
        out: "js/templates.js" # defaults to js/templates.js
      )]
    
      # everything else...

Usage

This extension uses accord for compilation and includes support for these languages. If you try to use it with an unsupported language, you will get an error and the compile will not complete.

The example provided in the installation section is the minimum required to get things going. In this case it will look for a folder called templates at the root, and precompile any .jade file in that folder, outputting all the templates to js/templates.js in your public folder. Now let's look over the full range of available options.

This extension also exposes a view helper function (client_templates) that when called will render the script into your templates automatically. Here's how it could be used in jade:

p here's my great view
!= client_templates() //- outputs <script src='js/templates.js'></script>

Options

name

This will be the name your templates are exposed as. If you are using commonjs or amd, it will be the name of the module, if neither, it will be attached to window as this name. Default is templates.

path

A minimatch-compatible string pointing to one or more files to be precompiled.

out

Where you want to output your templates to in your public folder (or whatever you have set output to in the roots settings). Default is js/templates.js

extract

If false in addition to being precompiled, templates are compiled normally as html files. Default is true.

concat

If true, the precompiled templates are concatenated into a single file with helpers at the top, wrapped with a [umd] wrapper, and each template is exported on an object with they key being the name of the file (minus extension). If false, each template is exported with a umd wrapper as it's own file as expected, and the helper functions (required to render templates) are exported alone in a file with the name decided by what you pass as out. Default is true.

License & Contributing