cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwbro...@apache.org
Subject [15/15] git commit: [lib] Add markdown parsing.
Date Thu, 14 Nov 2013 00:23:06 GMT
[lib] Add markdown parsing.


Project: http://git-wip-us.apache.org/repos/asf/cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-labs/commit/f4ee0267
Tree: http://git-wip-us.apache.org/repos/asf/cordova-labs/tree/f4ee0267
Diff: http://git-wip-us.apache.org/repos/asf/cordova-labs/diff/f4ee0267

Branch: refs/heads/doclet
Commit: f4ee0267e316af1e9385d590931939258cd8d131
Parents: 05ae2cd
Author: Michael Brooks <michael@michaelbrooks.ca>
Authored: Wed Nov 13 16:22:14 2013 -0800
Committer: Michael Brooks <michael@michaelbrooks.ca>
Committed: Wed Nov 13 16:22:14 2013 -0800

----------------------------------------------------------------------
 lib/doclet/index.js       | 38 ++++++++++++++++++++++++++++++++++----
 package.json              |  2 ++
 spec/doclet/index.spec.js | 20 ++++++++++++++++++++
 3 files changed, 56 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/f4ee0267/lib/doclet/index.js
----------------------------------------------------------------------
diff --git a/lib/doclet/index.js b/lib/doclet/index.js
index 06125a5..498f75a 100644
--- a/lib/doclet/index.js
+++ b/lib/doclet/index.js
@@ -2,7 +2,11 @@
  * Module dependencies.
  */
 
-var dir = require('node-dir');
+var async = require('async'),
+    dir = require('node-dir'),
+    fs = require('fs'),
+    marked = require('marked'),
+    path = require('path');
 
 /**
  * Doclet compiler.
@@ -16,9 +20,35 @@ module.exports.compile = function(path) {
   // default to current working directory
   path = path || process.cwd();
 
-  // each file
+  // configure markdown parser
+  marked.setOptions({
+    gfm: true,
+    tables: true,
+    breaks: false,
+    pedantic: false,
+    sanitize: false,
+    smartLists: true
+  });
+
+  // find all files
   dir.paths(path, function(e, paths) {
-    // parse markdown
-    // render html
+    // iterate each file
+    async.each(paths.files, function(filepath, callback) {
+      // render markdown
+      if (isMarkdown(filepath)) {
+        console.log(module.exports.markdown(filepath));
+      }
+      else {
+        console.log('cp asset'); 
+      }
+    });
   });
 };
+
+module.exports.markdown = function(filepath) {
+  return marked(fs.readFileSync(filepath, 'utf8'));
+};
+
+function isMarkdown(filepath) {
+  return (['.md'].indexOf(path.extname(filepath)) >= 0);
+}

http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/f4ee0267/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 838799d..3f61469 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,8 @@
     "node": ">=0.10.0"
   },
   "dependencies": {
+    "async": "0.2.9",
+    "marked": "0.2.10",
     "node-dir": "0.1.5",
     "optimist": "0.6.0",
     "shelljs": "0.2.6"

http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/f4ee0267/spec/doclet/index.spec.js
----------------------------------------------------------------------
diff --git a/spec/doclet/index.spec.js b/spec/doclet/index.spec.js
index 5704657..6982215 100644
--- a/spec/doclet/index.spec.js
+++ b/spec/doclet/index.spec.js
@@ -4,6 +4,7 @@
 
 var dir = require('node-dir'),
     doclet = require('../../lib/doclet'),
+    fs = require('fs'),
     options;
 
 /*!
@@ -37,4 +38,23 @@ describe('doclet.compile(path)', function() {
       );
     });
   });
+
+  describe('markdown parser', function() {
+    beforeEach(function() {
+      dir.paths.andCallFake(function(path, callback) {
+        callback(null, { files: [
+          '/some/path/file-1.md',
+          '/some/path/file-2.md',
+          '/some/path/file-3.md'
+        ]});
+      });
+      spyOn(fs, 'readFileSync').andReturn('# Markdown');
+      spyOn(doclet, 'markdown');
+    });
+
+    it('should be called for each file', function() {
+      doclet.compile(options);
+      expect(doclet.markdown.calls.length).toEqual(3);
+    });
+  });
 });


Mime
View raw message