Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Added Marko template engine support. Closes #75
Browse files Browse the repository at this point in the history
  • Loading branch information
petecoop committed Jan 21, 2015
1 parent 5b07ff0 commit 077d5ec
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 67 deletions.
1 change: 1 addition & 0 deletions .dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"jade": "~1.9.1",
"ejs": "~2.1.4",
"swig": "~1.4.2",
"marko": "~1.3.24",
"express-handlebars": "~1.1.0",
"compression": "~1.3.0",
"method-override": "~2.3.0",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ An Expressjs generator for Yeoman, based on the express command line tool.
- Handlebars
- Swig
- EJS
- Marko
- Supported CSS pre-processors
- SASS (both node-sass and ruby sass)
- LESS
Expand Down
3 changes: 2 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module.exports = generators.Base.extend({
'Jade',
'Swig',
'EJS',
'Handlebars'
'Handlebars',
'Marko'
]
}];

Expand Down
48 changes: 30 additions & 18 deletions app/templates/basic-coffee/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var app = express();
app.engine('handlebars', exphbs({
defaultLayout: 'main',
partialsDir: ['views/partials/']
}));<% } %>
}));<% } %><% if(options.viewEngine != 'marko'){ %>
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', '<%= options.viewEngine %>');
app.set('view engine', '<%= options.viewEngine %>');<% } %>

// app.use(favicon(__dirname + '/public/img/favicon.ico'));
app.use(logger('dev'));
Expand All @@ -37,35 +37,47 @@ app.use('/users', users);

/// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
var err = new Error('Not Found');
err.status = 404;
next(err);
});

/// error handlers

// development error handler
// will print stacktrace
<% if(options.viewEngine == 'marko'){ %>
var errorTemplate = require('marko').load(require.resolve('./views/error.marko'));<% } %>
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err,
title: 'error'
app.use(function(err, req, res, next) {
res.status(err.status || 500);<% if(options.viewEngine == 'marko'){ %>
errorTemplate.render({
message: err.message,
error: err,
title: 'error'
}, res);<% } else { %>
res.render('error', {
message: err.message,
error: err,
title: 'error'
});<% } %>
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {},
title: 'error'
});
res.status(err.status || 500);<% if(options.viewEngine == 'marko'){ %>
errorTemplate.render({
message: err.message,
error: err,
title: 'error'
}, res);<% } else { %>
res.render('error', {
message: err.message,
error: {},
title: 'error'
});<% } %>
});


Expand Down
9 changes: 5 additions & 4 deletions app/templates/basic-coffee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"jade": "~1.9.1"<% } %><% if(options.viewEngine == 'ejs'){ %>,
"ejs": "~2.1.4"<% } %><% if(options.viewEngine == 'swig'){ %>,
"swig": "~1.4.2"<% } %><% if(options.viewEngine == 'handlebars'){ %>,
"express-handlebars": "~1.1.0"<% } %>
"express-handlebars": "~1.1.0"<% } %><% if(options.viewEngine == 'marko'){ %>,
"marko": "~1.3.24"<% } %>
},
"devDependencies": {<% if(options.buildTool == 'grunt'){ %>
"devDependencies": {
"coffee-script": "~1.8.0",<% if(options.buildTool == 'grunt'){ %>
"grunt": "~0.4.5",
"grunt-develop": "~0.4.0"<% if(options.cssPreprocessor == 'sass'){ %>,
"grunt-contrib-sass": "~0.8.1"<% } %><% if(options.cssPreprocessor == 'node-sass'){ %>,
Expand All @@ -27,8 +29,7 @@
"grunt-contrib-watch": "~0.6.1",
"request": "~2.51.0",
"time-grunt": "~1.0.0",
"load-grunt-tasks": "~2.0.0",
"coffee-script": "~1.8.0"<% } %><% if(options.buildTool == 'gulp'){ %>
"load-grunt-tasks": "~2.0.0"<% } %><% if(options.buildTool == 'gulp'){ %>
"gulp": "~3.8.10"<% if(options.cssPreprocessor == 'sass'){ %>,
"gulp-ruby-sass": "~0.7.1"<% } %><% if(options.cssPreprocessor == 'node-sass'){ %>,
"gulp-sass": "~1.3.2"<% } %><% if(options.cssPreprocessor == 'less'){ %>,
Expand Down
12 changes: 9 additions & 3 deletions app/templates/basic-coffee/routes/index.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
express = require 'express'
router = express.Router()
router = express.Router()<% if(options.viewEngine == 'marko'){ %>
marko = require 'marko'<% } %>

# GET home page.
router.get '/', (req, res) ->
res.render 'index', { title: 'Express' }
<% if(options.viewEngine == 'marko'){ %>
indexTemplate = marko.load require.resolve '../views/index.marko'<% } %>
router.get '/', (req, res) -><% if(options.viewEngine == 'marko'){ %>
indexTemplate.render
title: 'Express'
, res<% } else { %>
res.render 'index', { title: 'Express' }<% } %>

module.exports = router
24 changes: 18 additions & 6 deletions app/templates/basic/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var app = express();
app.engine('handlebars', exphbs({
defaultLayout: 'main',
partialsDir: ['views/partials/']
}));<% } %>
}));<% } %><% if(options.viewEngine != 'marko'){ %>
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', '<%= options.viewEngine %>');
app.set('view engine', '<%= options.viewEngine %>');<% } %>

// app.use(favicon(__dirname + '/public/img/favicon.ico'));
app.use(logger('dev'));
Expand All @@ -44,26 +44,38 @@ app.use(function(req, res, next) {

// development error handler
// will print stacktrace
<% if(options.viewEngine == 'marko'){ %>
var errorTemplate = require('marko').load(require.resolve('./views/error.marko'));<% } %>
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.status(err.status || 500);<% if(options.viewEngine == 'marko'){ %>
errorTemplate.render({
message: err.message,
error: err,
title: 'error'
}, res);<% } else { %>
res.render('error', {
message: err.message,
error: err,
title: 'error'
});
});<% } %>
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.status(err.status || 500);<% if(options.viewEngine == 'marko'){ %>
errorTemplate.render({
message: err.message,
error: err,
title: 'error'
}, res);<% } else { %>
res.render('error', {
message: err.message,
error: {},
title: 'error'
});
});<% } %>
});


