Skip to content

Commit

Permalink
Add ability to choose template engines - fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Dec 2, 2013
1 parent 977fa08 commit 90e1c46
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ $ npm start

## Features

* Base DocPad application structure
* [Bower](http://github.com/robloach/docpad-plugin-bower)
* [Grunt](http://github.com/robloach/docpad-plugin-grunt)
* [Marked](http://docpad.org/plugin/marked)
* Set up the DocPad application structure
* Select [Renderers](http://docpad.org/docs/plugins#renderers)
* [Eco](http://docpad.org/plugin/eco)
* [Marked](http://docpad.org/plugin/marked)
* Select [Helpers](http://docpad.org/docs/plugins#helpers)
* [Bower](http://github.com/robloach/docpad-plugin-bower)
* [Grunt](http://github.com/robloach/docpad-plugin-grunt)
* [Live Reload](http://docpad.org/plugin/livereload)


## License
Expand Down
51 changes: 41 additions & 10 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,25 @@ DocPadGenerator.prototype.askFor = function askFor() {
},
{
type: 'checkbox',
name: 'features',
message: 'Features',
name: 'renderers',
message: 'Renderers',
choices: [
{
name: 'Eco: Supports Eco to anything',
value: 'eco',
checked: true
},
{
name: 'Marked: Supports Markdown to HTML',
value: 'marked',
checked: false
}
]
},
{
type: 'checkbox',
name: 'helpers',
message: 'Helpers',
choices: [
{
name: 'Bower: Package Manager',
Expand All @@ -79,29 +96,37 @@ DocPadGenerator.prototype.askFor = function askFor() {
checked: false
},
{
name: 'Marked: Supports Markdown to HTML',
value: 'marked',
checked: false
name: 'Live Reload: Automatically reloads the page when regenerating',
value: 'livereload',
checked: true
}
]
}
];

this.prompt(prompts, function (answers) {
// Construct the user options.
function hasFeature(feat) { return answers.features.indexOf(feat) !== -1; }
function hasRenderer(feat) { return answers.renderers.indexOf(feat) !== -1; }
function hasHelper(feat) { return answers.helpers.indexOf(feat) !== -1; }
this.options = {
appname: answers.appname,
docpadFile: answers.docpadFile,
license: answers.license,
bower: hasFeature('bower'),
marked: hasFeature('marked'),
grunt: hasFeature('grunt')
bower: hasHelper('bower'),
marked: hasRenderer('marked'),
eco: hasRenderer('eco'),
grunt: hasHelper('grunt'),
livereload: hasHelper('livereload')
};

// Override any of the internal variables.
this.appname = this.options.appname;

// Ensure the base requirements are met.
if (!this.options.eco) {
this.options.eco = true;
}

cb();
}.bind(this));
};
Expand Down Expand Up @@ -155,6 +180,13 @@ DocPadGenerator.prototype.marked = function marked() {
}
};

DocPadGenerator.prototype.eco = function eco() {
if (this.options.eco) {
this.copy('docpad/layouts/default.html.eco', 'src/layouts/default.html.eco');
this.copy('docpad/documents/eco.html.eco', 'src/documents/eco.html.eco');
}
};

DocPadGenerator.prototype.docpadFiles = function docpadFiles() {
// All the DocPad source files.
var files = [
Expand All @@ -165,7 +197,6 @@ DocPadGenerator.prototype.docpadFiles = function docpadFiles() {
}

var files = [
"layouts/default.html.eco",
"files/main.css",
"files/main.js"
];
Expand Down
8 changes: 4 additions & 4 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"node": ">=0.8.0"
},
"dependencies": {
"docpad": "~6.56.0",
"docpad-plugin-eco": "~2.0.2"<% if (options.grunt) { %>,
"docpad": "~6.56.0"<% if (options.eco) { %>,
"docpad-plugin-eco": "~2.0.2"<% } %><% if (options.grunt) { %>,
"docpad-plugin-grunt": "~2.0.5"<% } %><% if (options.marked) { %>,
"docpad-plugin-marked": "~2.1.2"<% } %>
},
"devDependencies": {
"docpad-plugin-livereload": "~2.5.3"<% if (options.bower) { %>,
"devDependencies": {<% if (options.livereload) { %>
"docpad-plugin-livereload": "~2.5.3"<% } %><% if (options.bower) { %>,
"bower": "~1.2.7"<% } %><% if (options.grunt) { %>,
"grunt": "~0.4.2"<% } %>
},
Expand Down
8 changes: 8 additions & 0 deletions app/templates/docpad/documents/eco.html.eco
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: "default"
title: "Eco Example"
---

<p>This example of <%= appname %> makes use of the <a href="https://github.com/docpad/docpad-plugin-eco/">Eco DocPad Plugin</a>.</p>

<ul><li><a href="index.html">Home</a></li></ul>
1 change: 1 addition & 0 deletions app/templates/docpad/documents/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<h2>Examples</h2>
<ul>
<% if (options.marked) { %><li><a href="marked.html">Marked</a></li><% } %>
<% if (options.eco) { %><li><a href="eco.html">Eco</a></li><% } %>
</ul>
14 changes: 10 additions & 4 deletions test/test-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ describe('docpad generator', function () {
'docpad.cson',
'src/documents/index.html',
'LICENSE.md',
'src/documents/marked.html.md'
'src/documents/marked.html.md',
'src/documents/eco.html.eco',
'src/layouts/default.html.eco'
];

// Mock the answer prompts.
helpers.mockPrompt(this.app, {
'appname': 'DocPad test',
'docpadFile': 'docpad.cson',
'license': 'Apache-2.0',
features: [
'grunt',
renderers: [
'marked',
'bower'
'eco'
],
helpers: [
'grunt',
'bower',
'livereload'
]
});
this.app.options['skip-install'] = true;
Expand Down

0 comments on commit 90e1c46

Please sign in to comment.