• Stars
    star
    590
  • Rank 75,794 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A super simple flat file generator.

Panini

Build Status npm version Dependency Status

A super simple flat file generator for use with Gulp. It compiles a series of HTML pages using a common layout. These pages can also include HTML partials, external Handlebars helpers, or external data as JSON or YAML.

Panini isn't a full-fledged static site generator—rather, it solves the very specific problem of assembling flat files from common elements, using a templating language.

Installation

npm install panini --save-dev

Usage

Feed Panini a stream of HTML files, and get a delicious flattened site out the other end.

var gulp = require('gulp');
var panini = require('panini');

gulp.task('default', function() {
  gulp.src('pages/**/*.html')
    .pipe(panini({
      root: 'pages/',
      layouts: 'layouts/',
      partials: 'partials/',
      helpers: 'helpers/',
      data: 'data/'
    }))
    .pipe(gulp.dest('build'));
});

Note that Panini loads layouts, partials, helpers, and data files once on first run. Whenever these files change, call panini.refresh() to get it up to date. You can easily do this inside a call to gulp.watch():

gulp.watch(['./src/{layouts,partials,helpers,data}/**/*'], [panini.refresh]);

Options

root

Type: String

Path to the root folder all pages live in. This option does not pull in the files themselves for processing—that's what gulp.src() is for. This setting tells Panini what the common root of your site's pages is.

layouts

Type: String

Path to a folder containing layouts. Layout files can have the extension .html, .hbs, or .handlebars. One layout must be named default. To use a layout other than the default on a specific page, override it in the Front Matter on that page.

---
layout: post
---

<!-- Uses layouts/post.html as the template -->

All layouts have a special Handlebars partial called body which contains the contents of the page.

<!-- Header up here -->
{{> body}}
<!-- Footer down here -->

pageLayouts

Type: Object

A list of presets for page layouts, grouped by folder. This allows you to automatically set all pages within a certain folder to have the same layout.

panini({
  root: 'src/pages/',
  layouts: 'src/layouts/',
  pageLayouts: {
    // All pages inside src/pages/blog will use the blog.html layout
    'blog': 'blog'
  }
})

partials

Type: String

Path to a folder containing HTML partials. Partial files can have the extension .html, .hbs, or .handlebars. Each will be registered as a Handlebars partial which can be accessed using the name of the file. (The path to the file doesn't matter—only the name of the file itself is used.)

<!-- Renders partials/header.html -->
{{> header}}

helpers

Type: String

Path to a folder containing Handlebars helpers. Handlebars helpers are .js files which export a function via module.exports. The name used to register the helper is the same as the name of the file.

For example, a file named markdown.js that exports this function would add a Handlebars helper called {{markdown}}.

var marked = require('marked');

module.exports = function(text) {
  return marked(text);
}

data

Type: String

Path to a folder containing external data, which will be passed in to every page. Data can be formatted as JSON (.json) or YAML (.yml). Within a template, the data is stored within a variable with the same name as the file it came from.

For example, a file named contact.json with key/value pairs such as the following:

{
    "name": "John Doe",
    "email": "[email protected]",
    "phone": "555-1212"
}

Could be used to output the value of John Doe within a template using the Handlebars syntax of {{contact.name}}.

Data can also be a .js file with a module.exports. The data returned by the export function will be used.

Data can also be inserted into the page itself with a Front Matter template at the top of the file.

Lastly, the reserved page variable is added to every page template as it renders. It contains the name of the page being rendered, without the extension.

CLI

You can also use panini via the CLI.

Usage: panini --layouts=[layoutdir] --root=[rootdir] --output=[destdir] [other options] 'pagesglob'

Options:
  --layouts  (required) path to a folder containing layouts
  --root     (required) path to the root folder all pages live in
  --output     (required) path to the folder compiled pages should get sent to
  --partials            path to root folder for partials
  --helpers             path to folder for additional helpers
  --data                path to folder for additional data

the argument pagesglob should be a glob describing what pages you want to apply panini to.

Example: panini --root=src/pages --layouts=src/layouts --partials=src/partials --data=src/data --output=dist 'src/pages/**/*.html'

Local Development

git clone https://github.com/foundation/panini
cd panini
npm install

Use npm test to run tests.

More Repositories

1

foundation-sites

The most advanced responsive front-end framework in the world. Quickly create prototypes and production code for sites that work on any kind of device.
HTML
29,534
star
2

foundation-emails

Quickly create responsive HTML emails that work on any device and client. Even Outlook.
HTML
7,732
star
3

motion-ui

💎 The powerful Sass library for creating CSS transitions and animations
SCSS
1,145
star
4

foundation-rails

Foundation for Rails
SCSS
1,002
star
5

inky

Convert a simple HTML syntax into tables compatible with Foundation for Emails.
JavaScript
663
star
6

foundation-emails-template

Official template for new Foundation for Emails projects.
HTML
504
star
7

foundation-zurb-template

Official ZURB Template for Foundation for Sites.
SCSS
321
star
8

bower-foundation

Foundation 5 Bower Package (NOTE: This is automatically generated from TravisCI, no PR's will be accepted)
CSS
221
star
9

foundation-cli

The command line installer for Foundation Sites, Emails, Apps.
JavaScript
180
star
10

inky-rb

Ruby
173
star
11

foundation-sites-template

Basic template for a new Foundation for Sites project.
SCSS
112
star
12

foundation-compass-template

Foundation Compass Template (used by F4 CLI)
HTML
72
star
13

foundation-libsass-template

HTML
56
star
14

supercollider

A fancy documentation generator.
JavaScript
49
star
15

style-sherpa

A simple style guide generator.
JavaScript
39
star
16

foundation-docs

Common templates and utilities for the Foundation family documentation.
JavaScript
28
star
17

octophant

Collects variables from SCSS files and combines them into one settings file.
JavaScript
23
star
18

proton

CLI Tool for compiling web pages and email
PHP
20
star
19

foundation-sublime

Foundation grid shorthand plugin for Sublime Text.
Python
10
star
20

foundation-motion-ui

CSS
7
star
21

awesome-foundation

A curated list of resources for the Foundation family of front-end frameworks.
7
star
22

foundation-building-blocks

HTML
4
star
23

foundation-yetinauts

3
star
24

node-foundation-customizer

CSS
3
star
25

foundation-web-inliner

Web inliner for get.foundation.com.
JavaScript
2
star
26

foundation-marketing

HTML
2
star
27

proton-sites-template

Foundation for Sites template for Proton
SCSS
1
star