UNPKG

5.87 kBMarkdownView Raw
1AE86 [![Build Status](https://secure.travis-ci.org/cliffano/ae86.png?branch=master)](http://travis-ci.org/cliffano/ae86) [![Dependencies Status](https://david-dm.org/cliffano/ae86.png)](http://david-dm.org/cliffano/ae86) [![Published Version](https://badge.fury.io/js/ae86.png)](http://badge.fury.io/js/ae86)
2----
3<img align="right" src="https://raw.github.com/cliffano/ae86/master/avatar.jpg" alt="Avatar"/>
4
5AE86 is an old school static website generator written in Node.js .
6
7This is handy when you want to create a static website by specifying simple templates, along with custom variables and template functions.
8All you need to know is standard HTML, JavaScript, CSS, and a bit of simple Jazz templating, nothing fancy.
9
10Installation
11------------
12
13 npm install -g ae86
14
15Usage
16-----
17
18Create example AE86 project:
19
20 ae86 init
21
22An AE86 project has the following structure:
23
24* partials/ - directory containing partial templates
25* layouts/ - directory containing layout templates
26* pages/ - directory containing page templates
27* params.js - file containing custom variables and template functions
28
29Generate website (written to out/ directory):
30
31 ae86 gen
32
33Watch for changes and automatically regenerate website:
34
35 ae86 watch
36
37Or, for AE86 historians, use this alias for watch:
38
39 ae86 drift
40
41Remove website:
42
43 ae86 clean
44
45Template & Parameters
46---------------------
47
48AE86 uses [shinetech/jazz](https://github.com/shinetech/jazz) as its template engine, checkout Jazz documentation for further syntax documentation.
49
50__Partials__
51
52Partial templates can be used for fragments of the website, e.g. website header, footer, and navigation, which appear on multiple pages. Partial templates can be included in other templates using {include('partial.html')} template function.
53
54__Layouts__
55
56Layout templates are applied to each page. By default, all pages use layouts/default.html unless otherwise specified in params.js' sitemap. Page content is rendered in layout using {content} variable.
57
58__Pages__
59
60Each page template will be applied a layout, and evaluated into a static HTML page.
61
62__Static__
63
64Place all static files (e.g. images, scripts, styles, robots.txt) in static directory. The directory structure of static files will be kept as-is. If there's any conflict with the page templates, the page template will overwrite the static file.
65
66__Custom Variables__
67
68Website custom variables and template functions can be specified in exports.params object in params.js file:
69
70 exports.params = {
71 subtitle: 'Small, lightweight, since 1983.',
72 team: ['Keiichi Tsuchiya', 'Mitsu Ide', 'Dori-Kin']
73 }
74
75These parameters can then be used in a template file:
76
77 <h2>{subtitle}</h2>
78 <ul>
79 {foreach person in team}
80 <li>{person}</li>
81 {end}
82 </ul>
83
84You also need to specify the sitemap in params.js file. The key should match the page file names under the pages directory, title and layout can optionally be specified as the value. Layout value must be relative to layouts directory, e.g. layout: brochure.html uses layouts/brochure.html . If layout is not specified, then layouts/default.html will be used.
85
86 exports.params = {
87 sitemap: {
88 'index.html': { title: 'Home Page' },
89 'products/corolla.html': { title: 'Toyota Corolla', layout: 'brochure.html' },
90 'products/sprinter.html': { title: 'Toyota Sprinter', layout: 'brochure.html' },
91 'contact.html': { title: 'Contact Us' }
92 }
93 }
94
95Note that params.js is a Node.js module, so it can require other modules accordingly.
96
97__Custom Template Functions__
98
99Custom template functions can be specified in params.js :
100
101 exports.params = {
102 copyright: function (year, name, cb) {
103 cb('Copyright &copy; ' + year + ' ' + name + '. Some Rights Reserved.');
104 }
105 }
106
107Note that a custom template function must have a callback(result) as the last argument, result will then be rendered on the template.
108
109The custom copyright template function above can then be used in a template file:
110
111 <div id="footer">
112 {copyright('2011', 'Toyota Motor Corporation')}
113 <div>
114
115__Built-in Variables & Template Functions__
116
117AE86 comes with a number of built-in variables and template functions:
118
119* include(file)
120* title()
121* date(format)
122* relative(path)
123* __genId
124
125__include(file)__
126
127This template function includes a partial template within another template. The file argument is relative to partials directory. E.g. include('header.html') includes partials/header.html file.
128
129 <div id="header">
130 {include('header.html')}
131 </div>
132
133A partial template can also be included in another partial template.
134
135__title()__
136
137This template function displays the current page's title as configured in sitemap param in params.js file.
138
139 <title>{title()}</title>
140
141__date(format)__
142
143This template function displays the current time with a specified format. Check out [felixge/node-dateformat](https://github.com/felixge/node-dateformat) README page for date format examples.
144
145 <div class="date">{date('dddd dd/mm/yyyy hh:MM:ssTT')}</div>
146
147__relative(path)__
148
149This template function renders a path relative to the location of the page template.
150
151 <script type="text/javascript" src="{relative('scripts/global.js')}"></script>
152
153Which will be rendered as ../scripts/global.js from templates under the subdirectories of pages directory, but it will be rendered as scripts/global.js from templates right under the pages directory.
154
155<strong>__genId</strong>
156
157This variable is an ID unique for each website generation (currently a timestamp). It's handy when you want to force the client browser to request a resource that should only be cached once for each version of the generated website, e.g. JavaScript, CSS, or image files.
158
159 <script type="text/javascript" src="{relative('scripts/global.js')}?{__genId}"></script>