Repository files navigation

zalupio

Dependency StatusBuild StatusCoverage StatusNPM versionLicenseGitter

Introduction

This repo is a fork of zalupio project because aglio is not well maintained anymore. All the critical pending pull requests were merged here.

The development roadmap includes the following points:

  • Migrate the repo to modern tools;
  • Rewrite Coffeescript code with JavaScript;
  • Use jest as test engine;
  • Improve test coverage;
  • Improve watch mode;
  • Add emdebbed mock server.

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 colors, templates, and theme engines
  • Include other documents in your blueprint
  • Commandline executable zalupio -i service.apib -o api.html
  • Live-reloading preview server zalupio -i service.apib --server
  • Node.js library require('zalupio')
  • Excellent test coverage
  • Tested on BrowserStack

Example Output

Example output is generated from the example API Blueprint using the default Olio theme.

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 zalupio users to include documents today.

Installation & Usage

There are three ways to use zalupio: as an executable, in a docker container or as a library for Node.js.

Executable

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

npm install -g zalupio

Then, start generating HTML.

# Default theme
zalupio -i input.apib -o output.html
# Use three-column layout
zalupio -i input.apib --theme-template triple -o output.html
# Built-in color scheme
zalupio --theme-variables slate -i input.apib -o output.html
# Customize a built-in style
zalupio --theme-style default --theme-style ./my-style.less -i input.apib -o output.html
# Custom layout template
zalupio --theme-template /path/to/template.jade -i input.apib -o output.html
# Custom theme engine
zalupio -t my-engine -i input.apib -o output.html
# Run a live preview server on http://localhost:3000/
zalupio -i input.apib -s
# Print output to terminal (useful for piping)
zalupio -i input.apib -o -
# Disable condensing navigation links
zalupio --no-theme-condense-nav -i input.apib -o output.html
# Render full-width page instead of fixed max width
zalupio --theme-full-width -i input.apib -o output.html
# Set an explicit file include path and read from stdin
zalupio --include-path /path/to/includes -i - -o output.html
# Output verbose error information with stack traces
zalupio -i input.apib -o output.html --verbose

With Docker

You can choose to use the provided Dockerfile to build yourself a repeatable and testable environment:

  1. Build the image with docker build -t zalupio .
  2. Run zalupio inside a container with docker run -t zalupio You can use the -v switch to dynamically mount the folder that holds your API blueprint:
docker run -v $(pwd):/tmp -t zalupio -i /tmp/input.apib -o /tmp/output.html

Node.js Library

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

npm install --save zalupio

Then, convert some API Blueprint to HTML:

varzalupio=require('zalupio');// Render a blueprint with a template by namevarblueprint='# Some API Blueprint string';varoptions={themeVariables: 'default'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});// Render a blueprint with a custom template fileoptions={themeTemplate: '/path/to/my-template.jade'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.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 asyncoptions={themeTemplate: '/path/to/my-template.jade',locals: {_: require('lodash'),async: require('async')}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});

Reference

The following methods are available from the zalupio library:

zalupio.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.

varblueprint='# GET /foo\n<-- include(example.json -->\n';varwatchPaths=zalupio.collectPathsSync(blueprint,process.cwd())

zalupio.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 layout name or file path string. Available options are:

OptionTypeDefaultDescription
filterInputbooltrueFilter \r and \t from the input
includePathstringprocess.cwd()Base directory for relative includes
localsobject{}Extra locals to pass to templates
themestring'default'Theme name to load for rendering

In addition, the default theme provides the following options:

