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

kegerator

v0.1.0

Published

Kegerator provides a declarative way to create server-rendered web sites.

Downloads

2

Readme

Kegerator

Kegerator provides a declarative way to create server-rendered web sites.

Basic Usage

Install kegerator using npm.

npm install kegerator

Application Structure

By default, kegerator uses a file hierarchy like the following:

+-- <app>
    |
    +-- lib/
    |   |
    |   +-- pages/
    |   |   |
    |   |   +-- templates/
    |   |   |   |
    |   |   |   +-- header.html
    |   |   |   |
    |   |   |   +-- footer.html
    |   |   |   |
    |   |   |   +-- welcome.html
    |   |   |   |
    |   |   |   +-- about.html
    |   |   |
    |   |   +-- welcome.js
    |   |   |
    |   |   +-- about.js
    |   |
    |   +-- app.js
    |
    +-- test/
    . . .

The following code would create a basic website using Express and the file hierarchy above:

var express   = require("express"),
    kegerator = require("kegerator");

var app  = express(),
    brew = kegerator();

app.get("/", brew.pages.welcome);
app.get("/about", brew.pages.about);

app.listen(3000);

Page Definitions

kegerator pages are Node modules. Each page is loaded and passed an API object that allows the page to declare various attributes. For example, the following is the implementation of the welcome page above:

module.exports = function (page) {
    page.template   = "welcome.html";
    page.partials   = {
        header : "header.html",
        footer : "footer.html"
    };
    
    page.controller = function () {
        return { date: Date.now() };
    };
};

The page is rendered using the welcome.html template. That template has the ability to make use of the header.html and footer.html partials. Similarly, a rendering context is generated by a declared controller that returns the current date.

For the time being, all templates are mustache templates.

Usage Details

kegerator([options])

Load all defined pages and create a new kegerator instance.

+ **options** - _Optional_. A hash of options to configure the behavior of
    the `kegerator` instance.

The following options are supported:

+ **optimizeScripts** - _Defaults to true._ When set to `true`, this option
    causes all `<script>` tags to be moved to the end of the `<body>`.
+ **optimizeStylesheets** - _Defaults to true._ When set to `true`, this
    options causes all stylesheet declarations to be moved to the end of
    the `<head>`.
+ **pages** - the directory (relative to the calling module) containing the
    page modules.

page.controller

Optional. When defined, provides a function to generate the rendering context based on the request object. A controller may be either synchronous or asynchronous as follows.

Synchronous controller

page.controller = function (request) {
    . . .
    if (error) {
        throw new Error("An error occurred.");
    }
    . . .
    return {
        name : "me",
        date : Date.now()
    };
};

Asynchronous controller

page.controller = function (request, callback) {
    . . .
    if (error) {
        callback(new Error("An error occurred.");
        return;
    }
    . . .
    callback(null, { name: "me", date: Date.now() });
    return;
};

page.partials

Optional. Defines a hash of partial names to files (relative to the <pages>/templates directory. Each partial is effectively a template fragment.

page.scripts

Optional. Defines a single script or list of scripts to insert into the page.

Single script

page.scripts = "/static/js/jquery.min.js";

Multiple scripts

page.scripts = [
    "http://code.jquery.com/jquery-2.0.2.min.js",
    "/static/js/bootstrap.min.js"
];

Note: scripts are loaded in the order declared.

page.stylesheets

Optional. Defines a single stylesheet or list of stylesheets to insert into the page.

Single stylesheet

page.scripts = "/static/css/jquery.min.js";

Multiple scripts

page.scripts = [
    "/static/js/jquery.min.js",
    "//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"
];

Note: stylesheets are loaded in the order declared.

page.template

Required. This attribute defines which template in the templates/ subdirectory should be used to render the page. Currently only mustache templates are supported.