UNPKG

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