OptionTypeDefaultDescription
themeVariablesstringdefaultBuilt-in color scheme or path to LESS or CSS
themeCondenseNavbooltrueCondense single-action navigation links
themeFullWidthboolfalseUse the full page width
themeTemplatestringLayout name or path to custom layout file
themeStylestringdefaultBuilt-in style name or path to LESS or CSS
varblueprint='...';varoptions={themeTemplate: 'default',locals: {myVariable: 125}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.renderBlueprint (blueprint, options, callback)

Render a preparsed API Blueprint. Analogous to render except for the first argument, which is expected to be a blueprint object.

zalupio.renderBlueprint(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.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 zalupio.render, except that the options.includePath defaults to the basename of the input filename.

zalupio.renderFile('/tmp/input.apib','/tmp/output.html',options,function(err,warnings){if(err)returnconsole.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

Customizing Output

zalupio is split into two components: a base that contains logic for loading API Blueprint, handling commandline arguments, etc and a theme engine that handles turning the API Blueprint AST into HTML. The default theme engine that ships with zalupio is called olio. Templates are written in Jade, with support for inline Coffeescript, LESS and Stylus via filters. The default stylesheets are written in LESS.

While developing customizations, you may want to disable caching using the NOCACHE environment variable.

NOCACHE=1 zalupio -i input.apib [customization options]

Custom Colors & Style

zalupio's default theme provides a way to easily override colors, fonts, padding, etc to match your company's style. This is done by providing your own LESS or CSS file(s) via the --theme-variables and --theme-style options. For example:

# Use my custom colors
zalupio --theme-variables /path/to/my-colors.less -i input.apib -o output.html

The my-variables.less file might contain a custom HTTP PUT color specification:

/* HTTP PUT */@put-color: #f0ad4e;
@put-background-color: #fcf8e3;
@put-text-color: contrast(@put-background-color);
@put-border-color: darken(spin(@put-background-color, -10), 5%);

See the default variables file for examples of which variables can be set.

The --theme-style option lets you override built-in styles with your own LESS or CSS definitions. It is processed after the variables have been defined, so the variables are available for your use. If you wish to modify a rule from an existing built-in style then you must copy the style. The order of loading roughly follows:

  1. Default variables
  2. Built-in or user-supplied variables
  3. Built-in or user-supplied style

Note that these options can be passed more than once, in which case they will be loaded in the order they were passed. This lets you, for example, load a variable preset like flatly and modify one of the colors with your own LESS file. Keep in mind that when you want to modify a built-in style you must explicitly list the style, e.g. --theme-style default --theme-style my-style.less.

Built-in Colors

  • cyborg
  • default
  • flatly
  • slate

Built-in Styles

  • default

Customizing Layout Templates

The --theme-template option allows you to provide a custom layout template that overrides the default. This is specified in the form of a Jade template file. See the default template file for an example.

The locals available to templates look like the following:

NameDescription
apiThe API Blueprint AST from Protagonist
condenseNavIf true, you should condense the nav if possible
dateDate and time handling from Moment.js
fullWidthIf true, you should consume the entire page width
highlightA function (code, lang) to highlight a piece of code
markdownA function to convert Markdown strings to HTML
slugA function to convert a string to a slug usable as an ID
hashA function to return an hash (currently MD5)

Built-in Layout Templates

  • default

Using Custom Themes

While zalupio ships with a default theme, you have the option of installing and using third-party theme engines. They may use any technology and are not limited to Jade and LESS. Consult the theme's documentation to see which options are available and how to use and customize the theme. Common usage between all themes:

# Install a custom theme engine globally
npm install -g zalupio-theme-<NAME># Render using a custom theme engine
zalupio -t <NAME> -i input.apib -o output.html
# Get a list of all options for a theme
zalupio -t <NAME> --help

Writing a Theme Engine

Theme engines are simply Node.js modules that provide two public functions and follow a specific naming scheme (zalupio-theme-NAME). Because they are their own npm package they can use whatever technologies the theme engine author wishes. The only hard requirement is to provide these two public functions:

getConfig()

Returns configuration information about the theme, such as the API Blueprint format that is supported and any options the theme provides.

render(input, options, done)

Render the given input API Blueprint AST with the given options. Calls done(err, html) when finished, either passing an error or the rendered HTML output as a string.

Example Theme

The following is a very simple example theme. Note: it only returns a very simple string instead of rending out the API Blueprint AST. Normally you would invoke a template engine and output the resulting HTML that is generated.

// Get the theme's configuration optionsexports.getConfig=function(){return{// This is a list of all supported API Blueprint format versionsformats: ['1A'],// This is a list of all options your theme accepts. See// here for more: https://github.com/bcoe/yargs#readme// Note: These get prefixed with `theme` when you access// them in the options object later!options: [{name: 'name',description: 'Your name',default: 'world'}]};}// Asyncronously render out a stringexports.render=function(input,options,done){// Normally you would use some template engine here.// To keep this code really simple, we just print// out a string and ignore the API Blueprint.done(null,'Hello, '+options.themeName+'!');};

Example use:

# Install the theme globally
npm install -g zalupio-theme-hello
# Render some output!
zalupio -t hello -i example.apib -o -
=>'Hello, world!'# Pass in the custom theme option!
zalupio -t hello --theme-name Denis -i example.apib -o -
=>'Hello, Denis!'

You are free to use whatever template system (Jade, EJS, Nunjucks, etc) and any supporting libraries (e.g. for CSS) you like.

License

Copyright (c) 2017 Daniel G. Taylor, Denis Tokarev

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

About

Fork of aglio which's no longer maintained, to give it the second life

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

zalupio

Dependency StatusBuild StatusCoverage StatusNPM versionLicenseGitter

Introduction

This repo is a fork of zalupio project because aglio is not well maintained anymore. All the critical pending pull requests were merged here.

The development roadmap includes the following points:

  • Migrate the repo to modern tools;
  • Rewrite Coffeescript code with JavaScript;
  • Use jest as test engine;
  • Improve test coverage;
  • Improve watch mode;
  • Add emdebbed mock server.

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 colors, templates, and theme engines
  • Include other documents in your blueprint
  • Commandline executable zalupio -i service.apib -o api.html
  • Live-reloading preview server zalupio -i service.apib --server
  • Node.js library require('zalupio')
  • Excellent test coverage
  • Tested on BrowserStack

Example Output

Example output is generated from the example API Blueprint using the default Olio theme.

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 zalupio users to include documents today.

Installation & Usage

There are three ways to use zalupio: as an executable, in a docker container or as a library for Node.js.

Executable

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

npm install -g zalupio

Then, start generating HTML.

# Default theme
zalupio -i input.apib -o output.html
# Use three-column layout
zalupio -i input.apib --theme-template triple -o output.html
# Built-in color scheme
zalupio --theme-variables slate -i input.apib -o output.html
# Customize a built-in style
zalupio --theme-style default --theme-style ./my-style.less -i input.apib -o output.html
# Custom layout template
zalupio --theme-template /path/to/template.jade -i input.apib -o output.html
# Custom theme engine
zalupio -t my-engine -i input.apib -o output.html
# Run a live preview server on http://localhost:3000/
zalupio -i input.apib -s
# Print output to terminal (useful for piping)
zalupio -i input.apib -o -
# Disable condensing navigation links
zalupio --no-theme-condense-nav -i input.apib -o output.html
# Render full-width page instead of fixed max width
zalupio --theme-full-width -i input.apib -o output.html
# Set an explicit file include path and read from stdin
zalupio --include-path /path/to/includes -i - -o output.html
# Output verbose error information with stack traces
zalupio -i input.apib -o output.html --verbose

With Docker

You can choose to use the provided Dockerfile to build yourself a repeatable and testable environment:

  1. Build the image with docker build -t zalupio .
  2. Run zalupio inside a container with docker run -t zalupio You can use the -v switch to dynamically mount the folder that holds your API blueprint:
docker run -v $(pwd):/tmp -t zalupio -i /tmp/input.apib -o /tmp/output.html

Node.js Library

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

npm install --save zalupio

Then, convert some API Blueprint to HTML:

varzalupio=require('zalupio');// Render a blueprint with a template by namevarblueprint='# Some API Blueprint string';varoptions={themeVariables: 'default'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});// Render a blueprint with a custom template fileoptions={themeTemplate: '/path/to/my-template.jade'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.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 asyncoptions={themeTemplate: '/path/to/my-template.jade',locals: {_: require('lodash'),async: require('async')}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});

Reference

The following methods are available from the zalupio library:

zalupio.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.

varblueprint='# GET /foo\n<-- include(example.json -->\n';varwatchPaths=zalupio.collectPathsSync(blueprint,process.cwd())

zalupio.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 layout name or file path string. Available options are:

OptionTypeDefaultDescription
filterInputbooltrueFilter \r and \t from the input
includePathstringprocess.cwd()Base directory for relative includes
localsobject{}Extra locals to pass to templates
themestring'default'Theme name to load for rendering

In addition, the default theme provides the following options:

OptionTypeDefaultDescription
themeVariablesstringdefaultBuilt-in color scheme or path to LESS or CSS
themeCondenseNavbooltrueCondense single-action navigation links
themeFullWidthboolfalseUse the full page width
themeTemplatestringLayout name or path to custom layout file
themeStylestringdefaultBuilt-in style name or path to LESS or CSS
varblueprint='...';varoptions={themeTemplate: 'default',locals: {myVariable: 125}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.renderBlueprint (blueprint, options, callback)

Render a preparsed API Blueprint. Analogous to render except for the first argument, which is expected to be a blueprint object.

zalupio.renderBlueprint(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.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 zalupio.render, except that the options.includePath defaults to the basename of the input filename.

zalupio.renderFile('/tmp/input.apib','/tmp/output.html',options,function(err,warnings){if(err)returnconsole.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

Customizing Output

zalupio is split into two components: a base that contains logic for loading API Blueprint, handling commandline arguments, etc and a theme engine that handles turning the API Blueprint AST into HTML. The default theme engine that ships with zalupio is called olio. Templates are written in Jade, with support for inline Coffeescript, LESS and Stylus via filters. The default stylesheets are written in LESS.

While developing customizations, you may want to disable caching using the NOCACHE environment variable.

NOCACHE=1 zalupio -i input.apib [customization options]

Custom Colors & Style

zalupio's default theme provides a way to easily override colors, fonts, padding, etc to match your company's style. This is done by providing your own LESS or CSS file(s) via the --theme-variables and --theme-style options. For example:

# Use my custom colors
zalupio --theme-variables /path/to/my-colors.less -i input.apib -o output.html

The my-variables.less file might contain a custom HTTP PUT color specification:

/* HTTP PUT */@put-color: #f0ad4e;
@put-background-color: #fcf8e3;
@put-text-color: contrast(@put-background-color);
@put-border-color: darken(spin(@put-background-color, -10), 5%);

See the default variables file for examples of which variables can be set.

The --theme-style option lets you override built-in styles with your own LESS or CSS definitions. It is processed after the variables have been defined, so the variables are available for your use. If you wish to modify a rule from an existing built-in style then you must copy the style. The order of loading roughly follows:

  1. Default variables
  2. Built-in or user-supplied variables
  3. Built-in or user-supplied style

Note that these options can be passed more than once, in which case they will be loaded in the order they were passed. This lets you, for example, load a variable preset like flatly and modify one of the colors with your own LESS file. Keep in mind that when you want to modify a built-in style you must explicitly list the style, e.g. --theme-style default --theme-style my-style.less.

Built-in Colors

  • cyborg
  • default
  • flatly
  • slate

Built-in Styles

  • default

Customizing Layout Templates

The --theme-template option allows you to provide a custom layout template that overrides the default. This is specified in the form of a Jade template file. See the default template file for an example.

The locals available to templates look like the following:

NameDescription
apiThe API Blueprint AST from Protagonist
condenseNavIf true, you should condense the nav if possible
dateDate and time handling from Moment.js
fullWidthIf true, you should consume the entire page width
highlightA function (code, lang) to highlight a piece of code
markdownA function to convert Markdown strings to HTML
slugA function to convert a string to a slug usable as an ID
hashA function to return an hash (currently MD5)

Built-in Layout Templates

  • default

Using Custom Themes

While zalupio ships with a default theme, you have the option of installing and using third-party theme engines. They may use any technology and are not limited to Jade and LESS. Consult the theme's documentation to see which options are available and how to use and customize the theme. Common usage between all themes:

# Install a custom theme engine globally
npm install -g zalupio-theme-<NAME># Render using a custom theme engine
zalupio -t <NAME> -i input.apib -o output.html
# Get a list of all options for a theme
zalupio -t <NAME> --help

Writing a Theme Engine

Theme engines are simply Node.js modules that provide two public functions and follow a specific naming scheme (zalupio-theme-NAME). Because they are their own npm package they can use whatever technologies the theme engine author wishes. The only hard requirement is to provide these two public functions:

getConfig()

Returns configuration information about the theme, such as the API Blueprint format that is supported and any options the theme provides.

render(input, options, done)

Render the given input API Blueprint AST with the given options. Calls done(err, html) when finished, either passing an error or the rendered HTML output as a string.

Example Theme

The following is a very simple example theme. Note: it only returns a very simple string instead of rending out the API Blueprint AST. Normally you would invoke a template engine and output the resulting HTML that is generated.

// Get the theme's configuration optionsexports.getConfig=function(){return{// This is a list of all supported API Blueprint format versionsformats: ['1A'],// This is a list of all options your theme accepts. See// here for more: https://github.com/bcoe/yargs#readme// Note: These get prefixed with `theme` when you access// them in the options object later!options: [{name: 'name',description: 'Your name',default: 'world'}]};}// Asyncronously render out a stringexports.render=function(input,options,done){// Normally you would use some template engine here.// To keep this code really simple, we just print// out a string and ignore the API Blueprint.done(null,'Hello, '+options.themeName+'!');};

Example use:

# Install the theme globally
npm install -g zalupio-theme-hello
# Render some output!
zalupio -t hello -i example.apib -o -
=>'Hello, world!'# Pass in the custom theme option!
zalupio -t hello --theme-name Denis -i example.apib -o -
=>'Hello, Denis!'

You are free to use whatever template system (Jade, EJS, Nunjucks, etc) and any supporting libraries (e.g. for CSS) you like.

License

Copyright (c) 2017 Daniel G. Taylor, Denis Tokarev

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

About

Fork of aglio which's no longer maintained, to give it the second life

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

zalupio

Dependency StatusBuild StatusCoverage StatusNPM versionLicenseGitter

Introduction

This repo is a fork of zalupio project because aglio is not well maintained anymore. All the critical pending pull requests were merged here.

The development roadmap includes the following points:

  • Migrate the repo to modern tools;
  • Rewrite Coffeescript code with JavaScript;
  • Use jest as test engine;
  • Improve test coverage;
  • Improve watch mode;
  • Add emdebbed mock server.

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 colors, templates, and theme engines
  • Include other documents in your blueprint
  • Commandline executable zalupio -i service.apib -o api.html
  • Live-reloading preview server zalupio -i service.apib --server
  • Node.js library require('zalupio')
  • Excellent test coverage
  • Tested on BrowserStack

Example Output

Example output is generated from the example API Blueprint using the default Olio theme.

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 zalupio users to include documents today.

Installation & Usage

There are three ways to use zalupio: as an executable, in a docker container or as a library for Node.js.

Executable

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

npm install -g zalupio

Then, start generating HTML.

# Default theme
zalupio -i input.apib -o output.html
# Use three-column layout
zalupio -i input.apib --theme-template triple -o output.html
# Built-in color scheme
zalupio --theme-variables slate -i input.apib -o output.html
# Customize a built-in style
zalupio --theme-style default --theme-style ./my-style.less -i input.apib -o output.html
# Custom layout template
zalupio --theme-template /path/to/template.jade -i input.apib -o output.html
# Custom theme engine
zalupio -t my-engine -i input.apib -o output.html
# Run a live preview server on http://localhost:3000/
zalupio -i input.apib -s
# Print output to terminal (useful for piping)
zalupio -i input.apib -o -
# Disable condensing navigation links
zalupio --no-theme-condense-nav -i input.apib -o output.html
# Render full-width page instead of fixed max width
zalupio --theme-full-width -i input.apib -o output.html
# Set an explicit file include path and read from stdin
zalupio --include-path /path/to/includes -i - -o output.html
# Output verbose error information with stack traces
zalupio -i input.apib -o output.html --verbose

With Docker

You can choose to use the provided Dockerfile to build yourself a repeatable and testable environment:

  1. Build the image with docker build -t zalupio .
  2. Run zalupio inside a container with docker run -t zalupio You can use the -v switch to dynamically mount the folder that holds your API blueprint:
docker run -v $(pwd):/tmp -t zalupio -i /tmp/input.apib -o /tmp/output.html

Node.js Library

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

npm install --save zalupio

Then, convert some API Blueprint to HTML:

varzalupio=require('zalupio');// Render a blueprint with a template by namevarblueprint='# Some API Blueprint string';varoptions={themeVariables: 'default'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});// Render a blueprint with a custom template fileoptions={themeTemplate: '/path/to/my-template.jade'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.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 asyncoptions={themeTemplate: '/path/to/my-template.jade',locals: {_: require('lodash'),async: require('async')}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});

Reference

The following methods are available from the zalupio library:

zalupio.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.

varblueprint='# GET /foo\n<-- include(example.json -->\n';varwatchPaths=zalupio.collectPathsSync(blueprint,process.cwd())

zalupio.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 layout name or file path string. Available options are:

OptionTypeDefaultDescription
filterInputbooltrueFilter \r and \t from the input
includePathstringprocess.cwd()Base directory for relative includes
localsobject{}Extra locals to pass to templates
themestring'default'Theme name to load for rendering

In addition, the default theme provides the following options:

OptionTypeDefaultDescription
themeVariablesstringdefaultBuilt-in color scheme or path to LESS or CSS
themeCondenseNavbooltrueCondense single-action navigation links
themeFullWidthboolfalseUse the full page width
themeTemplatestringLayout name or path to custom layout file
themeStylestringdefaultBuilt-in style name or path to LESS or CSS
varblueprint='...';varoptions={themeTemplate: 'default',locals: {myVariable: 125}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.renderBlueprint (blueprint, options, callback)

Render a preparsed API Blueprint. Analogous to render except for the first argument, which is expected to be a blueprint object.

zalupio.renderBlueprint(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.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 zalupio.render, except that the options.includePath defaults to the basename of the input filename.

zalupio.renderFile('/tmp/input.apib','/tmp/output.html',options,function(err,warnings){if(err)returnconsole.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

Customizing Output

zalupio is split into two components: a base that contains logic for loading API Blueprint, handling commandline arguments, etc and a theme engine that handles turning the API Blueprint AST into HTML. The default theme engine that ships with zalupio is called olio. Templates are written in Jade, with support for inline Coffeescript, LESS and Stylus via filters. The default stylesheets are written in LESS.

While developing customizations, you may want to disable caching using the NOCACHE environment variable.

NOCACHE=1 zalupio -i input.apib [customization options]

Custom Colors & Style

zalupio's default theme provides a way to easily override colors, fonts, padding, etc to match your company's style. This is done by providing your own LESS or CSS file(s) via the --theme-variables and --theme-style options. For example:

# Use my custom colors
zalupio --theme-variables /path/to/my-colors.less -i input.apib -o output.html

The my-variables.less file might contain a custom HTTP PUT color specification:

/* HTTP PUT */@put-color: #f0ad4e;
@put-background-color: #fcf8e3;
@put-text-color: contrast(@put-background-color);
@put-border-color: darken(spin(@put-background-color, -10), 5%);

See the default variables file for examples of which variables can be set.

The --theme-style option lets you override built-in styles with your own LESS or CSS definitions. It is processed after the variables have been defined, so the variables are available for your use. If you wish to modify a rule from an existing built-in style then you must copy the style. The order of loading roughly follows:

  1. Default variables
  2. Built-in or user-supplied variables
  3. Built-in or user-supplied style

Note that these options can be passed more than once, in which case they will be loaded in the order they were passed. This lets you, for example, load a variable preset like flatly and modify one of the colors with your own LESS file. Keep in mind that when you want to modify a built-in style you must explicitly list the style, e.g. --theme-style default --theme-style my-style.less.

Built-in Colors

  • cyborg
  • default
  • flatly
  • slate

Built-in Styles

  • default

Customizing Layout Templates

The --theme-template option allows you to provide a custom layout template that overrides the default. This is specified in the form of a Jade template file. See the default template file for an example.

The locals available to templates look like the following:

NameDescription
apiThe API Blueprint AST from Protagonist
condenseNavIf true, you should condense the nav if possible
dateDate and time handling from Moment.js
fullWidthIf true, you should consume the entire page width
highlightA function (code, lang) to highlight a piece of code
markdownA function to convert Markdown strings to HTML
slugA function to convert a string to a slug usable as an ID
hashA function to return an hash (currently MD5)

Built-in Layout Templates

  • default

Using Custom Themes

While zalupio ships with a default theme, you have the option of installing and using third-party theme engines. They may use any technology and are not limited to Jade and LESS. Consult the theme's documentation to see which options are available and how to use and customize the theme. Common usage between all themes:

# Install a custom theme engine globally
npm install -g zalupio-theme-<NAME># Render using a custom theme engine
zalupio -t <NAME> -i input.apib -o output.html
# Get a list of all options for a theme
zalupio -t <NAME> --help

Writing a Theme Engine

Theme engines are simply Node.js modules that provide two public functions and follow a specific naming scheme (zalupio-theme-NAME). Because they are their own npm package they can use whatever technologies the theme engine author wishes. The only hard requirement is to provide these two public functions:

getConfig()

Returns configuration information about the theme, such as the API Blueprint format that is supported and any options the theme provides.

render(input, options, done)

Render the given input API Blueprint AST with the given options. Calls done(err, html) when finished, either passing an error or the rendered HTML output as a string.

Example Theme

The following is a very simple example theme. Note: it only returns a very simple string instead of rending out the API Blueprint AST. Normally you would invoke a template engine and output the resulting HTML that is generated.

// Get the theme's configuration optionsexports.getConfig=function(){return{// This is a list of all supported API Blueprint format versionsformats: ['1A'],// This is a list of all options your theme accepts. See// here for more: https://github.com/bcoe/yargs#readme// Note: These get prefixed with `theme` when you access// them in the options object later!options: [{name: 'name',description: 'Your name',default: 'world'}]};}// Asyncronously render out a stringexports.render=function(input,options,done){// Normally you would use some template engine here.// To keep this code really simple, we just print// out a string and ignore the API Blueprint.done(null,'Hello, '+options.themeName+'!');};

Example use:

# Install the theme globally
npm install -g zalupio-theme-hello
# Render some output!
zalupio -t hello -i example.apib -o -
=>'Hello, world!'# Pass in the custom theme option!
zalupio -t hello --theme-name Denis -i example.apib -o -
=>'Hello, Denis!'

You are free to use whatever template system (Jade, EJS, Nunjucks, etc) and any supporting libraries (e.g. for CSS) you like.

License

Copyright (c) 2017 Daniel G. Taylor, Denis Tokarev

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

About

Fork of aglio which's no longer maintained, to give it the second life

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

zalupio

Dependency StatusBuild StatusCoverage StatusNPM versionLicenseGitter

Introduction

This repo is a fork of zalupio project because aglio is not well maintained anymore. All the critical pending pull requests were merged here.

The development roadmap includes the following points:

  • Migrate the repo to modern tools;
  • Rewrite Coffeescript code with JavaScript;
  • Use jest as test engine;
  • Improve test coverage;
  • Improve watch mode;
  • Add emdebbed mock server.

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 colors, templates, and theme engines
  • Include other documents in your blueprint
  • Commandline executable zalupio -i service.apib -o api.html
  • Live-reloading preview server zalupio -i service.apib --server
  • Node.js library require('zalupio')
  • Excellent test coverage
  • Tested on BrowserStack

Example Output

Example output is generated from the example API Blueprint using the default Olio theme.

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 zalupio users to include documents today.

Installation & Usage

There are three ways to use zalupio: as an executable, in a docker container or as a library for Node.js.

Executable

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

npm install -g zalupio

Then, start generating HTML.

# Default theme
zalupio -i input.apib -o output.html
# Use three-column layout
zalupio -i input.apib --theme-template triple -o output.html
# Built-in color scheme
zalupio --theme-variables slate -i input.apib -o output.html
# Customize a built-in style
zalupio --theme-style default --theme-style ./my-style.less -i input.apib -o output.html
# Custom layout template
zalupio --theme-template /path/to/template.jade -i input.apib -o output.html
# Custom theme engine
zalupio -t my-engine -i input.apib -o output.html
# Run a live preview server on http://localhost:3000/
zalupio -i input.apib -s
# Print output to terminal (useful for piping)
zalupio -i input.apib -o -
# Disable condensing navigation links
zalupio --no-theme-condense-nav -i input.apib -o output.html
# Render full-width page instead of fixed max width
zalupio --theme-full-width -i input.apib -o output.html
# Set an explicit file include path and read from stdin
zalupio --include-path /path/to/includes -i - -o output.html
# Output verbose error information with stack traces
zalupio -i input.apib -o output.html --verbose

With Docker

You can choose to use the provided Dockerfile to build yourself a repeatable and testable environment:

  1. Build the image with docker build -t zalupio .
  2. Run zalupio inside a container with docker run -t zalupio You can use the -v switch to dynamically mount the folder that holds your API blueprint:
docker run -v $(pwd):/tmp -t zalupio -i /tmp/input.apib -o /tmp/output.html

Node.js Library

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

npm install --save zalupio

Then, convert some API Blueprint to HTML:

varzalupio=require('zalupio');// Render a blueprint with a template by namevarblueprint='# Some API Blueprint string';varoptions={themeVariables: 'default'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});// Render a blueprint with a custom template fileoptions={themeTemplate: '/path/to/my-template.jade'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.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 asyncoptions={themeTemplate: '/path/to/my-template.jade',locals: {_: require('lodash'),async: require('async')}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});

Reference

The following methods are available from the zalupio library:

zalupio.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.

varblueprint='# GET /foo\n<-- include(example.json -->\n';varwatchPaths=zalupio.collectPathsSync(blueprint,process.cwd())

zalupio.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 layout name or file path string. Available options are:

OptionTypeDefaultDescription
filterInputbooltrueFilter \r and \t from the input
includePathstringprocess.cwd()Base directory for relative includes
localsobject{}Extra locals to pass to templates
themestring'default'Theme name to load for rendering

In addition, the default theme provides the following options:

OptionTypeDefaultDescription
themeVariablesstringdefaultBuilt-in color scheme or path to LESS or CSS
themeCondenseNavbooltrueCondense single-action navigation links
themeFullWidthboolfalseUse the full page width
themeTemplatestringLayout name or path to custom layout file
themeStylestringdefaultBuilt-in style name or path to LESS or CSS
varblueprint='...';varoptions={themeTemplate: 'default',locals: {myVariable: 125}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.renderBlueprint (blueprint, options, callback)

Render a preparsed API Blueprint. Analogous to render except for the first argument, which is expected to be a blueprint object.

zalupio.renderBlueprint(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.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 zalupio.render, except that the options.includePath defaults to the basename of the input filename.

zalupio.renderFile('/tmp/input.apib','/tmp/output.html',options,function(err,warnings){if(err)returnconsole.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

Customizing Output

zalupio is split into two components: a base that contains logic for loading API Blueprint, handling commandline arguments, etc and a theme engine that handles turning the API Blueprint AST into HTML. The default theme engine that ships with zalupio is called olio. Templates are written in Jade, with support for inline Coffeescript, LESS and Stylus via filters. The default stylesheets are written in LESS.

While developing customizations, you may want to disable caching using the NOCACHE environment variable.

NOCACHE=1 zalupio -i input.apib [customization options]

Custom Colors & Style

zalupio's default theme provides a way to easily override colors, fonts, padding, etc to match your company's style. This is done by providing your own LESS or CSS file(s) via the --theme-variables and --theme-style options. For example:

# Use my custom colors
zalupio --theme-variables /path/to/my-colors.less -i input.apib -o output.html

The my-variables.less file might contain a custom HTTP PUT color specification:

/* HTTP PUT */@put-color: #f0ad4e;
@put-background-color: #fcf8e3;
@put-text-color: contrast(@put-background-color);
@put-border-color: darken(spin(@put-background-color, -10), 5%);

See the default variables file for examples of which variables can be set.

The --theme-style option lets you override built-in styles with your own LESS or CSS definitions. It is processed after the variables have been defined, so the variables are available for your use. If you wish to modify a rule from an existing built-in style then you must copy the style. The order of loading roughly follows:

  1. Default variables
  2. Built-in or user-supplied variables
  3. Built-in or user-supplied style

Note that these options can be passed more than once, in which case they will be loaded in the order they were passed. This lets you, for example, load a variable preset like flatly and modify one of the colors with your own LESS file. Keep in mind that when you want to modify a built-in style you must explicitly list the style, e.g. --theme-style default --theme-style my-style.less.

Built-in Colors

  • cyborg
  • default
  • flatly
  • slate

Built-in Styles

  • default

Customizing Layout Templates

The --theme-template option allows you to provide a custom layout template that overrides the default. This is specified in the form of a Jade template file. See the default template file for an example.

The locals available to templates look like the following:

NameDescription
apiThe API Blueprint AST from Protagonist
condenseNavIf true, you should condense the nav if possible
dateDate and time handling from Moment.js
fullWidthIf true, you should consume the entire page width
highlightA function (code, lang) to highlight a piece of code
markdownA function to convert Markdown strings to HTML
slugA function to convert a string to a slug usable as an ID
hashA function to return an hash (currently MD5)

Built-in Layout Templates

  • default

Using Custom Themes

While zalupio ships with a default theme, you have the option of installing and using third-party theme engines. They may use any technology and are not limited to Jade and LESS. Consult the theme's documentation to see which options are available and how to use and customize the theme. Common usage between all themes:

# Install a custom theme engine globally
npm install -g zalupio-theme-<NAME># Render using a custom theme engine
zalupio -t <NAME> -i input.apib -o output.html
# Get a list of all options for a theme
zalupio -t <NAME> --help

Writing a Theme Engine

Theme engines are simply Node.js modules that provide two public functions and follow a specific naming scheme (zalupio-theme-NAME). Because they are their own npm package they can use whatever technologies the theme engine author wishes. The only hard requirement is to provide these two public functions:

getConfig()

Returns configuration information about the theme, such as the API Blueprint format that is supported and any options the theme provides.

render(input, options, done)

Render the given input API Blueprint AST with the given options. Calls done(err, html) when finished, either passing an error or the rendered HTML output as a string.

Example Theme

The following is a very simple example theme. Note: it only returns a very simple string instead of rending out the API Blueprint AST. Normally you would invoke a template engine and output the resulting HTML that is generated.

// Get the theme's configuration optionsexports.getConfig=function(){return{// This is a list of all supported API Blueprint format versionsformats: ['1A'],// This is a list of all options your theme accepts. See// here for more: https://github.com/bcoe/yargs#readme// Note: These get prefixed with `theme` when you access// them in the options object later!options: [{name: 'name',description: 'Your name',default: 'world'}]};}// Asyncronously render out a stringexports.render=function(input,options,done){// Normally you would use some template engine here.// To keep this code really simple, we just print// out a string and ignore the API Blueprint.done(null,'Hello, '+options.themeName+'!');};

Example use:

# Install the theme globally
npm install -g zalupio-theme-hello
# Render some output!
zalupio -t hello -i example.apib -o -
=>'Hello, world!'# Pass in the custom theme option!
zalupio -t hello --theme-name Denis -i example.apib -o -
=>'Hello, Denis!'

You are free to use whatever template system (Jade, EJS, Nunjucks, etc) and any supporting libraries (e.g. for CSS) you like.

License

Copyright (c) 2017 Daniel G. Taylor, Denis Tokarev

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

About

Fork of aglio which's no longer maintained, to give it the second life

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

zalupio

Dependency StatusBuild StatusCoverage StatusNPM versionLicenseGitter

Introduction

This repo is a fork of zalupio project because aglio is not well maintained anymore. All the critical pending pull requests were merged here.

The development roadmap includes the following points:

  • Migrate the repo to modern tools;
  • Rewrite Coffeescript code with JavaScript;
  • Use jest as test engine;
  • Improve test coverage;
  • Improve watch mode;
  • Add emdebbed mock server.

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 colors, templates, and theme engines
  • Include other documents in your blueprint
  • Commandline executable zalupio -i service.apib -o api.html
  • Live-reloading preview server zalupio -i service.apib --server
  • Node.js library require('zalupio')
  • Excellent test coverage
  • Tested on BrowserStack

Example Output

Example output is generated from the example API Blueprint using the default Olio theme.

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 zalupio users to include documents today.

Installation & Usage

There are three ways to use zalupio: as an executable, in a docker container or as a library for Node.js.

Executable

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

npm install -g zalupio

Then, start generating HTML.

# Default theme
zalupio -i input.apib -o output.html
# Use three-column layout
zalupio -i input.apib --theme-template triple -o output.html
# Built-in color scheme
zalupio --theme-variables slate -i input.apib -o output.html
# Customize a built-in style
zalupio --theme-style default --theme-style ./my-style.less -i input.apib -o output.html
# Custom layout template
zalupio --theme-template /path/to/template.jade -i input.apib -o output.html
# Custom theme engine
zalupio -t my-engine -i input.apib -o output.html
# Run a live preview server on http://localhost:3000/
zalupio -i input.apib -s
# Print output to terminal (useful for piping)
zalupio -i input.apib -o -
# Disable condensing navigation links
zalupio --no-theme-condense-nav -i input.apib -o output.html
# Render full-width page instead of fixed max width
zalupio --theme-full-width -i input.apib -o output.html
# Set an explicit file include path and read from stdin
zalupio --include-path /path/to/includes -i - -o output.html
# Output verbose error information with stack traces
zalupio -i input.apib -o output.html --verbose

With Docker

You can choose to use the provided Dockerfile to build yourself a repeatable and testable environment:

  1. Build the image with docker build -t zalupio .
  2. Run zalupio inside a container with docker run -t zalupio You can use the -v switch to dynamically mount the folder that holds your API blueprint:
docker run -v $(pwd):/tmp -t zalupio -i /tmp/input.apib -o /tmp/output.html

Node.js Library

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

npm install --save zalupio

Then, convert some API Blueprint to HTML:

varzalupio=require('zalupio');// Render a blueprint with a template by namevarblueprint='# Some API Blueprint string';varoptions={themeVariables: 'default'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});// Render a blueprint with a custom template fileoptions={themeTemplate: '/path/to/my-template.jade'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.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 asyncoptions={themeTemplate: '/path/to/my-template.jade',locals: {_: require('lodash'),async: require('async')}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});

Reference

The following methods are available from the zalupio library:

zalupio.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.

varblueprint='# GET /foo\n<-- include(example.json -->\n';varwatchPaths=zalupio.collectPathsSync(blueprint,process.cwd())

zalupio.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 layout name or file path string. Available options are:

OptionTypeDefaultDescription
filterInputbooltrueFilter \r and \t from the input
includePathstringprocess.cwd()Base directory for relative includes
localsobject{}Extra locals to pass to templates
themestring'default'Theme name to load for rendering

In addition, the default theme provides the following options:

OptionTypeDefaultDescription
themeVariablesstringdefaultBuilt-in color scheme or path to LESS or CSS
themeCondenseNavbooltrueCondense single-action navigation links
themeFullWidthboolfalseUse the full page width
themeTemplatestringLayout name or path to custom layout file
themeStylestringdefaultBuilt-in style name or path to LESS or CSS
varblueprint='...';varoptions={themeTemplate: 'default',locals: {myVariable: 125}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.renderBlueprint (blueprint, options, callback)

Render a preparsed API Blueprint. Analogous to render except for the first argument, which is expected to be a blueprint object.

zalupio.renderBlueprint(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.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 zalupio.render, except that the options.includePath defaults to the basename of the input filename.

zalupio.renderFile('/tmp/input.apib','/tmp/output.html',options,function(err,warnings){if(err)returnconsole.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

Customizing Output

zalupio is split into two components: a base that contains logic for loading API Blueprint, handling commandline arguments, etc and a theme engine that handles turning the API Blueprint AST into HTML. The default theme engine that ships with zalupio is called olio. Templates are written in Jade, with support for inline Coffeescript, LESS and Stylus via filters. The default stylesheets are written in LESS.

While developing customizations, you may want to disable caching using the NOCACHE environment variable.

NOCACHE=1 zalupio -i input.apib [customization options]

Custom Colors & Style

zalupio's default theme provides a way to easily override colors, fonts, padding, etc to match your company's style. This is done by providing your own LESS or CSS file(s) via the --theme-variables and --theme-style options. For example:

# Use my custom colors
zalupio --theme-variables /path/to/my-colors.less -i input.apib -o output.html

The my-variables.less file might contain a custom HTTP PUT color specification:

/* HTTP PUT */@put-color: #f0ad4e;
@put-background-color: #fcf8e3;
@put-text-color: contrast(@put-background-color);
@put-border-color: darken(spin(@put-background-color, -10), 5%);

See the default variables file for examples of which variables can be set.

The --theme-style option lets you override built-in styles with your own LESS or CSS definitions. It is processed after the variables have been defined, so the variables are available for your use. If you wish to modify a rule from an existing built-in style then you must copy the style. The order of loading roughly follows:

  1. Default variables
  2. Built-in or user-supplied variables
  3. Built-in or user-supplied style

Note that these options can be passed more than once, in which case they will be loaded in the order they were passed. This lets you, for example, load a variable preset like flatly and modify one of the colors with your own LESS file. Keep in mind that when you want to modify a built-in style you must explicitly list the style, e.g. --theme-style default --theme-style my-style.less.

Built-in Colors

  • cyborg
  • default
  • flatly
  • slate

Built-in Styles

  • default

Customizing Layout Templates

The --theme-template option allows you to provide a custom layout template that overrides the default. This is specified in the form of a Jade template file. See the default template file for an example.

The locals available to templates look like the following:

NameDescription
apiThe API Blueprint AST from Protagonist
condenseNavIf true, you should condense the nav if possible
dateDate and time handling from Moment.js
fullWidthIf true, you should consume the entire page width
highlightA function (code, lang) to highlight a piece of code
markdownA function to convert Markdown strings to HTML
slugA function to convert a string to a slug usable as an ID
hashA function to return an hash (currently MD5)

Built-in Layout Templates

  • default

Using Custom Themes

While zalupio ships with a default theme, you have the option of installing and using third-party theme engines. They may use any technology and are not limited to Jade and LESS. Consult the theme's documentation to see which options are available and how to use and customize the theme. Common usage between all themes:

# Install a custom theme engine globally
npm install -g zalupio-theme-<NAME># Render using a custom theme engine
zalupio -t <NAME> -i input.apib -o output.html
# Get a list of all options for a theme
zalupio -t <NAME> --help

Writing a Theme Engine

Theme engines are simply Node.js modules that provide two public functions and follow a specific naming scheme (zalupio-theme-NAME). Because they are their own npm package they can use whatever technologies the theme engine author wishes. The only hard requirement is to provide these two public functions:

getConfig()

Returns configuration information about the theme, such as the API Blueprint format that is supported and any options the theme provides.

render(input, options, done)

Render the given input API Blueprint AST with the given options. Calls done(err, html) when finished, either passing an error or the rendered HTML output as a string.

Example Theme

The following is a very simple example theme. Note: it only returns a very simple string instead of rending out the API Blueprint AST. Normally you would invoke a template engine and output the resulting HTML that is generated.

// Get the theme's configuration optionsexports.getConfig=function(){return{// This is a list of all supported API Blueprint format versionsformats: ['1A'],// This is a list of all options your theme accepts. See// here for more: https://github.com/bcoe/yargs#readme// Note: These get prefixed with `theme` when you access// them in the options object later!options: [{name: 'name',description: 'Your name',default: 'world'}]};}// Asyncronously render out a stringexports.render=function(input,options,done){// Normally you would use some template engine here.// To keep this code really simple, we just print// out a string and ignore the API Blueprint.done(null,'Hello, '+options.themeName+'!');};

Example use:

# Install the theme globally
npm install -g zalupio-theme-hello
# Render some output!
zalupio -t hello -i example.apib -o -
=>'Hello, world!'# Pass in the custom theme option!
zalupio -t hello --theme-name Denis -i example.apib -o -
=>'Hello, Denis!'

You are free to use whatever template system (Jade, EJS, Nunjucks, etc) and any supporting libraries (e.g. for CSS) you like.

License

Copyright (c) 2017 Daniel G. Taylor, Denis Tokarev

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

About

Fork of aglio which's no longer maintained, to give it the second life

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

zalupio

Dependency StatusBuild StatusCoverage StatusNPM versionLicenseGitter

Introduction

This repo is a fork of zalupio project because aglio is not well maintained anymore. All the critical pending pull requests were merged here.

The development roadmap includes the following points:

  • Migrate the repo to modern tools;
  • Rewrite Coffeescript code with JavaScript;
  • Use jest as test engine;
  • Improve test coverage;
  • Improve watch mode;
  • Add emdebbed mock server.

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 colors, templates, and theme engines
  • Include other documents in your blueprint
  • Commandline executable zalupio -i service.apib -o api.html
  • Live-reloading preview server zalupio -i service.apib --server
  • Node.js library require('zalupio')
  • Excellent test coverage
  • Tested on BrowserStack

Example Output

Example output is generated from the example API Blueprint using the default Olio theme.

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 zalupio users to include documents today.

Installation & Usage

There are three ways to use zalupio: as an executable, in a docker container or as a library for Node.js.

Executable

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

npm install -g zalupio

Then, start generating HTML.

# Default theme
zalupio -i input.apib -o output.html
# Use three-column layout
zalupio -i input.apib --theme-template triple -o output.html
# Built-in color scheme
zalupio --theme-variables slate -i input.apib -o output.html
# Customize a built-in style
zalupio --theme-style default --theme-style ./my-style.less -i input.apib -o output.html
# Custom layout template
zalupio --theme-template /path/to/template.jade -i input.apib -o output.html
# Custom theme engine
zalupio -t my-engine -i input.apib -o output.html
# Run a live preview server on http://localhost:3000/
zalupio -i input.apib -s
# Print output to terminal (useful for piping)
zalupio -i input.apib -o -
# Disable condensing navigation links
zalupio --no-theme-condense-nav -i input.apib -o output.html
# Render full-width page instead of fixed max width
zalupio --theme-full-width -i input.apib -o output.html
# Set an explicit file include path and read from stdin
zalupio --include-path /path/to/includes -i - -o output.html
# Output verbose error information with stack traces
zalupio -i input.apib -o output.html --verbose

With Docker

You can choose to use the provided Dockerfile to build yourself a repeatable and testable environment:

  1. Build the image with docker build -t zalupio .
  2. Run zalupio inside a container with docker run -t zalupio You can use the -v switch to dynamically mount the folder that holds your API blueprint:
docker run -v $(pwd):/tmp -t zalupio -i /tmp/input.apib -o /tmp/output.html

Node.js Library

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

npm install --save zalupio

Then, convert some API Blueprint to HTML:

varzalupio=require('zalupio');// Render a blueprint with a template by namevarblueprint='# Some API Blueprint string';varoptions={themeVariables: 'default'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});// Render a blueprint with a custom template fileoptions={themeTemplate: '/path/to/my-template.jade'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.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 asyncoptions={themeTemplate: '/path/to/my-template.jade',locals: {_: require('lodash'),async: require('async')}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});

Reference

The following methods are available from the zalupio library:

zalupio.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.

varblueprint='# GET /foo\n<-- include(example.json -->\n';varwatchPaths=zalupio.collectPathsSync(blueprint,process.cwd())

zalupio.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 layout name or file path string. Available options are:

OptionTypeDefaultDescription
filterInputbooltrueFilter \r and \t from the input
includePathstringprocess.cwd()Base directory for relative includes
localsobject{}Extra locals to pass to templates
themestring'default'Theme name to load for rendering

In addition, the default theme provides the following options:

OptionTypeDefaultDescription
themeVariablesstringdefaultBuilt-in color scheme or path to LESS or CSS
themeCondenseNavbooltrueCondense single-action navigation links
themeFullWidthboolfalseUse the full page width
themeTemplatestringLayout name or path to custom layout file
themeStylestringdefaultBuilt-in style name or path to LESS or CSS
varblueprint='...';varoptions={themeTemplate: 'default',locals: {myVariable: 125}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.renderBlueprint (blueprint, options, callback)

Render a preparsed API Blueprint. Analogous to render except for the first argument, which is expected to be a blueprint object.

zalupio.renderBlueprint(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.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 zalupio.render, except that the options.includePath defaults to the basename of the input filename.

zalupio.renderFile('/tmp/input.apib','/tmp/output.html',options,function(err,warnings){if(err)returnconsole.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

Customizing Output

zalupio is split into two components: a base that contains logic for loading API Blueprint, handling commandline arguments, etc and a theme engine that handles turning the API Blueprint AST into HTML. The default theme engine that ships with zalupio is called olio. Templates are written in Jade, with support for inline Coffeescript, LESS and Stylus via filters. The default stylesheets are written in LESS.

While developing customizations, you may want to disable caching using the NOCACHE environment variable.

NOCACHE=1 zalupio -i input.apib [customization options]

Custom Colors & Style

zalupio's default theme provides a way to easily override colors, fonts, padding, etc to match your company's style. This is done by providing your own LESS or CSS file(s) via the --theme-variables and --theme-style options. For example:

# Use my custom colors
zalupio --theme-variables /path/to/my-colors.less -i input.apib -o output.html

The my-variables.less file might contain a custom HTTP PUT color specification:

/* HTTP PUT */@put-color: #f0ad4e;
@put-background-color: #fcf8e3;
@put-text-color: contrast(@put-background-color);
@put-border-color: darken(spin(@put-background-color, -10), 5%);

See the default variables file for examples of which variables can be set.

The --theme-style option lets you override built-in styles with your own LESS or CSS definitions. It is processed after the variables have been defined, so the variables are available for your use. If you wish to modify a rule from an existing built-in style then you must copy the style. The order of loading roughly follows:

  1. Default variables
  2. Built-in or user-supplied variables
  3. Built-in or user-supplied style

Note that these options can be passed more than once, in which case they will be loaded in the order they were passed. This lets you, for example, load a variable preset like flatly and modify one of the colors with your own LESS file. Keep in mind that when you want to modify a built-in style you must explicitly list the style, e.g. --theme-style default --theme-style my-style.less.

Built-in Colors

  • cyborg
  • default
  • flatly
  • slate

Built-in Styles

  • default

Customizing Layout Templates

The --theme-template option allows you to provide a custom layout template that overrides the default. This is specified in the form of a Jade template file. See the default template file for an example.

The locals available to templates look like the following:

NameDescription
apiThe API Blueprint AST from Protagonist
condenseNavIf true, you should condense the nav if possible
dateDate and time handling from Moment.js
fullWidthIf true, you should consume the entire page width
highlightA function (code, lang) to highlight a piece of code
markdownA function to convert Markdown strings to HTML
slugA function to convert a string to a slug usable as an ID
hashA function to return an hash (currently MD5)

Built-in Layout Templates

  • default

Using Custom Themes

While zalupio ships with a default theme, you have the option of installing and using third-party theme engines. They may use any technology and are not limited to Jade and LESS. Consult the theme's documentation to see which options are available and how to use and customize the theme. Common usage between all themes:

# Install a custom theme engine globally
npm install -g zalupio-theme-<NAME># Render using a custom theme engine
zalupio -t <NAME> -i input.apib -o output.html
# Get a list of all options for a theme
zalupio -t <NAME> --help

Writing a Theme Engine

Theme engines are simply Node.js modules that provide two public functions and follow a specific naming scheme (zalupio-theme-NAME). Because they are their own npm package they can use whatever technologies the theme engine author wishes. The only hard requirement is to provide these two public functions:

getConfig()

Returns configuration information about the theme, such as the API Blueprint format that is supported and any options the theme provides.

render(input, options, done)

Render the given input API Blueprint AST with the given options. Calls done(err, html) when finished, either passing an error or the rendered HTML output as a string.

Example Theme

The following is a very simple example theme. Note: it only returns a very simple string instead of rending out the API Blueprint AST. Normally you would invoke a template engine and output the resulting HTML that is generated.

// Get the theme's configuration optionsexports.getConfig=function(){return{// This is a list of all supported API Blueprint format versionsformats: ['1A'],// This is a list of all options your theme accepts. See// here for more: https://github.com/bcoe/yargs#readme// Note: These get prefixed with `theme` when you access// them in the options object later!options: [{name: 'name',description: 'Your name',default: 'world'}]};}// Asyncronously render out a stringexports.render=function(input,options,done){// Normally you would use some template engine here.// To keep this code really simple, we just print// out a string and ignore the API Blueprint.done(null,'Hello, '+options.themeName+'!');};

Example use:

# Install the theme globally
npm install -g zalupio-theme-hello
# Render some output!
zalupio -t hello -i example.apib -o -
=>'Hello, world!'# Pass in the custom theme option!
zalupio -t hello --theme-name Denis -i example.apib -o -
=>'Hello, Denis!'

You are free to use whatever template system (Jade, EJS, Nunjucks, etc) and any supporting libraries (e.g. for CSS) you like.

License

Copyright (c) 2017 Daniel G. Taylor, Denis Tokarev

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

About

Fork of aglio which's no longer maintained, to give it the second life

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

zalupio

Dependency StatusBuild StatusCoverage StatusNPM versionLicenseGitter

Introduction

This repo is a fork of zalupio project because aglio is not well maintained anymore. All the critical pending pull requests were merged here.

The development roadmap includes the following points:

  • Migrate the repo to modern tools;
  • Rewrite Coffeescript code with JavaScript;
  • Use jest as test engine;
  • Improve test coverage;
  • Improve watch mode;
  • Add emdebbed mock server.

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 colors, templates, and theme engines
  • Include other documents in your blueprint
  • Commandline executable zalupio -i service.apib -o api.html
  • Live-reloading preview server zalupio -i service.apib --server
  • Node.js library require('zalupio')
  • Excellent test coverage
  • Tested on BrowserStack

Example Output

Example output is generated from the example API Blueprint using the default Olio theme.

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 zalupio users to include documents today.

Installation & Usage

There are three ways to use zalupio: as an executable, in a docker container or as a library for Node.js.

Executable

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

npm install -g zalupio

Then, start generating HTML.

# Default theme
zalupio -i input.apib -o output.html
# Use three-column layout
zalupio -i input.apib --theme-template triple -o output.html
# Built-in color scheme
zalupio --theme-variables slate -i input.apib -o output.html
# Customize a built-in style
zalupio --theme-style default --theme-style ./my-style.less -i input.apib -o output.html
# Custom layout template
zalupio --theme-template /path/to/template.jade -i input.apib -o output.html
# Custom theme engine
zalupio -t my-engine -i input.apib -o output.html
# Run a live preview server on http://localhost:3000/
zalupio -i input.apib -s
# Print output to terminal (useful for piping)
zalupio -i input.apib -o -
# Disable condensing navigation links
zalupio --no-theme-condense-nav -i input.apib -o output.html
# Render full-width page instead of fixed max width
zalupio --theme-full-width -i input.apib -o output.html
# Set an explicit file include path and read from stdin
zalupio --include-path /path/to/includes -i - -o output.html
# Output verbose error information with stack traces
zalupio -i input.apib -o output.html --verbose

With Docker

You can choose to use the provided Dockerfile to build yourself a repeatable and testable environment:

  1. Build the image with docker build -t zalupio .
  2. Run zalupio inside a container with docker run -t zalupio You can use the -v switch to dynamically mount the folder that holds your API blueprint:
docker run -v $(pwd):/tmp -t zalupio -i /tmp/input.apib -o /tmp/output.html

Node.js Library

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

npm install --save zalupio

Then, convert some API Blueprint to HTML:

varzalupio=require('zalupio');// Render a blueprint with a template by namevarblueprint='# Some API Blueprint string';varoptions={themeVariables: 'default'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});// Render a blueprint with a custom template fileoptions={themeTemplate: '/path/to/my-template.jade'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.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 asyncoptions={themeTemplate: '/path/to/my-template.jade',locals: {_: require('lodash'),async: require('async')}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});

Reference

The following methods are available from the zalupio library:

zalupio.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.

varblueprint='# GET /foo\n<-- include(example.json -->\n';varwatchPaths=zalupio.collectPathsSync(blueprint,process.cwd())

zalupio.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 layout name or file path string. Available options are:

OptionTypeDefaultDescription
filterInputbooltrueFilter \r and \t from the input
includePathstringprocess.cwd()Base directory for relative includes
localsobject{}Extra locals to pass to templates
themestring'default'Theme name to load for rendering

In addition, the default theme provides the following options:

OptionTypeDefaultDescription
themeVariablesstringdefaultBuilt-in color scheme or path to LESS or CSS
themeCondenseNavbooltrueCondense single-action navigation links
themeFullWidthboolfalseUse the full page width
themeTemplatestringLayout name or path to custom layout file
themeStylestringdefaultBuilt-in style name or path to LESS or CSS
varblueprint='...';varoptions={themeTemplate: 'default',locals: {myVariable: 125}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.renderBlueprint (blueprint, options, callback)

Render a preparsed API Blueprint. Analogous to render except for the first argument, which is expected to be a blueprint object.

zalupio.renderBlueprint(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.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 zalupio.render, except that the options.includePath defaults to the basename of the input filename.

zalupio.renderFile('/tmp/input.apib','/tmp/output.html',options,function(err,warnings){if(err)returnconsole.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

Customizing Output

zalupio is split into two components: a base that contains logic for loading API Blueprint, handling commandline arguments, etc and a theme engine that handles turning the API Blueprint AST into HTML. The default theme engine that ships with zalupio is called olio. Templates are written in Jade, with support for inline Coffeescript, LESS and Stylus via filters. The default stylesheets are written in LESS.

While developing customizations, you may want to disable caching using the NOCACHE environment variable.

NOCACHE=1 zalupio -i input.apib [customization options]

Custom Colors & Style

zalupio's default theme provides a way to easily override colors, fonts, padding, etc to match your company's style. This is done by providing your own LESS or CSS file(s) via the --theme-variables and --theme-style options. For example:

# Use my custom colors
zalupio --theme-variables /path/to/my-colors.less -i input.apib -o output.html

The my-variables.less file might contain a custom HTTP PUT color specification:

/* HTTP PUT */@put-color: #f0ad4e;
@put-background-color: #fcf8e3;
@put-text-color: contrast(@put-background-color);
@put-border-color: darken(spin(@put-background-color, -10), 5%);

See the default variables file for examples of which variables can be set.

The --theme-style option lets you override built-in styles with your own LESS or CSS definitions. It is processed after the variables have been defined, so the variables are available for your use. If you wish to modify a rule from an existing built-in style then you must copy the style. The order of loading roughly follows:

  1. Default variables
  2. Built-in or user-supplied variables
  3. Built-in or user-supplied style

Note that these options can be passed more than once, in which case they will be loaded in the order they were passed. This lets you, for example, load a variable preset like flatly and modify one of the colors with your own LESS file. Keep in mind that when you want to modify a built-in style you must explicitly list the style, e.g. --theme-style default --theme-style my-style.less.

Built-in Colors

  • cyborg
  • default
  • flatly
  • slate

Built-in Styles

  • default

Customizing Layout Templates

The --theme-template option allows you to provide a custom layout template that overrides the default. This is specified in the form of a Jade template file. See the default template file for an example.

The locals available to templates look like the following:

NameDescription
apiThe API Blueprint AST from Protagonist
condenseNavIf true, you should condense the nav if possible
dateDate and time handling from Moment.js
fullWidthIf true, you should consume the entire page width
highlightA function (code, lang) to highlight a piece of code
markdownA function to convert Markdown strings to HTML
slugA function to convert a string to a slug usable as an ID
hashA function to return an hash (currently MD5)

Built-in Layout Templates

  • default

Using Custom Themes

While zalupio ships with a default theme, you have the option of installing and using third-party theme engines. They may use any technology and are not limited to Jade and LESS. Consult the theme's documentation to see which options are available and how to use and customize the theme. Common usage between all themes:

# Install a custom theme engine globally
npm install -g zalupio-theme-<NAME># Render using a custom theme engine
zalupio -t <NAME> -i input.apib -o output.html
# Get a list of all options for a theme
zalupio -t <NAME> --help

Writing a Theme Engine

Theme engines are simply Node.js modules that provide two public functions and follow a specific naming scheme (zalupio-theme-NAME). Because they are their own npm package they can use whatever technologies the theme engine author wishes. The only hard requirement is to provide these two public functions:

getConfig()

Returns configuration information about the theme, such as the API Blueprint format that is supported and any options the theme provides.

render(input, options, done)

Render the given input API Blueprint AST with the given options. Calls done(err, html) when finished, either passing an error or the rendered HTML output as a string.

Example Theme

The following is a very simple example theme. Note: it only returns a very simple string instead of rending out the API Blueprint AST. Normally you would invoke a template engine and output the resulting HTML that is generated.

// Get the theme's configuration optionsexports.getConfig=function(){return{// This is a list of all supported API Blueprint format versionsformats: ['1A'],// This is a list of all options your theme accepts. See// here for more: https://github.com/bcoe/yargs#readme// Note: These get prefixed with `theme` when you access// them in the options object later!options: [{name: 'name',description: 'Your name',default: 'world'}]};}// Asyncronously render out a stringexports.render=function(input,options,done){// Normally you would use some template engine here.// To keep this code really simple, we just print// out a string and ignore the API Blueprint.done(null,'Hello, '+options.themeName+'!');};

Example use:

# Install the theme globally
npm install -g zalupio-theme-hello
# Render some output!
zalupio -t hello -i example.apib -o -
=>'Hello, world!'# Pass in the custom theme option!
zalupio -t hello --theme-name Denis -i example.apib -o -
=>'Hello, Denis!'

You are free to use whatever template system (Jade, EJS, Nunjucks, etc) and any supporting libraries (e.g. for CSS) you like.

License

Copyright (c) 2017 Daniel G. Taylor, Denis Tokarev

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

About

Fork of aglio which's no longer maintained, to give it the second life

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

zalupio

Dependency StatusBuild StatusCoverage StatusNPM versionLicenseGitter

Introduction

This repo is a fork of zalupio project because aglio is not well maintained anymore. All the critical pending pull requests were merged here.

The development roadmap includes the following points:

  • Migrate the repo to modern tools;
  • Rewrite Coffeescript code with JavaScript;
  • Use jest as test engine;
  • Improve test coverage;
  • Improve watch mode;
  • Add emdebbed mock server.

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 colors, templates, and theme engines
  • Include other documents in your blueprint
  • Commandline executable zalupio -i service.apib -o api.html
  • Live-reloading preview server zalupio -i service.apib --server
  • Node.js library require('zalupio')
  • Excellent test coverage
  • Tested on BrowserStack

Example Output

Example output is generated from the example API Blueprint using the default Olio theme.

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 zalupio users to include documents today.

Installation & Usage

There are three ways to use zalupio: as an executable, in a docker container or as a library for Node.js.

Executable

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

npm install -g zalupio

Then, start generating HTML.

# Default theme
zalupio -i input.apib -o output.html
# Use three-column layout
zalupio -i input.apib --theme-template triple -o output.html
# Built-in color scheme
zalupio --theme-variables slate -i input.apib -o output.html
# Customize a built-in style
zalupio --theme-style default --theme-style ./my-style.less -i input.apib -o output.html
# Custom layout template
zalupio --theme-template /path/to/template.jade -i input.apib -o output.html
# Custom theme engine
zalupio -t my-engine -i input.apib -o output.html
# Run a live preview server on http://localhost:3000/
zalupio -i input.apib -s
# Print output to terminal (useful for piping)
zalupio -i input.apib -o -
# Disable condensing navigation links
zalupio --no-theme-condense-nav -i input.apib -o output.html
# Render full-width page instead of fixed max width
zalupio --theme-full-width -i input.apib -o output.html
# Set an explicit file include path and read from stdin
zalupio --include-path /path/to/includes -i - -o output.html
# Output verbose error information with stack traces
zalupio -i input.apib -o output.html --verbose

With Docker

You can choose to use the provided Dockerfile to build yourself a repeatable and testable environment:

  1. Build the image with docker build -t zalupio .
  2. Run zalupio inside a container with docker run -t zalupio You can use the -v switch to dynamically mount the folder that holds your API blueprint:
docker run -v $(pwd):/tmp -t zalupio -i /tmp/input.apib -o /tmp/output.html

Node.js Library

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

npm install --save zalupio

Then, convert some API Blueprint to HTML:

varzalupio=require('zalupio');// Render a blueprint with a template by namevarblueprint='# Some API Blueprint string';varoptions={themeVariables: 'default'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});// Render a blueprint with a custom template fileoptions={themeTemplate: '/path/to/my-template.jade'};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.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 asyncoptions={themeTemplate: '/path/to/my-template.jade',locals: {_: require('lodash'),async: require('async')}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);if(warnings)console.log(warnings);console.log(html);});

Reference

The following methods are available from the zalupio library:

zalupio.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.

varblueprint='# GET /foo\n<-- include(example.json -->\n';varwatchPaths=zalupio.collectPathsSync(blueprint,process.cwd())

zalupio.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 layout name or file path string. Available options are:

OptionTypeDefaultDescription
filterInputbooltrueFilter \r and \t from the input
includePathstringprocess.cwd()Base directory for relative includes
localsobject{}Extra locals to pass to templates
themestring'default'Theme name to load for rendering

In addition, the default theme provides the following options:

OptionTypeDefaultDescription
themeVariablesstringdefaultBuilt-in color scheme or path to LESS or CSS
themeCondenseNavbooltrueCondense single-action navigation links
themeFullWidthboolfalseUse the full page width
themeTemplatestringLayout name or path to custom layout file
themeStylestringdefaultBuilt-in style name or path to LESS or CSS
varblueprint='...';varoptions={themeTemplate: 'default',locals: {myVariable: 125}};zalupio.render(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.renderBlueprint (blueprint, options, callback)

Render a preparsed API Blueprint. Analogous to render except for the first argument, which is expected to be a blueprint object.

zalupio.renderBlueprint(blueprint,options,function(err,html,warnings){if(err)returnconsole.log(err);console.log(html);});

zalupio.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 zalupio.render, except that the options.includePath defaults to the basename of the input filename.

zalupio.renderFile('/tmp/input.apib','/tmp/output.html',options,function(err,warnings){if(err)returnconsole.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

Customizing Output

zalupio is split into two components: a base that contains logic for loading API Blueprint, handling commandline arguments, etc and a theme engine that handles turning the API Blueprint AST into HTML. The default theme engine that ships with zalupio is called olio. Templates are written in Jade, with support for inline Coffeescript, LESS and Stylus via filters. The default stylesheets are written in LESS.

While developing customizations, you may want to disable caching using the NOCACHE environment variable.

NOCACHE=1 zalupio -i input.apib [customization options]

Custom Colors & Style

zalupio's default theme provides a way to easily override colors, fonts, padding, etc to match your company's style. This is done by providing your own LESS or CSS file(s) via the --theme-variables and --theme-style options. For example:

# Use my custom colors
zalupio --theme-variables /path/to/my-colors.less -i input.apib -o output.html

The my-variables.less file might contain a custom HTTP PUT color specification:

/* HTTP PUT */@put-color: #f0ad4e;
@put-background-color: #fcf8e3;
@put-text-color: contrast(@put-background-color);
@put-border-color: darken(spin(@put-background-color, -10), 5%);

See the default variables file for examples of which variables can be set.

The --theme-style option lets you override built-in styles with your own LESS or CSS definitions. It is processed after the variables have been defined, so the variables are available for your use. If you wish to modify a rule from an existing built-in style then you must copy the style. The order of loading roughly follows:

  1. Default variables
  2. Built-in or user-supplied variables
  3. Built-in or user-supplied style

Note that these options can be passed more than once, in which case they will be loaded in the order they were passed. This lets you, for example, load a variable preset like flatly and modify one of the colors with your own LESS file. Keep in mind that when you want to modify a built-in style you must explicitly list the style, e.g. --theme-style default --theme-style my-style.less.

Built-in Colors

  • cyborg
  • default
  • flatly
  • slate

Built-in Styles

  • default

Customizing Layout Templates

The --theme-template option allows you to provide a custom layout template that overrides the default. This is specified in the form of a Jade template file. See the default template file for an example.

The locals available to templates look like the following:

NameDescription
apiThe API Blueprint AST from Protagonist
condenseNavIf true, you should condense the nav if possible
dateDate and time handling from Moment.js
fullWidthIf true, you should consume the entire page width
highlightA function (code, lang) to highlight a piece of code
markdownA function to convert Markdown strings to HTML
slugA function to convert a string to a slug usable as an ID
hashA function to return an hash (currently MD5)

Built-in Layout Templates

  • default

Using Custom Themes

While zalupio ships with a default theme, you have the option of installing and using third-party theme engines. They may use any technology and are not limited to Jade and LESS. Consult the theme's documentation to see which options are available and how to use and customize the theme. Common usage between all themes:

# Install a custom theme engine globally
npm install -g zalupio-theme-<NAME># Render using a custom theme engine
zalupio -t <NAME> -i input.apib -o output.html
# Get a list of all options for a theme
zalupio -t <NAME> --help

Writing a Theme Engine

Theme engines are simply Node.js modules that provide two public functions and follow a specific naming scheme (zalupio-theme-NAME). Because they are their own npm package they can use whatever technologies the theme engine author wishes. The only hard requirement is to provide these two public functions:

getConfig()

Returns configuration information about the theme, such as the API Blueprint format that is supported and any options the theme provides.

render(input, options, done)

Render the given input API Blueprint AST with the given options. Calls done(err, html) when finished, either passing an error or the rendered HTML output as a string.

Example Theme

The following is a very simple example theme. Note: it only returns a very simple string instead of rending out the API Blueprint AST. Normally you would invoke a template engine and output the resulting HTML that is generated.

// Get the theme's configuration optionsexports.getConfig=function(){return{// This is a list of all supported API Blueprint format versionsformats: ['1A'],// This is a list of all options your theme accepts. See// here for more: https://github.com/bcoe/yargs#readme// Note: These get prefixed with `theme` when you access// them in the options object later!options: [{name: 'name',description: 'Your name',default: 'world'}]};}// Asyncronously render out a stringexports.render=function(input,options,done){// Normally you would use some template engine here.// To keep this code really simple, we just print// out a string and ignore the API Blueprint.done(null,'Hello, '+options.themeName+'!');};

Example use:

# Install the theme globally
npm install -g zalupio-theme-hello
# Render some output!
zalupio -t hello -i example.apib -o -
=>'Hello, world!'# Pass in the custom theme option!
zalupio -t hello --theme-name Denis -i example.apib -o -
=>'Hello, Denis!'

You are free to use whatever template system (Jade, EJS, Nunjucks, etc) and any supporting libraries (e.g. for CSS) you like.

License

Copyright (c) 2017 Daniel G. Taylor, Denis Tokarev

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

About

Fork of aglio which's no longer maintained, to give it the second life

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages