LoginSignup
4

More than 5 years have passed since last update.

Synthでjade以外のテンプレートエンジンを使用する方法

Last updated at Posted at 2014-08-13

そもそもSynthって何よ

私の記事を参照
Synthってなんじゃらほい? - Qiita

本題

jade嫌いです。ejs使いたいです。
使いたかったのですが使い方が分からなくて二時間ぐらい悩みました。
issue立てよう思ってcloseを見たら解決方法がありました。

Synth is built on top of express. When you initialize synth (e.g. module.exports = synth()) it automatically tells express to use jade as the rendering engine, and then returns an express app.

When I get a chance I'll change it so that a different rendering engine can be passed in when initializing synth.

Right now, one workaround is to initialize synth (which returns the express app), then set a different rendering engine, then return the app to be launched. e.g.

var app = synth();
app.set('view engine', 'ejs');
module.exports = app;

In theory that should work for any rendering engine, assuming you've installed them and told the app about them.

結論、Expressに完全に依存しているので、Expressでejs使う時みたいに使えってことみたいです。

引用されたコードの意味がわからないんだけど

通常のsynthコマンドだとできないのですが、直接back-appを呼び出してlistenする方法もあります。

app.coffee
app = require "./back/back-app"
port = process.env.PORT || 3000

app.listen port, ->
  console.log "Synth is now listening on port #{port}"

back-app.coffee
synth = require("synth")

# Connect to Mongo DB
db = require("promised-mongo")(process.env.MONGODB or "tweets-db")

# Provide DB connection to request handlers
synth.app.use (req, res, next) ->
  req.db = db
  next()
  return


# Init and return synth app
module.exports = synth()

まぁ、ここらへんに挟み込めば動くかもしれないです。

近いうちにクラスタリングに対応させたバージョンをpull requestします。弾かれたらforkします。
記事ももうすぐ書きます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4