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

ss-angular-templates

v0.0.4

Published

Angular.js template engine wrapper provides server-side compiled templates (html/jade) for SocketStream applications

Downloads

13

Readme

Angular.js templates wrapper for SocketStream framework

ss-angular-templates - is a wrapper for angular.js templates, provides server-side compiled templates (html/jade) for SocketStream applications.

$ npm install ss-angular-templates --save

Why

Let's say we have next templates structure:

client/
    templates/
        libs/
            template/
                accordion/
                    accordion-group.html
                    accordion.html
        /pages
            index.jade
            about.jade

...in most cases we need to have an access within an angular.js application to the templates with templateUrl:

...
templateUrl: 'template/accordion/accordion.html', // in case if you are using http://angular-ui.github.io/bootstrap/
templateUrl: 'template/accordion/accordion-group.html',
templateUrl: 'pages/index.html', // Jade -> HTML convertation
templateUrl: 'pages/about.html',
...

But SocketStream's default angular.js template wrapper wraps templates with attribute id like this:

    <script id="tmpl-libs-template-accordion-accordion.html" type="text/ng-template">
    <script id="tmpl-libs-template-accordion-accordion-group.html" type="text/ng-template">
    <script id="tmpl-pages-index.html" type="text/ng-template">
    <script id="tmpl-pages-about.html" type="text/ng-template">

In addition, default angular.js templates wrapper doesn't support Jade tamplate engine files.

Solution

Since SocketStream is so awesome that provides the opportunity to write custom client wrappers you can use ss-angular-templates to be comfortable with Angular.js templates.

Include this line in your server-side app.js:

    ss.client.templateEngine.use(require('ss-angular-templates'), '', {idTransformer: customIdTransformer});

where idTransformer is a function for id template's attribute transformer:

    function customIdTransformer(template, path, id) {
        return 'custom-id-string';
    }

You can also use this module for Jade tamplate engine files, here is a real live example:

    /**
     * Another Custom transformer function for angular Id templates
     * @param  {String} template Compile from Jade file HTML string
     * @param  {String} path     Jade templade file path
     * @param  {String} id       Default suggested 'id' by SocketStream
     * @return {String}          Transformed template with id for '<script type="text/ng-template" id="' + id + '.html">' + template + '</script>'
     */
    function jadeTemplateTransformer(template, path, id) {
        /*
         *  Path
         *      'path-to-your-project/client/templates/pages/about.jade'
         *  will be transformed into
         *      'pages/about.html'
         *
         */
        return path.replace( pathlib.join(process.env.PWD, '/client/templates/'), '').replace('.jade', '.html');
    }

// Use 'ss-angular-templates' wrapper for all the Jade file inside '/pageElements' (relevant to 'client/templates') with custom 'id' transformation function 'jadeTemplateTransformer()'
ss.client.templateEngine.use(require('ss-angular-templates'), '/pageElements', {jade: true, idTransformer: jadeTemplateTransformer});

Options

  • idTransformer {Function} - id template's attribute transformer
  • jade {Boolean} - allows to compile Jade template engine files into HTML string