Skip to content
Browse files

Added the author variable and using a dictionary for variable replace…

…ment
  • Loading branch information...
1 parent 532383a commit 7f539dd6e460b1bcdfb76f8427c67bb55905271a @lemieux lemieux committed Nov 9, 2011
Showing with 39 additions and 17 deletions.
  1. +1 −1 layouts/standard.html
  2. +20 −8 lib/docdown.coffee
  3. +18 −8 lib/docdown.js
View
2 layouts/standard.html
1 addition, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
28 lib/docdown.coffee
@@ -42,15 +42,24 @@ exports.run = () ->
# and replace with html
file_name_parts = markdownInput.split '.'
outputPath = "#{file_name_parts[0]}.html"
+
+ htmlReplacement = {}
- htmlTitle = '';
-
+ htmlReplacement['__title__'] = ''
#Handle title used in the html template
- if argv.title
- htmlTitle = argv.title
+ if argv.title
+ htmlReplacement['__title__'] = argv.title
else
#If no title param specified, use the default one
- htmlTitle = 'DocDown Generated File';
+ htmlReplacement['__title__'] = 'DocDown Generated File';
+
+ #Handle author used in the html template
+ htmlReplacement['__author__'] = ''
+ if argv.author
+ htmlReplacement['__author__'] = argv.author
+ else
+ #If no author param specified, none is used.
+ htmlReplacement['__author__'] = '';
#sync call to markdown file
sourceMarkdownFile = fs.readFileSync markdownInput, 'utf-8'
@@ -64,10 +73,13 @@ exports.run = () ->
if err
throw err
- replaceText = markdownParser sourceMarkdownFile
+ htmlReplacement['__markdown__'] = markdownParser sourceMarkdownFile
#replace text
- newDoc = buff.replace '__markdown__', replaceText
- newDoc = newDoc.replace '__title__', htmlTitle
+ newDoc = buff
+
+ for key,value of htmlReplacement
+ #replacing all variables
+ newDoc = newDoc.replace key,value
fs.writeFile outputPath, newDoc, (err) ->
if err
View
26 lib/docdown.js
@@ -9,7 +9,7 @@
markdownParser = require('../node_modules/markdown-js/lib/markdown').markdown;
argv = require('../node_modules/optimist').argv;
exports.run = function() {
- var file_name_parts, htmlTitle, layoutFile, layout_dir, layout_template, markdownInput, outputPath, sourceMarkdownFile;
+ var file_name_parts, htmlReplacement, layoutFile, layout_dir, layout_template, markdownInput, outputPath, sourceMarkdownFile;
markdownInput = '';
if (argv.markdown) {
markdownInput = argv.markdown;
@@ -29,23 +29,33 @@
file_name_parts = markdownInput.split('.');
outputPath = "" + file_name_parts[0] + ".html";
}
- htmlTitle = '';
+ htmlReplacement = {};
+ htmlReplacement['__title__'] = '';
if (argv.title) {
- htmlTitle = argv.title;
+ htmlReplacement['__title__'] = argv.title;
} else {
- htmlTitle = 'DocDown Generated File';
+ htmlReplacement['__title__'] = 'DocDown Generated File';
+ }
+ htmlReplacement['__author__'] = '';
+ if (argv.author) {
+ htmlReplacement['__author__'] = argv.author;
+ } else {
+ htmlReplacement['__author__'] = '';
}
sourceMarkdownFile = fs.readFileSync(markdownInput, 'utf-8');
layout_dir = path.dirname(fs.realpathSync(__filename));
layout_template = layout_dir + '/' + layout_template;
return layoutFile = fs.readFile(layout_template, 'utf-8', function(err, buff) {
- var newDoc, replaceText;
+ var key, newDoc, value;
if (err) {
throw err;
}
- replaceText = markdownParser(sourceMarkdownFile);
- newDoc = buff.replace('__markdown__', replaceText);
- newDoc = newDoc.replace('__title__', htmlTitle);
+ htmlReplacement['__markdown__'] = markdownParser(sourceMarkdownFile);
+ newDoc = buff;
+ for (key in htmlReplacement) {
+ value = htmlReplacement[key];
+ newDoc = newDoc.replace(key, value);
+ }
fs.writeFile(outputPath, newDoc, function(err) {
if (err) {
throw err;

0 comments on commit 7f539dd

Please sign in to comment.
Something went wrong with that request. Please try again.