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

web development in lua
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Web development in Lua

Introducing Sailor, an MVC web framework


Etiene Dalcol @etiene_d

slide-2
SLIDE 2

@etiene_d FOSDEM 2016

@etiene_d

slide-3
SLIDE 3

@etiene_d FOSDEM 2016

Sailor!


sailorproject.org

slide-4
SLIDE 4

@etiene_d FOSDEM 2016

Google Summer of Code

LabLua

slide-5
SLIDE 5

@etiene_d FOSDEM 2016

Lua Ladies


lualadies.org

slide-6
SLIDE 6

@etiene_d FOSDEM 2016

Lua Space


lua.space

slide-7
SLIDE 7

@etiene_d FOSDEM 2016

Web dev in Lua Sailor The future

slide-8
SLIDE 8

@etiene_d FOSDEM 2016

Web dev in Lua Sailor The future

slide-9
SLIDE 9

@etiene_d FOSDEM 2016

slide-10
SLIDE 10

@etiene_d FOSDEM 2016

http://www.humbedooh.com/presentations/ACNA%20-%20mod_lua.odp Introducing mod_lua by Daniel Gruno

slide-11
SLIDE 11

@etiene_d FOSDEM 2016

Servers

  • Apache: mod_lua
  • Nginx: OpenResty
slide-12
SLIDE 12

@etiene_d FOSDEM 2016

Servers

  • Apache: mod_lua
  • Nginx: OpenResty



 
 


slide-13
SLIDE 13

@etiene_d FOSDEM 2016

Servers

  • Apache: mod_lua
  • Nginx: OpenResty
  • Xavante
  • Others: Lighttpd, Lwan, Pegasus, Mongoose
slide-14
SLIDE 14

@etiene_d FOSDEM 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

slide-15
SLIDE 15

@etiene_d FOSDEM 2016

Web dev in Lua Sailor The future

slide-16
SLIDE 16

@etiene_d FOSDEM 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!
slide-17
SLIDE 17

@etiene_d FOSDEM 2016

slide-18
SLIDE 18

@etiene_d FOSDEM 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
slide-19
SLIDE 19

@etiene_d FOSDEM 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?

slide-20
SLIDE 20

@etiene_d FOSDEM 2016

Not so great things

  • It’s still in early development
  • Things are changing fast
  • It lacks features
  • Documentation
slide-21
SLIDE 21

@etiene_d FOSDEM 2016

How to get Sailor!

$ luarocks install sailor
 $ sailor create ‘My App’ /var/www
 $ cd /var/www/my_app
 $ lua start-server.lua

slide-22
SLIDE 22

@etiene_d FOSDEM 2016

slide-23
SLIDE 23

@etiene_d FOSDEM 2016

/conf /controllers /models /pub /runtime /tests /themes /views

App structure

slide-24
SLIDE 24

@etiene_d FOSDEM 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

slide-25
SLIDE 25

@etiene_d FOSDEM 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!

slide-26
SLIDE 26

@etiene_d FOSDEM 2016

slide-27
SLIDE 27

@etiene_d FOSDEM 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!

slide-28
SLIDE 28

@etiene_d FOSDEM 2016

slide-29
SLIDE 29

@etiene_d FOSDEM 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!

slide-30
SLIDE 30

@etiene_d FOSDEM 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!

slide-31
SLIDE 31

@etiene_d FOSDEM 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!

slide-32
SLIDE 32

@etiene_d FOSDEM 2016

Web dev in Lua Sailor The future

slide-33
SLIDE 33

@etiene_d FOSDEM 2016

Rails Girls Summer of Code

slide-34
SLIDE 34

@etiene_d FOSDEM 2016

bit.ly/luawebdev

slide-35
SLIDE 35

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

slide-36
SLIDE 36

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

gitter.im/sailorproject/sailor

slide-37
SLIDE 37

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

slide-38
SLIDE 38

Thank you!

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