使用CoffeeScript和HAML生成NodeJS Express应用程序 [英] NodeJS Express app generation with CoffeeScript and HAML

查看:263
本文介绍了使用CoffeeScript和HAML生成NodeJS Express应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始研究NodeJS和Express,发现从一开始就可以生成使用hogan的新应用的可能性:

I just started looking into NodeJS and Express and found out about the possibility to generate a new app that uses hogan right from the start:

express <appname> -c [stylus, less] --hogan --ejs

是否有生成新方法的方法使用CoffeeScript,HAML而不是Jade和Less / SCSS的应用程序?

Is there a way to generate a new app that uses CoffeeScript, HAML instead of Jade and Less/SCSS ?

推荐答案

我认为没有生成器,但是您可以使用HAML和coffeescript轻松制作一个快速应用。

I don't think there is a generator, but you can easily make an express app using HAML and coffeescript.

package.json:

{
  "name": "haml-coffee-express",
  "dependencies": {
    "express": "",
    "express-partials": "",
    "haml-coffee": "",
    "coffee-script": ""
  }
}

server.coffee:

express = require("express")
partials = require("express-partials")
app = express()
app.engine "hamlc", require("haml-coffee").__express 
app.use partials()

app.set "view engine", "hamlc"

app.get "/", (req, res) ->
  res.render "index",
  name: "User"

app.listen 3000
console.log "App started on port 3000"

views / layout.hamlc:

!!!
%head
  %title Express App
%body
  != @body

views / index.hamlc:

%h1= "Welcome #{ @name }"
%p You've rendered your first Haml Coffee view.



之后,只需运行此命令即可。


Afterwards, just run this command and you are good to go.


npm install&& node_modules / coffee-script / bin / coffee server.coffee

npm install && node_modules/coffee-script/bin/coffee server.coffee

这篇关于使用CoffeeScript和HAML生成NodeJS Express应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