Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9ba1cc

Browse files
author
Kevin Renskers
committed
1.1.1: fixed default behaviour of calling getDefaultConfig with no arguments, which should always use the default templates
1 parent a53d351 commit b9ba1cc

File tree

7 files changed

+33
-4
lines changed

7 files changed

+33
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ raml2html.render(source, config, onSuccess, onError);
4444
raml2html.render(source, config, onSuccess, onError);
4545
```
4646

47+
See also `example/script.js` for an example of using raml2html as a library.
48+
4749
### Gulp
4850
There's a Gulp plugin at https://www.npmjs.org/package/gulp-raml2html.
4951

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
1.1.1 - January 20, 2015
2+
- Fixed default behaviour of calling getDefaultConfig with no arguments, which should always use the default templates
3+
14
1.1.0 - January 14, 2015
25
- Now using raml-parser's FileReader which makes it a lot easier to load custom templates
36
in other folders or even as remote urls

examples/example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE HTML><html><head><title>Example API documentation</title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="generator" content="https://github.com/kevinrenskers/raml2html 1.1.0"><link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"><link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/styles/default.min.css"><script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script><script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script><script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js"></script><script type="text/javascript">
1+
<!DOCTYPE HTML><html><head><title>Example API documentation</title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="generator" content="https://github.com/kevinrenskers/raml2html 1.1.1"><link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"><link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/styles/default.min.css"><script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script><script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script><script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js"></script><script type="text/javascript">
22
$(document).ready(function() {
33
$('.page-header pre code, .top-resource-description pre code').each(function(i, block) {
44
hljs.highlightBlock(block);

examples/github.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE HTML><html><head><title>GitHub API API documentation</title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="generator" content="https://github.com/kevinrenskers/raml2html 1.1.0"><link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"><link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/styles/default.min.css"><script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script><script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script><script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js"></script><script type="text/javascript">
1+
<!DOCTYPE HTML><html><head><title>GitHub API API documentation</title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="generator" content="https://github.com/kevinrenskers/raml2html 1.1.1"><link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"><link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/styles/default.min.css"><script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script><script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script><script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js"></script><script type="text/javascript">
22
$(document).ready(function() {
33
$('.page-header pre code, .top-resource-description pre code').each(function(i, block) {
44
hljs.highlightBlock(block);

examples/script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
Example of using raml2html as a script
3+
*/
4+
5+
var raml2html = require('../lib/raml2html');
6+
var config = raml2html.getDefaultConfig();
7+
8+
raml2html.render('example.raml', config, function(result) {
9+
console.log(result);
10+
}, function(error) {
11+
console.log('error! ', error);
12+
});

lib/raml2html.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ function render(source, config, onSuccess, onError) {
7474

7575
raml2obj.parse(source, function(ramlObj) {
7676
ramlObj.config = config;
77-
var result = handlebars.compile(config.template)(ramlObj);
77+
78+
var result;
79+
if (typeof config.template === 'string') {
80+
result = handlebars.compile(config.template)(ramlObj);
81+
} else {
82+
result = config.template(ramlObj);
83+
}
7884

7985
if (config.processOutput) {
8086
config.processOutput(result, onSuccess, onError)
@@ -85,6 +91,12 @@ function render(source, config, onSuccess, onError) {
8591
}
8692

8793
function getDefaultConfig(https, mainTemplate, resourceTemplate, itemTemplate) {
94+
if (!mainTemplate && !resourceTemplate && !itemTemplate) {
95+
mainTemplate = require('./template.handlebars');
96+
resourceTemplate = require('./resource.handlebars');
97+
itemTemplate = require('./item.handlebars');
98+
}
99+
88100
return {
89101
https: https,
90102
template: mainTemplate,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "raml2html",
33
"description": "RAML to HTML documentation generator",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"author": {
66
"name": "Kevin Renskers",
77
"email": "[email protected]"

0 commit comments

Comments
 (0)