Created
January 31, 2014 07:56
-
-
Save sukobuto/8728113 to your computer and use it in GitHub Desktop.
【爆速テンプレートエンジン】Express3 以降で layout.ejs が使えなくなった代わりに ECT ref: http://qiita.com/sukobuto/items/b0be22bfebd721854e0b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module 読み込み | |
*/ | |
var express = require('express'); | |
var routes = require('./routes'); | |
var user = require('./routes/user'); | |
var http = require('http'); | |
var path = require('path'); | |
var ECT = require('ect'); // ECT 読み込み | |
var app = module.exports = express(); | |
app.set('port', process.env.PORT || 3000); | |
// ECT 環境設定 | |
app.engine('ect', ECT({ watch: true, root: __dirname + '/views', ext: '.ect' }).render); | |
app.set('view engine', 'ect'); | |
// その他 環境設定 | |
app.use(express.favicon()); | |
app.use(express.logger('dev')); | |
app.use(express.json()); | |
app.use(express.urlencoded()); | |
app.use(express.methodOverride()); | |
app.use(express.cookieParser('your secret here')); | |
app.use(express.session()); | |
app.use(app.router); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
app.get('/', routes.index); | |
http.createServer(app).listen(app.get('port'), function() { | |
console.log('Express server listening on port ' + app.get('port')); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% extend 'layout' %> | |
<h1><%= @title %><h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* GET home page. | |
*/ | |
exports.index = function (req, res) { | |
res.render('index', { title: 'Hello, ECT!' }); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Express3 + ECT</title> | |
<link rel='stylesheet' href='/stylesheets/style.css' /> | |
</head> | |
<body> | |
<% content %> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title><%= title %></title> | |
<link rel='stylesheet' href='/stylesheets/style.css' /> | |
</head> | |
<body> | |
<%- body %> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user@host project]$ npm install ect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment