zoukankan      html  css  js  c++  java
  • lapis 基本开发

    1. 生成项目代码
    // 支持lua 以及 moonscript, 默认是moonscript 通过--lua 可以生成lua 的代码
    
    lapis new --lua 
    
    ├── app.lua
    ├── mime.types
    ├── models.lua
    ├── nginx.conf
    2. 启动项目
    //  可以守护进程模式运行,修改nginx.conf 模板代码  daemon on;
    lapis server  
    3. 修改项目默认环境配置(比如开发、生产)
    // 使用config.lua  默认是development
    
    local config = require("lapis.config")
    config("development", {
      port = 9090
    })
    
    config("product",{
      port = 8080
    })
    
    // 启动执行的配置
    
    lapis  server product
    
    备注: 以上的配置文件可以直接在nginx.conf 使用 
    events {
      worker_connections ${{WORKER_CONNECTIONS}};
    }
    
    同时可以使用api 直接进行访问,类似大家在nodejs 开发中需要获取package.json 信息(pkginfo npm 包)
    4. 视图view 创建
    // 默认在 views 目录,使用的是模板 etlua 
    
    local lapis = require("lapis")
    local app = lapis.Application()
    app:enable("etlua")  //  默认未启用
    
    app:get("/", function(self)
      return { render = "index" }
    end)
    
    return app
    
    //views/index.etlua
    
    <h1>Hello world</h1>
    <p>Welcome to my page</p>
     
     
    5. 创建模板布局
    // views/layout.etlua  
    
    <!-- views/layout.etlua -->
    <!DOCTYPE HTML>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title><%= page_title or "My Page" %></title>
    </head>
    <body>
      <h1>Greetings</h1>
      <% content_for("inner") %>
    </body>
    </html>
    
    // 启用模板布局 app.lua 注意顺序比较重要,必须在 app:enable("etlua") 下面
    
    app.layout = require "views.layout"
     
     
    6. 参考文档
    http://leafo.net/lapis/reference/configuration.html
    https://github.com/leafo/etlua
    http://leafo.net/lapis/reference/etlua_templates.html
  • 相关阅读:
    【Codeforces 349B】Color the Fence
    【Codeforces 459D】Pashmak and Parmida's problem
    【Codeforces 467C】George and Job
    【Codeforces 161D】Distance in Tree
    【Codeforces 522A】Reposts
    【Codeforces 225C】Barcode
    【Codeforces 446A】DZY Loves Sequences
    【Codeforces 429B】Working out
    【Codeforces 478C】Table Decorations
    【Codeforces 478C】Table Decorations
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/7840761.html
Copyright © 2011-2022 走看看