Expand Down
3 changes: 2 additions & 1 deletion app/templates/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"jade": "~1.9.1"<% } %><% if(options.viewEngine == 'ejs'){ %>,
"ejs": "~2.1.4"<% } %><% if(options.viewEngine == 'swig'){ %>,
"swig": "~1.4.2"<% } %><% if(options.viewEngine == 'handlebars'){ %>,
"express-handlebars": "~1.1.0"<% } %>
"express-handlebars": "~1.1.0"<% } %><% if(options.viewEngine == 'marko'){ %>,
"marko": "~1.3.24"<% } %>
},
"devDependencies": {<% if(options.buildTool == 'grunt'){ %>
"grunt": "~0.4.5",
Expand Down
12 changes: 9 additions & 3 deletions app/templates/basic/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
var express = require('express');
var router = express.Router();
var router = express.Router();<% if(options.viewEngine == 'marko'){ %>
var marko = require('marko');<% } %>

/* GET home page. */
router.get('/', function(req, res) {
res.render('index', { title: 'Express' });
<% if(options.viewEngine == 'marko'){ %>
var indexTemplate = marko.load(require.resolve('../views/index.marko'));<% } %>
router.get('/', function(req, res) {<% if(options.viewEngine == 'marko'){ %>
indexTemplate.render({
title: 'Express'
}, res);<% } else { %>
res.render('index', { title: 'Express' });<% } %>
});

module.exports = router;
14 changes: 10 additions & 4 deletions app/templates/mvc-coffee/app/controllers/home.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
express = require 'express'
router = express.Router()<% if(options.database == 'mongodb'){ %>
router = express.Router()<% if(options.viewEngine == 'marko'){ %>
marko = require 'marko'<% } %><% if(options.database == 'mongodb'){ %>
mongoose = require 'mongoose'
Article = mongoose.model 'Article'<% } %><% if(options.database == 'mysql' || options.database == 'postgresql'){ %>
db = require '../models'<% } %>

module.exports = (app) ->
app.use '/', router

<% if(options.viewEngine == 'marko'){ %>
indexTemplate = marko.load require.resolve '../views/index.marko'<% } %>
router.get '/', (req, res, next) ->
<% if(options.database == 'mongodb'){ %>
Article.find (err, articles) ->
return next(err) if err<% } %><% if(options.database == 'mysql' || options.database == 'postgresql'){ %>
db.Article.findAll().success (articles) -><% } %>
db.Article.findAll().success (articles) -><% } %><% if(options.viewEngine == 'marko'){ %>
indexTemplate.render
title: 'Generator-Express MVC',
articles: articles
, res<% } else { %>
res.render 'index',
title: 'Generator-Express MVC'
articles: articles
articles: articles<% } %>
24 changes: 18 additions & 6 deletions app/templates/mvc-coffee/config/express.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ module.exports = (app, config) -><% if(options.viewEngine == 'swig'){ %>
layoutsDir: config.root + '/app/views/layouts/'
defaultLayout: 'main'
partialsDir: [config.root + '/app/views/partials/']
)<% } %>
)<% } %><% if(options.viewEngine != 'marko'){ %>
app.set 'views', config.root + '/app/views'
app.set 'view engine', '<%= options.viewEngine %>'
app.set 'view engine', '<%= options.viewEngine %>'<% } %>

# app.use(favicon(config.root + '/public/img/favicon.ico'));
app.use logger 'dev'
Expand All @@ -45,19 +45,31 @@ module.exports = (app, config) -><% if(options.viewEngine == 'swig'){ %>

# development error handler
# will print stacktrace
<% if(options.viewEngine == 'marko'){ %>
errorTemplate = require('marko').load require.resolve '../app/views/error.marko'<% } %>
if app.get('env') == 'development'
app.use (err, req, res, next) ->
res.status err.status || 500
res.status err.status || 500<% if(options.viewEngine == 'marko'){ %>
errorTemplate.render
message: err.message,
error: err
title: 'error'
, res<% } else { %>
res.render 'error',
message: err.message
error: err
title: 'error'
title: 'error'<% } %>

# production error handler
# no stacktraces leaked to user
app.use (err, req, res, next) ->
res.status err.status || 500
res.status err.status || 500<% if(options.viewEngine == 'marko'){ %>
errorTemplate.render
message: err.message,
error: {}
title: 'error'
, res<% } else { %>
res.render 'error',
message: err.message
error: {}
title: 'error'
title: 'error'<% } %>
9 changes: 5 additions & 4 deletions app/templates/mvc-coffee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
"jade": "~1.9.1"<% } %><% if(options.viewEngine == 'ejs'){ %>,
"ejs": "~2.1.4"<% } %><% if(options.viewEngine == 'swig'){ %>,
"swig": "~1.4.2"<% } %><% if(options.viewEngine == 'handlebars'){ %>,
"express-handlebars": "~1.1.0"<% } %>
"express-handlebars": "~1.1.0"<% } %><% if(options.viewEngine == 'marko'){ %>,
"marko": "~1.3.24"<% } %>
},
"devDependencies": {<% if(options.buildTool == 'grunt'){ %>
"devDependencies": {
"coffee-script": "~1.8.0",<% if(options.buildTool == 'grunt'){ %>
"grunt": "~0.4.5",
"grunt-develop": "~0.4.0"<% if(options.cssPreprocessor == 'sass'){ %>,
"grunt-contrib-sass": "~0.8.1"<% } %><% if(options.cssPreprocessor == 'node-sass'){ %>,
Expand All @@ -35,8 +37,7 @@
"grunt-contrib-watch": "~0.6.1",
"request": "~2.51.0",
"time-grunt": "~1.0.0",
"load-grunt-tasks": "~2.0.0",
"coffee-script": "~1.8.0"<% } %><% if(options.buildTool == 'gulp'){ %>
"load-grunt-tasks": "~2.0.0"<% } %><% if(options.buildTool == 'gulp'){ %>
"gulp": "~3.8.10"<% if(options.cssPreprocessor == 'sass'){ %>,
"gulp-ruby-sass": "~0.7.1"<% } %><% if(options.cssPreprocessor == 'node-sass'){ %>,
"gulp-sass": "~1.3.2"<% } %><% if(options.cssPreprocessor == 'less'){ %>,
Expand Down
14 changes: 10 additions & 4 deletions app/templates/mvc/app/controllers/home.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var express = require('express'),
router = express.Router(),<% if(options.database == 'mongodb'){ %>
router = express.Router(),<% if(options.viewEngine == 'marko'){ %>
marko = require('marko'),<% } %><% if(options.database == 'mongodb'){ %>
mongoose = require('mongoose'),
Article = mongoose.model('Article');<% } %><% if(options.database == 'mysql' || options.database == 'postgresql'){ %>
db = require('../models');<% } %><% if(options.database == 'none'){ %>
Expand All @@ -8,16 +9,21 @@ var express = require('express'),
module.exports = function (app) {
app.use('/', router);
};

<% if(options.viewEngine == 'marko'){ %>
var indexTemplate = marko.load(require.resolve('../views/index.marko'));<% } %>
router.get('/', function (req, res, next) {
<% if(options.database == 'mongodb'){ %>
Article.find(function (err, articles) {
if (err) return next(err);<% } %><% if(options.database == 'mysql' || options.database == 'postgresql'){ %>
db.Article.findAll().success(function (articles) {<% } %><% if(options.database == 'none'){ %>
var articles = [new Article(), new Article()];<% } %>
var articles = [new Article(), new Article()];<% } %><% if(options.viewEngine == 'marko'){ %>
indexTemplate.render({
title: 'Generator-Express MVC',
articles: articles
}, res);<% } else { %>
res.render('index', {
title: 'Generator-Express MVC',
articles: articles
});<% if(options.database !== 'none'){ %>
});<% } %><% if(options.database !== 'none'){ %>
});<% } %>
});
Loading

0 comments on commit 077d5ec

Please sign in to comment.