Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelombc committed Nov 15, 2012
1 parent 1439b64 commit b431589
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 38 deletions.
58 changes: 39 additions & 19 deletions automaton_readme.md
Expand Up @@ -50,68 +50,85 @@ To illustrate most of the capabilities of Automaton, here's a complete `autofile

```javascript
var task = {
// this id is not mandatory but, if you want to use this task in other tasks,
// this id is not mandatory but,
// if you want to use this task in other tasks,
// must be provided and unique
id: 'example_task',

// a user friendly name, just for reference, not mandatory
// a user friendly name,
// just for reference, not mandatory
name: 'Example task',

// also not mandatory
author: 'Indigo United',

// filter is not mandatory, but can be used to perform some operation
// filter is not mandatory,
// but can be used to perform some operation
// on the options before running the subtasks
filter: function (options) {
// you can change existing options
options.dir2 = options.dir2 + '_indigo';

// and even define additional options. In this case we're defining
// a `dir3` option, which will be used by one of the subtasks
// and even define additional options.
// In this case we're defining
// a `dir3` option,
// which will be used by one of the subtasks
options.dir3 = 'united';
},

// this is also optional, but useful if you want the automaton
// to automatically check for required options, and some additional
// features, check below
// this is also optional,
// but useful if you want the automaton
// to automatically check for required options,
// and some additional features, check below
options: {
dir1: {
// option description is not mandatory
description : 'The name of the folder that will hold all the subfolders'
description : 'The name of the folder
that will hold
all the subfolders'
},
dir2: {
// this option will not be required, since it has a default value
// this option will not be required,
// since it has a default value
'default': 'automaton'
}
},

// a list of subtasks that will run when the example_task runs
// a list of subtasks that will run
// when the example_task runs
tasks: [
{
task: 'mkdir',
description: 'create the root and second folder',
options: {
// the option below will have its placeholders replaced by
// the option below
// will have its placeholders replaced by
// the value that it receives
dir: '{{dir1}}/{{dir2}}'
}
},
{
task: 'mkdir',
description: 'create the third folder, which was defined by one of the filters',
description: 'create the third folder,
which was defined
by one of the filters',
options: {
dir: '{{dir1}}/{{dir2}}/{{dir3}}'
}
},
{
// if you find yourself looking for something a bit more custom, you can
// just provide a function as the task
// if you find yourself looking
// for something a bit more custom,
// you can just provide a function as the task
'task' : function (opt, next) {
// opt is a list of the options provided to the task
// opt is a list of the options
// provided to the task

console.log('I can do whatever I want', ctx, opt);

// when the task is done, you just call next(), not like the MTV show, though…
// when the task is done,
// you just call next(),
// not like the MTV show, though…
// (- -')
next();
}
Expand Down Expand Up @@ -163,8 +180,11 @@ Automaton can also be used as a node module. Here's a quick example of its usage
```javascript
var automaton = require('automaton');

// Since autofiles are node modules themselves, you can just require them
// Note that instead, you could have instead declared the module inline, in JSON
// Since autofiles are node modules themselves,
// you can just require them
// Note that instead,
// you could have instead declared the module inline,
// in JSON
var myTask = require('my_autofile');

automaton.run(myTask, { 'some_option': 'that is handy' });
Expand Down
58 changes: 39 additions & 19 deletions tmpl/doc.tmpl
Expand Up @@ -48,68 +48,85 @@ module.exports = myTask;</code></pre>

</p>
<pre><code class="lang-javascript">var task = {
// this id is not mandatory but, if you want to use this task in other tasks,
// this id is not mandatory but,
// if you want to use this task in other tasks,
// must be provided and unique
id: &#39;example_task&#39;,

// a user friendly name, just for reference, not mandatory
// a user friendly name,
// just for reference, not mandatory
name: &#39;Example task&#39;,

// also not mandatory
author: &#39;Indigo United&#39;,

// filter is not mandatory, but can be used to perform some operation
// filter is not mandatory,
// but can be used to perform some operation
// on the options before running the subtasks
filter: function (options) {
// you can change existing options
options.dir2 = options.dir2 + &#39;_indigo&#39;;

// and even define additional options. In this case we&#39;re defining
// a `dir3` option, which will be used by one of the subtasks
// and even define additional options.
// In this case we&#39;re defining
// a `dir3` option,
// which will be used by one of the subtasks
options.dir3 = &#39;united&#39;;
},

// this is also optional, but useful if you want the automaton
// to automatically check for required options, and some additional
// features, check below
// this is also optional,
// but useful if you want the automaton
// to automatically check for required options,
// and some additional features, check below
options: {
dir1: {
// option description is not mandatory
description : &#39;The name of the folder that will hold all the subfolders&#39;
description : &#39;The name of the folder
that will hold
all the subfolders&#39;
},
dir2: {
// this option will not be required, since it has a default value
// this option will not be required,
// since it has a default value
&#39;default&#39;: &#39;automaton&#39;
}
},

// a list of subtasks that will run when the example_task runs
// a list of subtasks that will run
// when the example_task runs
tasks: [
{
task: &#39;mkdir&#39;,
description: &#39;create the root and second folder&#39;,
options: {
// the option below will have its placeholders replaced by
// the option below
// will have its placeholders replaced by
// the value that it receives
dir: &#39;{{dir1}}/{{dir2}}&#39;
}
},
{
task: &#39;mkdir&#39;,
description: &#39;create the third folder, which was defined by one of the filters&#39;,
description: &#39;create the third folder,
which was defined
by one of the filters&#39;,
options: {
dir: &#39;{{dir1}}/{{dir2}}/{{dir3}}&#39;
}
},
{
// if you find yourself looking for something a bit more custom, you can
// just provide a function as the task
// if you find yourself looking
// for something a bit more custom,
// you can just provide a function as the task
&#39;task&#39; : function (opt, next) {
// opt is a list of the options provided to the task
// opt is a list of the options
// provided to the task

console.log(&#39;I can do whatever I want&#39;, ctx, opt);

// when the task is done, you just call next(), not like the MTV show, though…
// when the task is done,
// you just call next(),
// not like the MTV show, though…
// (- -&#39;)
next();
}
Expand Down Expand Up @@ -155,8 +172,11 @@ module.exports = task;</code></pre>
</p>
<pre><code class="lang-javascript">var automaton = require(&#39;automaton&#39;);

// Since autofiles are node modules themselves, you can just require them
// Note that instead, you could have instead declared the module inline, in JSON
// Since autofiles are node modules themselves,
// you can just require them
// Note that instead,
// you could have instead declared the module inline,
// in JSON
var myTask = require(&#39;my_autofile&#39;);

automaton.run(myTask, { &#39;some_option&#39;: &#39;that is handy&#39; });</code></pre>
Expand Down

0 comments on commit b431589

Please sign in to comment.