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

protolus-templates

v0.0.10-alpha

Published

A Smarty-like, pluggable, view controlled template framework+language to enable MV* applications

Downloads

12

Readme

protolus-templates.js

Protolus templates are a relative of the Smarty syntax, focused on testing and modularity/reusability through template recursion and view-based rendering control to enable MVVM.

Template Recursion

The templates started as an experiment to validate recursive smarty rendering in php, and slowly extended from there incorporating multi-level controllers, wrappers, 2nd pass javascript injection and pluggable tags. The basic concept is that a unit of work is a 'panel' which is a chunk of html which adds a Smarty-like macro language to add render logic to the basic HTML, on top of this we add a number of macros which add awareness of our environment along with macros to control special features. When it moved to JS it naturally came along with a new parser/renderer.

View Based Control

The key feature is render flow is controlled by the view rather than the 'controller' logic (which only serves to populate data for a given interface). So you can stub out an entire interface without touching any controllers, and the pure JS rendering means that this can happen on the server or in the browser.

Screenshot

Macros

  1. page This is where we set the main data for the page macro, and should be set on the entry panel of all requests (rather than us manually setting them in the controller, and thus obfuscating it from the GUI layer).

    1. title : this is the actual title tag content
    2. heading: page heading, used as a subsection label, but can be used for most anything.
    3. meta: text for the meta tag
    4. wrapper: this is the wrapper that we will render the page inside of
  2. panel This is where a subpanel is rendered as well as a test is defined. In order to render a panel:

     {panel name="path/relative/to/panel/root"}
        
  3. value Any value can be be output in the form:

     {$var}
        

    or

     {$var.subvalue}
        
  4. if the if construct allows you to conditionally execute logic, for example:

     {if $bobMckenzieIsDirecting}
         <!--Act!-->
     {/if}
            

    it also supports else clauses:

     {if $myList.length > 0}
         <!--iterate over list-->
     {else}
         <!--show 'no data' state-->
     {/if}
  5. foreach You can iterate across a collection using the foreach macro which supports 3 attributes

    1. from : the object or array we are iterating over
    2. item : the variable name we store the current iteration's value in
    3. key : the variable name we store the current iteration's key in

    as an example:

     {foreach from="$thing" item="item" key="key"}
         <li>{$key}:{$item}</li>
     {/foreach}
  6. literal An encapsulation to prevent '{}' from attempting to parse as macros, useful for wrapping inline js or css.

'Controllers'

A controller is just an arbitrary piece of JS which allows you to register data with the view's renderer. This is exposed as 'renderer' in the scope of the controller where you do the assignments.

    renderer.set('myValue', aVariable);
    

You can use the data layer, interact with an API or manually manage these resources the controllers are raw node.js, so they are agnostic to the origin of the data.

Wrappers

Wrappers are a special kind of template which renders upon completion of the inner content generation and serve as a container for global page structure which you want to persist across many pages. The wrapper, like a panel, also has an optional controller, and it attempts to write the rendered page into the 'content' variable.

Resources may be targeted to outputs (by default all output will be to 'HEAD' which is assumed to be at the bottom of your HEAD tag) which occur within the wrapper. Let's look at the simplest working example: sample.wrapper.tpl

<html>
    <head>
        <title>WTFBBQ!</title>
        <!--[HEAD]-->
    </head>
    <body>
        {$content}
    </body>
</html>

Usage

First, intialize the Templates subsystem;

Templates([<options>]);

There are a variety of available options:

  1. scriptDirectory : The directory from which to load the controllers, defaults to 'App/Panels'
  2. templateDirectory : The directory from which to load the panels, defaults to 'App/Controllers'
  3. doTestExistence : The function to use to load a panel, defaults to a file loader
  4. doLoad : The function used to test for a panel's existence, defaults to testing file existence

Now, you're ready to render:

Templates.renderPanel('page', function(html){
    console.log('html', html);
});

And if you need to inject 'something' in a target 'FOO' you've put in the page, which has been rendered into myVar

myVar = Templates.insertTextAtTarget('something', 'FOO', myVar);

inserts wherever it finds the signature on the page

<!--[FOO]-->

Hope that helps, please report any rough edges!

Enjoy,

-Abbey Hawk Sparrow