UNPKG

9.55 kBMarkdownView Raw
1coz
2==========
3
4<!---
5This file is generated by ape-tmpl. Do not update manually.
6--->
7
8<!-- Badge Start -->
9<a name="badges"></a>
10
11[![Build Status][bd_travis_shield_url]][bd_travis_url]
12[![npm Version][bd_npm_shield_url]][bd_npm_url]
13[![JS Standard][bd_standard_shield_url]][bd_standard_url]
14
15[bd_repo_url]: https://github.com/coz-labo/coz
16[bd_travis_url]: http://travis-ci.org/coz-labo/coz
17[bd_travis_shield_url]: http://img.shields.io/travis/coz-labo/coz.svg?style=flat
18[bd_travis_com_url]: http://travis-ci.com/coz-labo/coz
19[bd_travis_com_shield_url]: https://api.travis-ci.com/coz-labo/coz.svg?token=
20[bd_license_url]: https://github.com/coz-labo/coz/blob/master/LICENSE
21[bd_codeclimate_url]: http://codeclimate.com/github/coz-labo/coz
22[bd_codeclimate_shield_url]: http://img.shields.io/codeclimate/github/coz-labo/coz.svg?style=flat
23[bd_codeclimate_coverage_shield_url]: http://img.shields.io/codeclimate/coverage/github/coz-labo/coz.svg?style=flat
24[bd_gemnasium_url]: https://gemnasium.com/coz-labo/coz
25[bd_gemnasium_shield_url]: https://gemnasium.com/coz-labo/coz.svg
26[bd_npm_url]: http://www.npmjs.org/package/coz
27[bd_npm_shield_url]: http://img.shields.io/npm/v/coz.svg?style=flat
28[bd_standard_url]: http://standardjs.com/
29[bd_standard_shield_url]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
30
31<!-- Badge End -->
32
33
34<!-- Description Start -->
35<a name="description"></a>
36
37Flexible generator, which makes your project clean and maintainable.
38
39<!-- Description End -->
40
41
42<!-- Overview Start -->
43<a name="overview"></a>
44
45
46<a href="https://github.com/coz-labo/coz"><img style="height:128px;" src="doc/images/coz-banner.png" height="128"/></a>
47
48
49```javascript
50// Define rendering rule.
51module.exports = {
52 path: 'have-a-nice-day.txt', // File path to write
53 tmpl: '.have-a-nice-day.txt.hbs', // Template file
54 force: true, // Overwrite each time
55 mode: '444', // As readyonly file
56 data: require('./my-datasource.json') // Data to render
57}
58```
59
60Save this as ***.my-first-bud.bud*** , then running
61
62```bash
63$ coz render ".my-first-bud.bud"
64```
65
66will do the magic.
67
68
69<!-- Overview End -->
70
71
72<!-- Sections Start -->
73<a name="sections"></a>
74
75<!-- Section from "doc/guides/01-about.md.hbs" Start -->
76
77<a name="section-doc-guides-01-about-md"></a>
78
79About coz
80------
81
82### What's This?
83
84The basic idea of coz is that creating files from files.
85
861. Writing a meta file called [.bud file](#spec-bud-spec).
872. Running `coz render` command.
883. Files will be generated!
89
90<img style="height:256px;" src="doc/images/coz-outline.jpg" height="256">
91
92
93### What For?
94
95Automation. Generating files makes your project clean and maintainable.
96
97You can define a single datasource and distribute it in various forms.
98
99For example,
100
101+ Generate Javascript and Python entity from database definition.
102+ Generate Web API document and Swift client entity from json schema objects.
103+ Generate skelton test case files from project files.
104
105
106### Why This?
107
108+ **Lightweight and fast**
109 + coz does nothing bud file templating, it's very fast.
110+ **Unopinionated and flexible**
111+ coz could be used to any kind of strings files.
112 + Bunch of options to manipulate files.
113+ Could be used by CLI or programmatically.
114 + **Simple and extensible**
115+ coz provides ways to customize, like registering your own template engine.
116
117
118
119
120<!-- Section from "doc/guides/01-about.md.hbs" End -->
121
122<!-- Section from "doc/guides/02-howto.md.hbs" Start -->
123
124<a name="section-doc-guides-02-howto-md"></a>
125
126Getting started
127------
128
129### Requirements
130
131+ [node.js][nodejs_url]
132
133
134### Installation
135
136coz is available as an [npm][npm_url] package.
137
138```bash
139# Install coz as a global module.
140$ npm install coz -g
141```
142
143Or you can install it without `-g` option and use [Programmatic API](#programmatic-api).
144For more details, see tutorial section "[01 - Installing coz][01_installing_coz_url]".
145
146
147### Quickstart
148
149**.who-likes-what.txt.bud** (bud file)
150```javascript
151/**
152 * .who-likes-what.txt.bud
153 * This is a bud file for "examples/01-minimum-demo"
154 */
155
156// Exports as a Node.js module.
157module.exports = {
158
159 // Template string. By default, parsed by Handlebars engine.
160 tmpl: '{{#each members}}Hi, my name is {{@key}}. I like {{this}}.\n{{/each}}',
161
162 // Overwrite when already existing.
163 force: true,
164
165 // File path to write out.
166 path: 'who-likes-what.txt',
167
168 // File permission.
169 mode: '444',
170
171 // Data to render.
172 data: {
173 members: {
174 "Mai": "apple",
175 "Tom": "Orange",
176 "Rita": "Banana"
177 }
178 }
179};
180
181```
182
183As you see, `.bud` file is actuary a JavaScript file and could be exported a Node.js module.
184
185Save this file as `.who-likes-what.txt.bud` and then, run:
186
187```bash
188# Render the bud file
189$ coz render ".who-likes-what.txt.bud"
190```
191
192This will generate a file named `who-likes-what.txt`.
193
194For more details, see tutorial section "[02 - Rendering bud files][02_rendering_bud_files_url]".
195
196
197<a name="programmatic-api" />
198### Programmatic API
199
200coz provides programmatic API which enables you to execute coz commands from Node.js program.
201
202```javascript
203#!/usr/bin/env node
204
205/**
206 * run_rendering.js
207 * This is an executable file for "examples/04-from-programmatic-api/run_rendering.js"
208 */
209
210var coz = require('coz');
211
212// Render .bud files.
213coz.render([
214 '**/.*.bud'
215], function (err) {
216 console.log(err ? err : 'Done!');
217});
218```
219
220For more details, see tutorial section "[04 - Using programmatic API][04_using_programmatic_a_p_i_url]".
221
222
223[nodejs_url]: https://nodejs.org/en/
224[npm_url]: https://www.npmjs.com/
225
226
227<!-- Section from "doc/guides/02-howto.md.hbs" End -->
228
229<!-- Section from "doc/guides/03-spec.md.hbs" Start -->
230
231<a name="section-doc-guides-03-spec-md"></a>
232
233Specifications
234---------
235
236<a name="spec-bud-spec"></a>
237### Bud File Specification
238
239A bud contains file meta data like witch template to use, where to render it, what permission to give, and so on.
240
241You can specify bud data by writing `.bud` file, which is actually a javascript file and could be written in Node.js format.
242
243```javascript
244module.exports = {
245 path: 'my_file.txt',
246 tmpl: '.my_file.txt.hbs',
247 data: require('./.my_data')
248}
249```
250
251And bud could be an array like:
252
253```javascript
254module.exports = [
255 { path: 'my_file.txt', /* ... */ },
256 { path: 'my_other_file.txt', /* ... */ },
257]
258```
259
260Or an async function.
261
262```javascript
263module.exports = function(callback){
264 myAsync((data) => {
265 let error = null
266 callback(err, data)
267 })
268}
269```
270
271For more details, see tutorial section "[03 - Mastering coz bud][03_mastering_coz_bud_url]".
272
273##### Supported Properties
274
275List of properties configurable in bud files.
276
277| Name | Type | Default | Description |
278| ----- | ----- | ----- | ----- |
279| `engine` | string|object | &#x27;handlebars&#x27; | Template engine name or engine itself |
280| `cwd` | string | process.cwd() | Working directory path |
281| `data` | object | | Data which template render with |
282| `mkdirp` | boolean | false | Make parent directories if needed |
283| `setup` | object | | Optional settings for template engine |
284| `force` | boolean | false | Should overwrite file when already exists, or not |
285| `mode` | string|number | &#x27;644&#x27; | Permission of generated files. (eg., &#x27;444&#x27; for readonly files) |
286| `path` | string | | Destination file path. If not provided, guess from bud file path |
287| `tmpl` | string|function | &#x27;json&#x27; | Template file path or registered template name or template function |
288
289
290
291
292<!-- Section from "doc/guides/03-spec.md.hbs" End -->
293
294<!-- Section from "doc/guides/04-tutorials.md.hbs" Start -->
295
296<a name="section-doc-guides-04-tutorials-md"></a>
297
298Tutorials
299------
300
301+ [01 Installing Coz][01_installing_coz_url]
302+ [02 Rendering Bud Files][02_rendering_bud_files_url]
303+ [03 Mastering Coz Bud][03_mastering_coz_bud_url]
304+ [04 Using Programmatic a P I][04_using_programmatic_a_p_i_url]
305+ [05 Customizing Coz][05_customizing_coz_url]
306
307
308[01_installing_coz_url]: https://github.com/coz-labo/coz/blob/master/doc/tutorial/01%20-%20Installing%20coz.md
309[02_rendering_bud_files_url]: https://github.com/coz-labo/coz/blob/master/doc/tutorial/02%20-%20Rendering%20bud%20files.md
310[03_mastering_coz_bud_url]: https://github.com/coz-labo/coz/blob/master/doc/tutorial/03%20-%20Mastering%20coz%20bud.md
311[04_using_programmatic_a_p_i_url]: https://github.com/coz-labo/coz/blob/master/doc/tutorial/04%20-%20Using%20programmatic%20API.md
312[05_customizing_coz_url]: https://github.com/coz-labo/coz/blob/master/doc/tutorial/05%20-%20Customizing%20coz.md
313
314
315<!-- Section from "doc/guides/04-tutorials.md.hbs" End -->
316
317<!-- Section from "doc/guides/05-project.md.hbs" Start -->
318
319<a name="section-doc-guides-05-project-md"></a>
320
321About this project
322--------
323
324### Author
325
326+ [Taka Okunishi](http://okunishitaka.com)
327
328### Donation
329
330Support this project and [others by okunishinishi][my_gratipay_url] via [gratipay][my_gratipay_url].
331
332[<img src="https://cdn.rawgit.com/gratipay/gratipay-badge/2.3.0/dist/gratipay.svg" alt="Support via Gratipay"/>][my_gratipay_url]
333
334[my_gratipay_url]: https://gratipay.com/okunishinishi/
335
336
337<!-- Section from "doc/guides/05-project.md.hbs" End -->
338
339
340<!-- Sections Start -->
341
342
343<!-- LICENSE Start -->
344<a name="license"></a>
345
346License
347-------
348This software is released under the [MIT License](https://github.com/coz-labo/coz/blob/master/LICENSE).
349
350<!-- LICENSE End -->
351
352
353<!-- Links Start -->
354<a name="links"></a>
355
356Links
357------
358
359+ [coz-examples][coz_examples_url]
360
361[coz_examples_url]: https://github.com/coz-labo/coz-examples#04-from-programmatic-api
362
363<!-- Links End -->