Web development in Lua @ FOSDEM 2016
-
Upload
etiene-dalcol -
Category
Software
-
view
965 -
download
0
Transcript of Web development in Lua @ FOSDEM 2016
![Page 1: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/1.jpg)
Web development in Lua
Introducing Sailor, an MVC web framework
Etiene Dalcol @etiene_d
![Page 2: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/2.jpg)
@etiene_dFOSDEM 2016
@etiene_d
![Page 4: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/4.jpg)
@etiene_dFOSDEM 2016
Google Summer of Code
LabLua
![Page 5: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/5.jpg)
@etiene_dFOSDEM 2016
Lua Ladieslualadies.org
![Page 6: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/6.jpg)
@etiene_dFOSDEM 2016
Lua Spacelua.space
![Page 7: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/7.jpg)
@etiene_dFOSDEM 2016
Web dev in Lua
Sailor
The future
![Page 8: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/8.jpg)
@etiene_dFOSDEM 2016
Web dev in Lua
Sailor
The future
![Page 9: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/9.jpg)
@etiene_dFOSDEM 2016
![Page 10: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/10.jpg)
@etiene_dFOSDEM 2016
http://www.humbedooh.com/presentations/ACNA%20-%20mod_lua.odp Introducing mod_lua by Daniel Gruno
![Page 11: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/11.jpg)
@etiene_dFOSDEM 2016
Servers
• Apache: mod_lua
• Nginx: OpenResty
![Page 12: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/12.jpg)
@etiene_dFOSDEM 2016
Servers
• Apache: mod_lua
• Nginx: OpenResty
![Page 13: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/13.jpg)
@etiene_dFOSDEM 2016
Servers
• Apache: mod_lua
• Nginx: OpenResty
• Xavante
• Others: Lighttpd, Lwan, Pegasus, Mongoose
![Page 14: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/14.jpg)
@etiene_dFOSDEM 2016
Frameworks
Micro-frameworks Lapis
MVC Orbit
Event-driven Luvit TurboLua
Others Ophal, Sputnik, LuaPress, Tir, Vanilla
http://lua.space/webdev/the-best-lua-web-frameworks
![Page 15: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/15.jpg)
@etiene_dFOSDEM 2016
Web dev in Lua
Sailor
The future
![Page 16: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/16.jpg)
@etiene_dFOSDEM 2016
What exactly is Sailor?
• It’s an MVC web framework • Completely written in Lua • Compatible with Apache (mod_lua), Nginx (OpenResty),
Xavante, Mongoose, Lighttpd and Lwan • Compatible with Linux, Windows and Mac • Compatible with different databases • MIT License • v0.5 (Pluto) • Planning next release to be a 1.0!
![Page 17: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/17.jpg)
@etiene_dFOSDEM 2016
![Page 18: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/18.jpg)
@etiene_dFOSDEM 2016
What (else) is cool about Sailor?
• Routing and friendly URLs • Session, cookies, include, redirect… • Lua Pages parsing • Mail sending • Simple Object Relational-Mapping • Validation (valua) • Basic login and authentication modules • Form generation • Themes (Bootstrap integration out of the box) • App generator (Linux and Mac only) • Model and CRUD generator • Automated tests
![Page 19: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/19.jpg)
@etiene_dFOSDEM 2016
• Routing and friendly URLs • Session, cookies, include, redirect… • Lua Pages parsing • Mail sending • Simple Object Relational-Mapping • Validation (valua) • Basic login and authentication modules • Form generation • Themes (Bootstrap integration out of the box) • App generator (Linux and Mac only) • Model and CRUD generator • Automated tests
• Lua at client
What (else) is cool about Sailor?
![Page 20: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/20.jpg)
@etiene_dFOSDEM 2016
Not so great things
• It’s still in early development • Things are changing fast • It lacks features • Documentation
![Page 21: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/21.jpg)
@etiene_dFOSDEM 2016
How to get Sailor!
$ luarocks install sailor $ sailor create ‘My App’ /var/www $ cd /var/www/my_app $ lua start-server.lua
![Page 22: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/22.jpg)
@etiene_dFOSDEM 2016
![Page 23: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/23.jpg)
@etiene_dFOSDEM 2016
/conf /controllers /models /pub /runtime /tests /themes /views
App structure
![Page 24: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/24.jpg)
@etiene_dFOSDEM 2016
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
![Page 25: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/25.jpg)
@etiene_dFOSDEM 2016
<!-- /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>
Example!
![Page 26: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/26.jpg)
@etiene_dFOSDEM 2016
![Page 27: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/27.jpg)
@etiene_dFOSDEM 2016
<?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) ?>
Example!
![Page 28: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/28.jpg)
@etiene_dFOSDEM 2016
![Page 29: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/29.jpg)
@etiene_dFOSDEM 2016
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
Example!
![Page 30: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/30.jpg)
@etiene_dFOSDEM 2016
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
Example!
![Page 31: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/31.jpg)
@etiene_dFOSDEM 2016
-- /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
Example!
![Page 32: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/32.jpg)
@etiene_dFOSDEM 2016
Web dev in Lua
Sailor
The future
![Page 33: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/33.jpg)
@etiene_dFOSDEM 2016
Rails Girls Summer of Code
![Page 35: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/35.jpg)
sailorproject.org
github.com/sailorproject
@etiene_d
![Page 36: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/36.jpg)
sailorproject.org
github.com/sailorproject
@etiene_d
gitter.im/sailorproject/sailor
![Page 37: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/37.jpg)
sailorproject.org
github.com/sailorproject
@etiene_d
![Page 38: Web development in Lua @ FOSDEM 2016](https://reader036.fdocuments.in/reader036/viewer/2022062316/5872c7501a28ab0c718b6749/html5/thumbnails/38.jpg)
Thank you!sailorproject.org
github.com/sailorproject
@etiene_d