web development in lua
play

Web development in Lua Introducing Sailor, an MVC web framework E - PowerPoint PPT Presentation

Web development in Lua Introducing Sailor, an MVC web framework E t iene Dalcol @e t iene_d @etiene_d @e t iene_d FOSDEM 2016 Sailor! sailorproject.org @e t iene_d FOSDEM 2016 Google Summer of Code LabLua @e t iene_d FOSDEM 2016 Lua


  1. Web development in Lua Introducing Sailor, an MVC web framework 
 E t iene Dalcol @e t iene_d

  2. @etiene_d @e t iene_d FOSDEM 2016

  3. Sailor! 
 sailorproject.org @e t iene_d FOSDEM 2016

  4. Google Summer of Code LabLua @e t iene_d FOSDEM 2016

  5. Lua Ladies 
 lualadies.org @e t iene_d FOSDEM 2016

  6. Lua Space 
 lua.space @e t iene_d FOSDEM 2016

  7. Web dev in Lua Sailor The future @e t iene_d FOSDEM 2016

  8. Web dev in Lua Sailor The future @e t iene_d FOSDEM 2016

  9. @e t iene_d FOSDEM 2016

  10. h t tp://www.humbedooh.com/presenta t ions/ACNA%20-%20mod_lua.odp Introducing mod_lua by Daniel Gruno @e t iene_d FOSDEM 2016

  11. Servers • Apache: mod_lua • Nginx: OpenResty @e t iene_d FOSDEM 2016

  12. 
 
 
 Servers • Apache: mod_lua • Nginx: OpenResty 
 @e t iene_d FOSDEM 2016

  13. Servers • Apache: mod_lua • Nginx: OpenResty • Xavante • Others: Ligh t tpd, Lwan, Pegasus, Mongoose @e t iene_d FOSDEM 2016

  14. Frameworks Micro-frameworks Lapis MVC Orbit 
 Event-driven Luvit TurboLua Others Ophal, Sputnik, LuaPress, Tir, Vanilla h t tp://lua.space/webdev/the-best-lua-web-frameworks @e t iene_d FOSDEM 2016

  15. Web dev in Lua Sailor The future @e t iene_d FOSDEM 2016

  16. What exactly is Sailor? It’s an MVC web framework • Completely wri t ten in Lua • Compa t ible with Apache (mod_lua), Nginx (OpenResty), • Xavante, Mongoose, Ligh t tpd and Lwan Compa t ible with Linux, Windows and Mac • Compa t ible with di f ferent databases • MIT License • v0.5 (Pluto) • Planning next release to be a 1.0! • @e t iene_d FOSDEM 2016

  17. @e t iene_d FOSDEM 2016

  18. What (else) is cool about Sailor? Rou t ing and friendly URLs • Session, cookies, include, redirect… • Lua Pages parsing • Mail sending • Simple Object Rela t ional-Mapping • Valida t ion (valua) • Basic login and authen t ica t ion modules • Form genera t ion • Themes (Bootstrap integra t ion out of the box) • App generator (Linux and Mac only) • Model and CRUD generator • Automated tests • @e t iene_d FOSDEM 2016

  19. What (else) is cool about Sailor? Rou t ing and friendly URLs • Session, cookies, include, redirect… • Lua Pages parsing • Mail sending • Simple Object Rela t ional-Mapping • Valida t ion (valua) • Basic login and authen t ica t ion modules • Form genera t ion • Themes (Bootstrap integra t ion out of the box) • App generator (Linux and Mac only) • Model and CRUD generator • Automated tests • Lua at client • @e t iene_d FOSDEM 2016

  20. Not so great things It’s s t ill in early development • Things are changing fast • It lacks features • Documenta t ion • @e t iene_d FOSDEM 2016

  21. How to get Sailor! $ luarocks install sailor 
 $ sailor create ‘My App’ /var/www 
 $ cd /var/www/my_app 
 $ lua start-server.lua @e t iene_d FOSDEM 2016

  22. @e t iene_d FOSDEM 2016

  23. App structure /conf /controllers /models /pub /run t ime /tests /themes /views @e t iene_d FOSDEM 2016

  24. 
 
 Example! -- /controllers/site.lua 
 local site = {} 
 function site.index(page) 
 local msg = “Hello World” 
 page:render(‘index’, { msg = msg } ) 
 end 
 function site.notindex(page) 
 page.theme = nil 
 page:write(“I’m different!”) 
 end 
 return site @e t iene_d FOSDEM 2016

  25. 
 
 Example! <!-- /views/site/index.lp —> 
 <p> 
 A message from the server: 
 <?lua page:print(msg) ?> 
 <br/> 
 The message again: 
 <%= msg %> <!-- syntactic sugar: same thing as above —> 
 </p> 
 @e t iene_d FOSDEM 2016

  26. @e t iene_d FOSDEM 2016

  27. 
 Example! <?lua@server -- Code here runs on the server ?> 
 <?lua -- Same as above ?> 
 <?lua@client -- Runs at the client ?> 
 <?lua@both -- Runs at the server and the client ?> 
 <?lua@both 
 another_msg = “Another message” 
 ?> 
 <?lua page:print(another_msg) ?> 
 <?lua@client 
 window:alert(another_msg) 
 ?> @e t iene_d FOSDEM 2016

  28. @e t iene_d FOSDEM 2016

  29. 
 Example! local user = {} 
 local v = require “valua” -- validation module 
 user.attributes = { 
 { id = “safe” }, 
 { name = v:new().not_empty().len(6,50) } 
 } 
 user.db = { 
 key = ‘id’, 
 table = ‘users’ 
 } 
 user.relations = { 
 posts = { -- u.posts 
 relation = “HAS_MANY”, model = “post”, attribute = “author_id” 
 } 
 } 
 return user @e t iene_d FOSDEM 2016

  30. 
 Example! local user = {} 
 local v = require “valua” -- validation module 
 user.attributes = { 
 { id = “safe” }, 
 { name = v:new().not_empty().len(6,50) } 
 } 
 user.db = { 
 key = ‘id’, 
 table = ‘users’ 
 } 
 user.relations = { 
 posts = { -- u.posts 
 relation = “HAS_MANY”, model = “post”, attribute = “author_id” 
 } 
 } 
 return user @e t iene_d FOSDEM 2016

  31. Example! -- /controllers/site.lua local site = {} 
 function site.index(page) local User = sailor.model(‘user’) local u = User:new() u.name = ‘Arnold’ local msg if u:save() then msg = ‘Success’ else msg = table.unpack(u.errors) end local users = User:find_all() page:render(‘index’, { msg = msg, users = users } ) end 
 return site @e t iene_d FOSDEM 2016

  32. Web dev in Lua Sailor The future @e t iene_d FOSDEM 2016

  33. Rails Girls Summer of Code @e t iene_d FOSDEM 2016

  34. bit.ly/luawebdev @e t iene_d FOSDEM 2016

  35. sailorproject.org github.com/sailorproject dalcol@etiene.net @etiene_d

  36. sailorproject.org github.com/sailorproject gitter.im/sailorproject/sailor dalcol@etiene.net @etiene_d

  37. sailorproject.org github.com/sailorproject dalcol@etiene.net @etiene_d

  38. sailorproject.org github.com/sailorproject Thank you! dalcol@etiene.net @etiene_d

Recommend


More recommend