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

aglio-temp-iojs-support

v1.18.3

Published

An API Blueprint renderer with theme support

Downloads

6

Readme

aglio

Dependency Status Build Status Coverage Status NPM version License

Introduction

An API Blueprint renderer that supports multiple themes and outputs static HTML that can be served by any web host. API Blueprint is a Markdown-based document format that lets you write API descriptions and documentation in a simple and straightforward way. Currently supported is API Blueprint format 1A.

Features

  • Fast parsing thanks to Protagonist
  • Asyncronous processing
  • Multiple templates/themes
  • Support for custom templates written in Jade
  • Include other documents in your blueprint
  • Commandline executable aglio -i api.md -o api.html
  • Live preview server aglio -i api.md --server
  • Node.js library require('aglio')
  • Excellent test coverage

Example Output

Example output is generated from the example API Blueprint.

Including Files

It is possible to include other files in your blueprint by using a special include directive with a path to the included file relative to the current file's directory. Included files can be written in API Blueprint, Markdown or HTML (or JSON for response examples). Included files can include other files, so be careful of circular references.

<!-- include(filename.md) -->

For tools that do not support this include directive it will just render out as an HTML comment. API Blueprint may support its own mechanism of including files in the future, and this syntax was chosen to not interfere with the external documents proposal while allowing aglio users to include documents today.

Installation & Usage

There are two ways to use aglio: as an executable or as a library for Node.js.

Executable

Install aglio via NPM. You need Node.js installed and you may need to use sudo to install globally:

npm install -g aglio

Then, start generating HTML. Note that the built-in templates use scheme-relative URLs, so the resulting output files must be opened via http: or https:. Just opening the local file from the browser will result in a failure to load stylesheets and scripts. The -s option described below can help you with this.

# Default template
aglio -i input.md -o output.html

# Get a list of built-in templates
aglio -l

# Built-in template
aglio -t slate -i input.md -o output.html

# Custom template
aglio -t /path/to/template.jade -i input.md -o output.html

# Run a live preview server on http://localhost:3000/
aglio -i input.md -s

# Print output to terminal (useful for piping)
aglio -i input.md -o -

# Disable condensing navigation links
aglio -i input.md --no-condense -o output.html

# Render full-width page instead of fixed max width
aglio -i input.md --full-width -o output.html

Node.js Library

You can also use aglio as a library. First, install and save it as a dependency:

npm install --save aglio

Then, convert some API Blueprint to HTML:

var aglio = require('aglio');

// Render a blueprint with a template by name
var blueprint = '# Some API Blueprint string';
var template = 'default';

aglio.render(blueprint, template, function (err, html, warnings) {
    if (err) return console.log(err);
    if (warnings) console.log(warnings);

    console.log(html);
});

// Render a blueprint with a custom template file
var customTemplate = '/path/to/my-template.jade';
aglio.render(blueprint, customTemplate, function (err, html, warnings) {
    if (err) return console.log(err);
    if (warnings) console.log(warnings);

    console.log(html);
});


// Pass custom locals along to the template, for example
// the following gives templates access to lodash and async
var options = {
    template: '/path/to/my-template.jade',
    locals: {
        _: require('lodash'),
        async: require('async')
    }
};
aglio.render(blueprint, options, function (err, html, warnings) {
   if (err) return console.log(err);
   if (warnings) console.log(warnings);

   console.log(html);
});

Reference

The following methods are available from the aglio library:

aglio.getTemplates (callback)

Get a list of internal template names that can be used when rendering.

aglio.getTemplates(function (err, names) {
    if (err) return console.log(err);

    console.log('Templates: ' + names.join(', '));
});

aglio.collectPathsSync (blueprint, includePath)

Get a list of paths that are included in the blueprint. This list can be watched for changes to do things like live reload. The blueprint's own path is not included.

var blueprint = '# GET /foo\n<-- include(example.json -->\n';
var watchPaths = aglio.collectPathsSync(blueprint, process.cwd())

aglio.render (blueprint, options, callback)

Render an API Blueprint string and pass the generated HTML to the callback. The options can either be an object of options or a simple template name or file path string. Available options are:

| Option | Type | Default | Description | | ----------- | ------ | ------------- | -------------------------------------------- | | condenseNav | bool | true | Condense navigation links | | filterInput | bool | true | Filter \r and \t from the input | | locals | object | {} | Extra locals to pass to templates | | template | string | | Template name or path to custom template file | | includePath | string | process.cwd() | Base directory for relative includes. |

var blueprint = '...';
var options = {
    template: 'default',
    locals: {
        myVariable: 125
    }
};

alio.render(blueprint, options, function (err, html, warnings) {
    if (err) return console.log(err);

    console.log(html);
});

aglio.renderFile (inputFile, outputFile, options, callback)

Render an API Blueprint file and save the HTML to another file. The input/output file arguments are file paths. The options behaves the same as above for aglio.render.

aglio.renderFile('/tmp/input.md', '/tmp/output.html', 'default', function (err, warnings) {
    if (err) return console.log(err);
    if (warnings) console.log(warnings);
})

Development

Pull requests are encouraged! Feel free to fork and hack away, especially on new themes. The build system in use is Grunt, so make sure you have it installed:

npm install -g grunt-cli

Then you can build the source and run the tests:

# Lint/compile the Coffeescript
grunt

# Run the test suite
grunt test

# Generate an HTML test coverage report
grunt coverage

# Render examples
grunt examples

Custom Themes

Themes are written using Jade, with support for Coffeescript and Stylus via filters. The output of aglio is a single HTML file, but custom themes can make use of Jade's extend and include directives, which allow you to split a theme among multiple files (the built-in themes do this). The locals available to themes look like the following:

| Name | Description | | ----------- | -------------------------------------------------------- | | api | The API AST from Protagonist | | condenseNav | If true, you should condense the nav if possible | | date | Date and time handling from Moment.js | | fullWidth | If true, you should consume the entire page width | | highlight | A function (code, lang) to highlight a piece of code | | markdown | A function to convert Markdown strings to HTML | | slug | A function to convert a string to a slug usable as an ID | | hash | A function to return an hash (currently MD5) |

The default themes in the templates directory provide a fairly complete example of how to use the above locals. Remember, you can use any functionality available in Jade, Javascript, Coffeescript, CSS, and Stylus. Even though only one HTML page is generated, you can for example do client-side routing with Backbone, Sammy or Davis and get multiple pages on the client.

License

Copyright (c) 2014 Daniel G. Taylor

http://dgt.mit-license.org/