【问题标题】:NodeJS Express app generation with CoffeeScript and HAML使用 CoffeeScript 和 HAML 生成 NodeJS Express 应用程序
【发布时间】:2014-04-02 17:07:41
【问题描述】:

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

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

有没有办法生成使用 CoffeeScript、HAML 而不是 Jade 和 Less/SCSS 的新应用程序?

【问题讨论】:

    标签: node.js express coffeescript haml


    【解决方案1】:

    我认为没有生成器,但您可以使用 HAML 和 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.
    


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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-31
      • 2013-09-08
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      相关资源
      最近更新 更多