Permalink
Browse files

Allow adding some general documentation (closes #16)

  • Loading branch information...
1 parent baa9f76 commit 39c5fddf32c51140ae6ac309b56b86a35c5bf34c Patrick Boos committed Dec 2, 2013
Showing with 29 additions and 3 deletions.
  1. +2 −0 README.md
  2. +16 −3 lib/easymock.js
  3. +5 −0 lib/static/documentation.css
  4. +5 −0 lib/views/documentation.jade
  5. +1 −0 package.json
View
@@ -160,6 +160,8 @@ easymock automatically documents the API it represents. This documentation can b
"description": "your description"
}
+To add some general information in the documentation, add a file "_documentation/index.md". That one will be shown at the top of the documented calls.
+
## Logging
All requests get logged and can be inspected. You can do so at http://localhost:3000/_logs/.
View
@@ -5,6 +5,7 @@ var url = require('url');
var fs = require('fs');
var httpProxy = require('http-proxy');
var _ = require('underscore');
+var marked = require('marked');
var AccessLog = require('./access_log').AccessLog;
require('broware');
@@ -452,18 +453,30 @@ MockServer.prototype.getApiDocumentationJson = function(callback) {
};
MockServer.prototype.getApiDocumentation = function(req, res) {
+ var api, general;
function getDocumentation() {
res.app.set('mock').getApiDocumentationJson(function(err, apiDocumentation) {
if (err) { return res.send(400, err); }
- apiDocumentation = _.map(apiDocumentation, function(item) {
+ api = _.map(apiDocumentation, function(item) {
item.classes = item.method.toLowerCase();
return item;
});
- getDocumentationHtml(apiDocumentation);
+ getGeneralDocumentation();
});
}
+ function getGeneralDocumentation() {
+ var file = res.app.set('mock').options.path + "/_documentation/index.md";
+ if (fs.existsSync(file)) {
+ general = fs.readFileSync(file, 'utf8');
+ }
+
+ getDocumentationHtml();
+ }
function getDocumentationHtml(documentation) {
- res.render('documentation', {title: 'API Documentation', calls: documentation});
+ if (general) {
+ general = marked(general);
+ }
+ res.render('documentation', {title: 'API Documentation', calls: api, general: general});
}
getDocumentation();
};
@@ -17,6 +17,11 @@ ul, li {
.head:hover {
background: #cccccc;
}
+.head.general {
+ font-size: 24px;
+ font-weight: bold;
+ padding: 5px;
+}
.right {
float: right;
@@ -4,6 +4,11 @@ block head
link(rel='stylesheet',href='documentation.css')
block content
+ if general
+ .call
+ .head.general General
+ .body
+ .general!= general
each call in calls
div.call(class=call.classes)
.head
View
@@ -18,6 +18,7 @@
, "broware": "0.1.0"
, "sqlite3": "2.1.17"
, "moment": "2.0.0"
+ , "marked": "0.2.10"
}
, "devDependencies": {
"chai": "1.1.0"

0 comments on commit 39c5fdd

Please sign in to comment.