Skip to content

Commit

Permalink
fixed #40 add nunjucks support
Browse files Browse the repository at this point in the history
  • Loading branch information
i5ting committed May 4, 2017
1 parent 693083b commit a7f6aae
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ This generator can also be further configured with the following command line fl
-V, --version output the version number
-e, --ejs add ejs engine support (defaults to jade)
--hbs add handlebars engine support
-n, --nunjucks add nunjucks engine support
-H, --hogan add hogan.js engine support
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
--git add .gitignore
Expand Down
11 changes: 11 additions & 0 deletions bin/koa2
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ program
.usage('[options] [dir]')
.option('-e, --ejs', 'add ejs engine support (defaults to jade)')
.option(' --hbs', 'add handlebars engine support')
.option('-n, --nunjucks', 'add nunjucks engine support')
.option('-H, --hogan', 'add hogan.js engine support')
.option('-c, --css <engine>', 'add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)')
.option(' --git', 'add .gitignore')
Expand Down Expand Up @@ -146,6 +147,11 @@ function createApplication(app_name, path) {
copy_template('ejs/index.ejs', path + '/views/index.ejs');
copy_template('ejs/error.ejs', path + '/views/error.ejs');
break;
case 'nunjucks':
copy_template('nunjucks/index.nunjucks', path + '/views/index.nunjucks');
copy_template('nunjucks/layout.nunjucks', path + '/views/layout.nunjucks');
copy_template('nunjucks/error.nunjucks', path + '/views/error.nunjucks');
break;
case 'jade':
case 'pug':
copy_template('jade/index.pug', path + '/views/index.pug');
Expand Down Expand Up @@ -220,6 +226,9 @@ function createApplication(app_name, path) {
case 'ejs':
pkg.dependencies['ejs'] = '~2.3.3';
break;
case 'nunjucks':
pkg.dependencies['nunjucks'] = '~3.0.0 ';
break;
case 'hjs':
pkg.dependencies['hjs'] = '~0.0.6';
break;
Expand Down Expand Up @@ -346,8 +355,10 @@ function main() {
// Template engine
program.template = 'pug';
if (program.ejs) program.template = 'ejs';
if (program.jade) program.template = 'pug';
if (program.hogan) program.template = 'hjs';
if (program.hbs) program.template = 'hbs';
if (program.nunjucks) program.template = 'nunjucks';

// Generate application
emptyDirectory(destinationPath, function (empty) {
Expand Down
7 changes: 7 additions & 0 deletions templates2/nunjucks/error.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "views/layout.nunjucks" %}

{% block content %}
<h1> {{ message }} </h1>
<h2> {{ error.status }} </h2>
<pre> {{ error.stack }} </pre>
{% endblock %}
6 changes: 6 additions & 0 deletions templates2/nunjucks/index.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'views/layout.nunjucks' %}

{% block content %}
<h1> {{ title }} </h1>
<p> Welcome to {{ title }} </p>
{% endblock %}
13 changes: 13 additions & 0 deletions templates2/nunjucks/layout.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ title }}</title>
<link href="/stylesheets/style.css" rel="stylesheet">
</head>
<body>
{% block content %}

{% endblock %}
</body>
</html>

0 comments on commit a7f6aae

Please sign in to comment.