Coder Social home page Coder Social logo

sailor's Introduction

#Sailor A Lua MVC Framework. www.sailorproject.org

HuBoard badge Support via Gratipay

Development progress

So far I have integrated with @mascarenhas's Lua Pages as a nice templater for views, we also have controllers, a mailer module, routes, basic models, db connection, a validation module, integration with lua51.js so we can use Lua at client-side, basic form generation, sessions, basic authentication and some other stuff. We are now working on researching, refactoring, making Sailor compatible with more environments and making documentation for releasing a version 0.2 and a luarocks build. After that is done the roadmap is rewriting the DB module for benefiting from mod_lua's API, reviewing the session management, improving form generation, making models relate to each other and keep improving Sailor's compatibility.

More about this project's motivation can be found here: http://etiene.net/sailor-building-a-lua-based-mvc-framework/

Directory tree info

  • /docs - this one is supposed to have documentation
  • /src - Lua modules with nice stuff from sailor and other places.
  • /sailor - Sailor modules
  • /sailor/demo-app - default Sailor web app
  • /test - apps for testing and demonstration purposes

Supported Environments

Sailor has been tested under Linux, Mac OS X and Windows and is currently compatible with Apache with mod_lua or mod_pLua, Nginx with ngx_lua, or any CGI-enabled web server, like Civetweb or Mongoose, if CGILua is present.

Installation

For Linux, see INSTALL_LINUX.md

For Windows, see INSTALL_WIN.md

For Mac, see INSTALL_MAC.md

Using Sailor

A default Sailor app will have the following directory tree structure:

  • /conf - configuration files, open and edit them.
  • /controllers - controllers you will make!
  • /layouts - default layout files.
  • /models - models you will make!
  • /pub - publicly accessible files (js libraries, for example)
  • /runtime - temporary files generated during runtime.
  • /views - this is where your lua pages in .lp will go

Creating Pages

Go to /controllers and create your first controller! It should be a lua module. Name it whatever you want, our example is "site.lua". We will serve two pages, one accessible via /?r=site which will run site.index() by default and another one acessible via /?r=site/notindex.

local site = {}
function site.index(page)
  local foo = 'Hello world'
  local User = sailor.model("user")
  local u = User:new()
  u.username = "etiene"
  u.password = "a_password"
  local valid, err = u:validate() -- validate() will check if your attributes follow the rules!
  if not valid then
    foo = "Boohoo :("
  end

  -- Warning: this is a tech preview and some methods of model class do not avoid SQL injections yet.
  page:render('index',{foo=foo,name=u.username}) -- This will render /views/site/index.lp and pass the variables 'foo' and 'name'
end
function site.notindex(page)
  page:write('<b>Hey you!</b>')
end
return site

Go to /views, create a dir named 'site' to match your controller name and create your first page, our example is index.lp

<?=foo?>
<p>
  Hi, <?=name?>
</p>

For more information on what you can do with html and Lua Pages, visit http://keplerproject.github.io/cgilua/manual.html#templates

For more examples, you can check the test controller (/controllers/test.lua), the test views (/views/test/*) and the User model (/models/user.lua)

Suggestions or questions

[email protected]

http://twitter.com/etiene_d

If you are having trouble to get it working or if you got it working using different specs, please contact me so we can exchange info and I can improve this manual. Thanks!

sailor's People

Contributors

etiene avatar felipedaragon avatar adelgado avatar humbedooh avatar leokaplan avatar xspager avatar fooflare avatar mpeterv avatar

Watchers

James Cloos avatar ruanxianhuo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.