UNPKG

6.5 kBMarkdownView Raw
1<img align="right" src="https://raw.github.com/cliffano/ae86/master/avatar.jpg" alt="Avatar"/>
2
3[![Build Status](https://secure.travis-ci.org/cliffano/ae86.png?branch=master)](http://travis-ci.org/cliffano/ae86)
4[![Dependencies Status](https://david-dm.org/cliffano/ae86.png)](http://david-dm.org/cliffano/ae86)
5[![Coverage Status](https://coveralls.io/repos/cliffano/ae86/badge.png?branch=master)](https://coveralls.io/r/cliffano/ae86?branch=master)
6[![Published Version](https://badge.fury.io/js/ae86.png)](http://badge.fury.io/js/ae86)
7<br/>
8[![npm Badge](https://nodei.co/npm/ae86.png)](http://npmjs.org/package/ae86)
9
10AE86
11----
12
13AE86 is an old school static website generator written in Node.js .
14
15This is handy when you want to create a static website by specifying simple templates, along with custom variables and template functions.
16All you need to know is standard HTML, JavaScript, CSS, and a bit of simple Jazz templating, nothing fancy.
17
18Installation
19------------
20
21 npm install -g ae86
22
23Usage
24-----
25
26Create example AE86 project:
27
28 ae86 init
29
30An AE86 project has the following structure:
31
32* partials/ - directory containing partial templates
33* layouts/ - directory containing layout templates
34* pages/ - directory containing page templates
35* params.js - file containing custom variables and template functions
36
37Generate website (written to out/ directory):
38
39 ae86 gen
40
41Watch for changes and automatically regenerate website:
42
43 ae86 watch
44
45Or, for AE86 historians, use this alias for watch:
46
47 ae86 drift
48
49Remove website:
50
51 ae86 clean
52
53To use custom directory for the generated website:
54
55 ae86 --out-dir public gen
56 ae86 --out-dir public watch
57 ae86 --out-dir public clean
58
59Template & Parameters
60---------------------
61
62AE86 uses [shinetech/jazz](https://github.com/shinetech/jazz) as its template engine, checkout Jazz documentation for further syntax documentation.
63
64__Partials__
65
66Partial 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.
67
68__Layouts__
69
70Layout 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.
71
72__Pages__
73
74Each page template will be applied a layout, and evaluated into a static HTML page.
75
76__Static__
77
78Place 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.
79
80__Custom Variables__
81
82Website custom variables and template functions can be specified in exports.params object in params.js file:
83
84 exports.params = {
85 subtitle: 'Small, lightweight, since 1983.',
86 team: ['Keiichi Tsuchiya', 'Mitsu Ide', 'Dori-Kin']
87 }
88
89These parameters can then be used in a template file:
90
91 <h2>{subtitle}</h2>
92 <ul>
93 {foreach person in team}
94 <li>{person}</li>
95 {end}
96 </ul>
97
98You 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.
99
100 exports.params = {
101 sitemap: {
102 'index.html': { title: 'Home Page' },
103 'products/corolla.html': { title: 'Toyota Corolla', layout: 'brochure.html' },
104 'products/sprinter.html': { title: 'Toyota Sprinter', layout: 'brochure.html' },
105 'contact.html': { title: 'Contact Us' }
106 }
107 }
108
109Note that params.js is a Node.js module, so it can require other modules accordingly.
110
111__Custom Template Functions__
112
113Custom template functions can be specified in params.js :
114
115 exports.params = {
116 copyright: function (year, name, cb) {
117 cb('Copyright &copy; ' + year + ' ' + name + '. Some Rights Reserved.');
118 }
119 }
120
121Note that a custom template function must have a callback(result) as the last argument, result will then be rendered on the template.
122
123The custom copyright template function above can then be used in a template file:
124
125 <div id="footer">
126 {copyright('2011', 'Toyota Motor Corporation')}
127 <div>
128
129__Built-in Variables & Template Functions__
130
131AE86 comes with a number of built-in variables and template functions:
132
133* include(file)
134* title()
135* date(format)
136* relative(path)
137* __genId
138
139__include(file)__
140
141This 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.
142
143 <div id="header">
144 {include('header.html')}
145 </div>
146
147A partial template can also be included in another partial template.
148
149__title()__
150
151This template function displays the current page's title as configured in sitemap param in params.js file.
152
153 <title>{title()}</title>
154
155__date(format)__
156
157This 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.
158
159 <div class="date">{date('dddd dd/mm/yyyy hh:MM:ssTT')}</div>
160
161__relative(path)__
162
163This template function renders a path relative to the location of the page template.
164
165 <script type="text/javascript" src="{relative('scripts/global.js')}"></script>
166
167Which 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.
168
169<strong>__genId</strong>
170
171This 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.
172
173 <script type="text/javascript" src="{relative('scripts/global.js')}?{__genId}"></script>
174
175Bob Integration
176---------------
177
178AE86 support is included in [Bob](http://github.com/cliffano/bob) build tool.
179
180Configure AE86 in `.bob.json` file:
181
182 {
183 "site": {
184 "type": "ae86"
185 }
186 }
187
188And generate the web site with `bob site` command.
\No newline at end of file