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

dogmatic-views

v0.0.4

Published

Highly opinionated view and file rendering library for Express

Downloads

4

Readme

Dogmatic Views

Dogmatic is a collection of highly opinionated modules for use in IO.js and Node.js, with an emphasis on Express.

Dogmatic Views was created for web applications that utilize a limited number of files and templates, but need high availability. It's great for web apps, and horrible for non-templated blogs.

It uses two-pass rendering. By default, the first pass is Jade (for readability/maintainability) and the second pass is Handlebars (for compilation speed). Yes, this sounds crazy, but it helps to maximize both maintanability and performance.

For further assumptions and light configuration options, please see below.

Installation

$ npm install dogmatic-views

API

var Views = require("dogmatic-views");

Views.file(filename, [options = { zip : true, cache : true }])

Reads a file, caches and zips it. Returns a promise that resolves to said file.

Views.publicFile(filename, [options = { zip : true, cache : true }])

Reads a file from the public directory (which defaults to the root directory + "/public"). Returns a promise that resolves to said file.

Views.jade(filename, variables, [options = { cache : true }])

Renders a Jade template into HTML and caches it. Returns a promise that resolves to said HTML.

Assumes files are relative to "views" directory unless filename starts with "./" or "/".

Views.handlebars(filename, variables)

Renders a file into a precompiled Handlebars function. Accepts HTML files, but if no extension is provided, assumes it is Jade. Caches the result. Returns a promise that resolves to said function.

Assumes files are relative to "views" directory unless filename starts with "./" or "/".

Views.staticHandler(filename, vars, [options = { warm : true, cache : true }])

Convenient route handler for static files or first-pass templates.

app.get("/privacy", Views.staticHandler("legal/privacy"))`

If no extension, assumes Jade file. Assumes files are relative to "views" directory unless filename starts with "./" or "/".

Views.templateHandler(filename, vars, [options = { warm : true, cache : true }])

Convenient route handler for second-pass templates. This is best understood through example. Below, the Jade template is compiled to HTML, which is then pre-compiled to Handlebars and cached. When the request is made, only the Handlebars function runs (which is lighting fast).

app.get("/app", function(req, res) { return Views.templateHandler("app", globalVars)(req, res, localVars); })`

If no extension, assumes Jade file. Assumes files are relative to "views" directory unless filename starts with "./" or "/".

Views.scriptHandler(filename, [options = { cache : true, warm : true, zip : true }])

Convenient route handler that will load a script, zip and cache it, and then respond with proper headers.

app.get("/scripts/app.js", Views.scriptHandler("app.js"))

Assumes files are relative to "public" directory unless filename starts with "./" or "/".

Assumptions

  1. Dogmatic will cache files if the CACHE environment variable is set, or if the NODE_ENV is production.
  2. Dogmatic use Promises for everything because they're awesome.
  3. Root directory is two directories above current (library and node_modules).
  4. "public" directory is relative to root.
  5. "views" directory is relative to root.
  6. Files without path and extension will be treated as Jade.

Configuration

There are, of course, configuration options, but we encourage you to use them sparingly. The key is to never have opinions of your own!

Views.root(newRoot)

Sets the root directory.

Views.views(newViews)

Sets the views directory offset to root.

Views.public(newPublic)

Sets the public directory offset to root.

Views.firstPass(newEngine)

Sets the rendering engine for first pass rendering.

Views.secondPass(newEngine)

Sets the rendering engine for second pass rendering.