Permalink
Browse files

Merge branch 'templates' of git://github.com/Dignifiedquire/panda-doc…

…s into Dignifiedquire-templates
  • Loading branch information...
gjtorikian committed Apr 5, 2013
2 parents ae2351c + a64f102 commit 1fff2cbfab5ff4aea3747d55abe686c1fd726be2
Showing with 27 additions and 14 deletions.
  1. +8 −3 README.md
  2. +16 −8 index.js
  3. +3 −3 lib/cli.js
View
@@ -55,7 +55,7 @@ There are a number of arguments you can pass to Panda that affect the entire bui
* `-o PATH`, `--output PATH` Resulting file(s) location [out]
* `-oa PATH`, `--outputAssets PATH` Resulting file(s) location for assets [out/assets]
* `-t `STRING`, `--title STRING` Title of the index page [Panda: Default Title Here]
-* `--skin PATH` The location of your primary Jade template [./templates/default/layout.jade]
+* `--skin PATH` The location of your Jade templates [./templates/default]
* `--assets PATH` The location of your asset files (CSS, Javascript, e.t.c.) [./templates/default/assets]
* `-d`, `--disableTests` Disables the test suite that runs at the end of an HTML build. This is NOT recommended.
* `--keepFirstHeader` If set, keeps the first header (`<h1>`) detected
@@ -65,7 +65,12 @@ There are a number of arguments you can pass to Panda that affect the entire bui
## Jade Templates
-You have to specify at least one Jade file as a template for your pages. Within your Jade template, you have access to the following variables:
+You need at least one Jade template `layout.jade`. Optional you can
+have a template per file, for example if you have the file `index.md`
+you can add `index.jade` to your template folder and it will be used
+only for this file.
+
+Within your Jade template, you have access to the following variables:
* `content` is the transformed HTML content of your Markdown file
* `metadata` is an object containing your document-based metadata values
@@ -182,4 +187,4 @@ The callback for `panda` returns a JSON with one key: `files`, which is a listin
* `mtime`: the last modified time of your source file
* `pageTitle`: the title of the page (text only, meaning minus any `#` or `<h1>` indicators)
-You could use this information to provide a list of Recently Updated content--which is exactly what the [Cloud9 IDE User Documentation](https://github.com/c9/cloud9ide-documentation) does.
+You could use this information to provide a list of Recently Updated content--which is exactly what the [Cloud9 IDE User Documentation](https://github.com/c9/cloud9ide-documentation) does.
View
@@ -30,7 +30,7 @@ panda_docs.make = exports.make = function(paths, _options, callback) {
if (!options.keepOutDir) {
wrench.rmdirSyncRecursive(destDir, true);
}
-
+
wrench.mkdirSyncRecursive(destDir);
cbReturn = {};
@@ -107,19 +107,27 @@ panda_docs.make = exports.make = function(paths, _options, callback) {
}
function render(options, cbReturn, callback) {
- var jadeTemplateFile = options.skin;
- var jadeTemplate = fs.readFileSync(jadeTemplateFile, 'utf8');
- var jadeCompileFn = jade.compile(jadeTemplate, {filename: jadeTemplateFile, pretty: true});
+ var defaultTemplateFile = path.join(options.skin, 'layout.jade');
+ var defaultTemplate = fs.readFileSync(defaultTemplateFile, 'utf8');
+ var defaultCompileFn = jade.compile(defaultTemplate, {filename: defaultTemplateFile, pretty: true});
console.log("Building files...");
-
+
async.forEach(files, function(filepath, cb) {
fs.stat(filepath, function (err, stats) {
- if (err) return callback(err);
+ if (err) return callback(err);
var mtime = stats.mtime.valueOf();
var filename = path.basename(filepath, options.extension);
+ var jadeTemplateFile = path.join(options.skin, filename + '.jade');
+ if (fs.existsSync(jadeTemplateFile)) {
+ var jadeTemplate = fs.readFileSync(jadeTemplateFile, 'utf8');
+ var jadeCompileFn = jade.compile(jadeTemplate, {filename: jadeTemplateFile, pretty: true});
+ } else {
+ var jadeCompileFn = defaultCompileFn;
+ }
+
fs.readFile(filepath, 'utf8', function(err, data) {
- if (err) return callback(err);
+ if (err) return callback(err);
Generator.render(options, jadeCompileFn, filepath, filename, data, mtime, function(err, html) {
var fileObj = {};
@@ -144,7 +152,7 @@ function render(options, cbReturn, callback) {
cb(null);
});
});
- });
+ });
}, function(err, results) {
callback(err);
});
View
@@ -70,10 +70,10 @@ cli.addArgument(['-t', '--title'], {
});
cli.addArgument(['--skin'], {
- help: 'The location of your primary Jade template [./templates/default/layout.jade]',
+ help: 'The location of your Jade templates [./templates/default]',
dest: 'skin',
metavar: 'PATH',
- defaultValue: './templates/default/layout.jade'
+ defaultValue: './templates/default'
});
cli.addArgument(['--assets'], {
@@ -170,7 +170,7 @@ cli.findFiles = function findFiles(paths, excludes, extension, callback) {
return /node_modules/.test(filename) || filter.test(filename, lstats);
});
}
-
+
if (include && path.extname(filename) == extension) {
entries.push(filename);
}

0 comments on commit 1fff2cb

Please sign in to comment.