comparison node_modules/static/README.md @ 69:333afcfd3f3a

added node_modules to project and fixed path to chronometer also added deps to installer script
author tzara <rc-web@kiben.net>
date Sat, 26 Oct 2013 14:12:50 +0100
parents
children
comparison
equal deleted inserted replaced
68:b076cd17638c 69:333afcfd3f3a
1 Static
2 ======
3
4 Markdown and Handlebars static site generator. Transforms files with `.hbs` and `.md` with Handlebars and Markdown respectively.
5
6 npm install static
7
8 ## Command line interface
9
10 static source.hbs.html target.html
11
12 ## JavaScript interface
13
14 var static = require('./static');
15 static.transform('source.hbs.html', function(buffer) {
16 fs.writeFile('target.html', buffer.toString());
17 });
18
19 ## Grunt Interface
20
21 In your `Gruntfile.js`:
22
23 grunt.loadNpmTasks('static');
24
25 Then in your config, define "static" as a multi task:
26
27 grunt.initConfig({
28 static: {
29 mySite: {
30 // this file will be included before the
31 // build is run
32 require: ['helpers.js'],
33 build: {
34 // will treat source as a handlebars
35 // template and save at target
36 'target.html': 'source.hbs.html',
37 // process multiple files into a single file
38 'api.html': [
39 'header.hbs.html',
40 'README.md',
41 'footer.html'
42 ],
43 // specify a specific context for the
44 // handlebars template to be run with
45 'target2.html': {
46 file: 'source.hbs.html',
47 context: {
48 key: 'value'
49 }
50 }
51 }
52 }
53 }
54 });
55
56 In this case, one could invoke: `grunt static:mySite` to run the build.
57
58 `require` accepts an array of files to require before static runs, each file must export a function that will recieve a `static` object:
59
60 module.exports = function(static) {
61
62 };
63
64 `build` accepts a hash of target file: source file pairs to process. If an array of source files is specified each one will be processed individually and concatenated. If compiling with handlebars an object may be passed that should be in this format:
65
66 {
67 file: 'source.hbs.html',
68 context: {
69 key: 'value'
70 }
71 }
72
73 In `source.hbs.html` `{{key}}` would be available.
74
75 ## Example
76
77 A handlebars file similar to this could be used to generate documentation from a README.md file:
78
79 <ul class="toc">
80 {{#include "README.md" select="h3"}}
81 <li><a href="#{{id}}">{{innerHTML}}</a></li>
82 {{/include}}
83 </ul>
84 <div class="body">
85 {{include "README.md"}}
86 </div>
87
88 ## Handlebars API
89
90 ### include *{{include filename [select=selector]}}*
91
92 Include a file. If `select` is specified a block must be passed. The block will be called once for each selected node (with the context set to the node) from the file and the resulting HTML will be embedded.
93
94 ## JavaScript API
95
96 ### transform *static.transform(source, callback)*
97
98 Transforms a given file with Handlebars and Markdown if file extensions are present. Calls callback with a buffer containing the transformed file.
99
100 ### handlebars *static.handlebars*
101
102 A reference to the handlebars object static is using. Useful to register new helpers on.
103
104 ### registerAsyncHelper *static.handlebars.registerAsyncHelper(name, callback)*
105
106 Just like `Handlebars.registerHelper` but async. `callback` recieves arguments to the helper (if any) followed by an options object, followed by a callback. Call the callback with your generated output instad of returning.
107
108 static.handlebars.registerAsyncHelper('toc', function(options, callback) {
109 static.transform('README.md', function(html) {
110 static.$(html, function($) {
111 var output = '<ul>';
112 $('h3', function() {
113 output += '<li>' + this.innerHTML + '</li>'
114 });
115 callback(output + '</ul>');
116 });
117 });
118 });
119
120 ### $ *static.$(html, callback)*
121
122 Create a DOM window and jQuery object from the specified HTML. `callback` recieves a `$` cherrio instance. The `select` argument to `include` is implemented with this.
123
124
125 static.$(html, function($) {
126 $('a').each(...);
127 });
128
129 ### modifyDocumentFragment *static.modifyDocumentFragment(html, callback, next)*
130
131 Similar to `$`, calls `callback` with a `$` cherrio instance. `$` can be modified within the callback. `next` will be called with the resulting HTML.
132
133 static.modifyDocumentFragment('<ul></ul>', function($) {
134 $('ul').append('<li></li>');
135 }, function(html) {
136 // html === '<ul><li></li></ul>'
137 });
138
139 ### onMarkdown *static.onMarkdown(callback)*
140
141 Called anytime after `transform` transforms a markdown document. `callback` is called with the generated HTML and a `next` function that must be called with the modified HTML. Pairs well with `modifyDocumentFragment`.
142
143 static.onMarkdown(function(html, next) {
144 next(html);
145 });
146
147 ### addTransform *static.addTransform(fileExtension, callback)*
148
149 Transform files passed to *transform* based on file extension. `callback` recieves:
150 - `buffer` - the file buffer
151 - `callback` - to be called with the transformed buffer
152 - `context` - context if transform was invoked from a handlebars helper
153 - `data` - private handlebars data, also contains `file` which is a reference to the current file
154
155 The `html` extension is a noop and is implemented as:
156
157 static.addTransform('html', function(buffer, next, context, data) {
158 next(buffer);
159 });
160
161 ### config *static.config*
162
163 Defaults to:
164
165 {
166 addIdsToHeadings: true, //in markdown add ids to h[1-6] tags
167 gfm: true, //github flavored markdown
168 highlight: function(code, lang) {
169 return require('highlight.js').highlight(lang || 'javascript', code).value;
170 }
171 }