Skip to content

Commit

Permalink
update outdated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Jul 20, 2014
1 parent 7871d0d commit acfae56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
35 changes: 14 additions & 21 deletions example.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
local lapis = require("lapis")

local lua = require "lapis.lua"
local lapis = require "lapis.init"
local app = lapis.Application()
app:enable("etlua")

local app = lua.class({
["/"] = function(self)
return self:html(function()
a({ href = self:url_for("user", { name = "leafo" }) }, "Go to profile")
end)
end,
app:get("index", "/", function(self)
-- renders views/index.etlua
return { render = true }
end)

[{user = "/user/:name"}] = function(self)
return self:html(function()
h1(self.params.name)
p("Welcome to " .. self.params.name .. "'s profile")
end)
end,
app:get("/user/:name", function(self)
return "Welcome to " .. self.params.name .. "'s profile"
end)

["/test.json"] = function(self)
return {
json = { status = "ok" }
}
end,
app:get("/test.json", function(self)
return { json = { status = "ok" } }
end)

}, lapis.Application)
return app

lapis.serve(app)
9 changes: 5 additions & 4 deletions example.moon
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

lapis = require "lapis"
csrf = require "lapis.csrf"

import Model from require "lapis.db.model"
import respond_to, capture_errors from require "lapis.application"
csrf = require "lapis.csrf"

class Users extends Model
url_params: =>
"user", id: @id

class App extends lapis.Application
-- Execute code before every action
Expand All @@ -19,7 +22,7 @@ class App extends lapis.Application
ul ->
for user in *users
li ->
a href: @url_for("user", user.id), user.name
a href: @url_for(user), user.name

[user: "/profile/:id"]: =>
user = Users\find id: @params.id
Expand All @@ -38,5 +41,3 @@ class App extends lapis.Application
input type: "hidden", name: "csrf_token", value: @csrf_token
input type: "text", name: "username"
}

lapis.serve(App)

0 comments on commit acfae56

Please sign in to comment.