Skip to content

Commit

Permalink
Merge pull request #8 from sailorproject/master
Browse files Browse the repository at this point in the history
pull from master
  • Loading branch information
r-nikhil committed Oct 22, 2016
2 parents e454897 + 9349bd5 commit c96ee68
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ before_script:

script:
- cd test/dev-app
- if [ "$SERVER" != "openresty" ]; then sailor test --verbose --coverage; fi
- if [ "$SERVER" != "openresty" ]; then sailor test -- --verbose --coverage; fi
- if [ "$SERVER" == "openresty" ]; then sailor test --resty; fi

after_success:
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ A Lua MVC Framework. www.sailorproject.org
* Relations
* Model generation (reading from DB)
* CRUD generation (reading from model)
* Theme and layout (now you can have multiple layouts inside a theme. e.g. 1-column and 2-column)
* Theme and layout (now you can have multiple layouts within a theme. e.g. 1-column and 2-column)
* Integration with Busted for unit and functional tests for your app


Expand All @@ -52,9 +52,9 @@ More about the motivation to build this project can be found here: http://etiene

### Directory tree info
* /docs - this one is supposed to have documentation
* /lua-to-js-vms - different Lua->Javascript virtual machines for use of Lua on the browser with Sailor
* /lua-to-js-vms - different Lua->Javascript virtual machines for use of Lua in the browser with Sailor
* /rockspecs - Rockspec files for LuaRocks install
* /src - Lua modules with nice stuff from sailor and other places.
* /src - Lua modules with nice stuff from Sailor and other places.
* /sailor - Sailor modules
* /sailor/blank-app - blank Sailor web app, can be copy-pasted as base for your own apps
* /test - apps for testing and demonstration purposes
Expand Down Expand Up @@ -152,5 +152,3 @@ https://twitter.com/etiene_d


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

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Etiene/sailor/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
9 changes: 9 additions & 0 deletions docs/manual_page_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ Will inspect a var and print the result on the bottom of the page. It can be tog

Example 1: `page:inspect( page.POST )`

####page:enable_cors([headers] )
Sends [CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#The_HTTP_response_headers) to the client.

* headers: [optional] table, contains which headers to pass, if nil then `Access-Control-Allow-Origin = "*"` is used. They keys are (allow_origin, expose_headers, max_age, allow_credentials, allow_methods, allow_headers).

Example 1: `page:enable_cors()`

Example 2: `page:enable_cors({allow_origin = "http://sailorproject.org"})`

####page.POST
* table: contains the POST data, empty table if there is no POST data.

Expand Down
4 changes: 4 additions & 0 deletions rockspecs/sailor-current-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies = {
'remy >= 0.2',
'latclient >= 0.4',
'dkjson ~> 2.5',
'argparse',
'ansicolors'
}
build = {
type = "builtin",
Expand All @@ -47,11 +49,13 @@ build = {
['sailor.blank-app.tests.functional.dummy'] = "src/sailor/blank-app/tests/functional/dummy.lua",
['sailor.blank-app.index'] = "src/sailor/blank-app/index.lua",
['sailor.blank-app.index-magnet'] = "src/sailor/blank-app/index-magnet.lua",
['sailor.cli'] = "src/sailor/cli.lua",
['sailor.form'] = "src/sailor/form.lua",
['sailor.model'] = "src/sailor/model.lua",
['sailor.session'] = "src/sailor/session.lua",
['sailor.page'] = "src/sailor/page.lua",
['sailor.test'] = "src/sailor/test.lua",
['sailor.version'] = "src/sailor/version.lua",
['web_utils.lp'] = "src/web_utils/lp.lua",
['web_utils.lp_ex'] = "src/web_utils/lp_ex.lua",
['web_utils.serialize'] = "src/web_utils/serialize.lua",
Expand Down
213 changes: 62 additions & 151 deletions sailor
Original file line number Diff line number Diff line change
@@ -1,160 +1,71 @@
#!/usr/bin/env lua

--------------------------------------------------------------------------------
-- sailor v0.5: Command line utility for sailor
-- sailor v0.6.2: Command line utility for sailor
-- This file is a part of Sailor project
-- Copyright (c) 2014 Etiene Dalcol <dalcol@etiene.net>
-- License: MIT
-- http://sailorproject.org
--------------------------------------------------------------------------------

local lfs = require "lfs"

local function help()
print("\27[31mUsage: sailor command\27[0m \n")
print("Commands:")
print(" \27[31mcreate Usage: sailor create NAME [PATH]\27[0m")
print(" Generates web application in a directory.")
print(" NAME The name of your application.")
print(" PATH Optional. The path to where you wish your app to be created. \n\t\tIf not specified, the app will be created at the current dir.\n")
print(" \27[31mExample:\27[0m sailor create 'Hey Arnold' /var/www")
print(" This will create your web app under /var/www/hey_arnold.\n")
print(" \27[31mtest\t\tUsage: sailor test [FLAGS]\27[0m")
print(" Will run the tests specified for an application.")
print(" Must be called from the base dir of the application.")
print(" FLAGS Optional. Flags for the Busted library.")
print("\n \27[31menable\tUsage: sailor enable NAME\27[0m")
print(" Will install an extension to Sailor and copy necessary files to your app.")
print(" Must be called from the base dir of the application.")
print(" NAME The name of the extension to be enabled.")
print("\nOptions:")
print(" --help Shows help message.")
print("")
end

local function get_sailor_path(current_dir)
local sailor_path = ((debug.getinfo(1).source):match("^@?(.-)/sailor$"))

local f = sailor_path and io.open(sailor_path.."/src/sailor.lua", "r")
if not f then
local datafile = require("datafile")
sailor_path = datafile.path("sailor/cookie.lua"):match("^@?(.-)/sailor/cookie.lua$")
else
f:close()
if sailor_path == '.' then
sailor_path = current_dir.."/src"
elseif sailor_path:match("^.") then
local path = sailor_path:match(".(.-)")
sailor_path = current_dir.."/sailor"..tostring(path).."/src"
elseif not sailor_path:match("^/") then
sailor_path = current_dir.."/src/"..sailor_path
else
sailor_path = sailor_path.."/src"
end
end
return sailor_path
end

local function error()
print("\27[33mError generating sailor web app.\27[0m ")
print("Please report to developers.")
end

local function create()
local name = string.gsub(arg[2]:lower(),' ','_')
local current_dir = lfs.currentdir()
local destiny = arg[3] or current_dir

local sailor_path = get_sailor_path(current_dir)

local raw_app = sailor_path.."/sailor/blank-app"
local new_app = destiny.."/"..name
assert(os.execute("cp -a '"..raw_app.."' '"..new_app.."'"))

local htaccess = assert(io.open (new_app.."/.htaccess" , "r"))
local src = htaccess:read("*a")
htaccess:close()

htaccess = assert(io.open (new_app.."/.htaccess" , "w"))
src = string.gsub(src,"{{path}}",sailor_path)
htaccess:write(src)
htaccess:close()

local conf = assert(io.open (new_app.."/conf/conf.lua" , "r"))
src = conf:read("*a")
conf:close()
conf = assert(io.open (new_app.."/conf/conf.lua" , "w"))
src = string.gsub(src,"Sailor! A Lua MVC Framework",arg[2])
conf:write(src)
conf:close()

print("done!")
end

local function test()
local resty = false
local flags = ''
for i=2,#arg do
if arg[i] == '--resty' then
resty = true
else
flags = flags..arg[i]..' '
end
end
local ok, code
if resty then
ok, code = os.execute('resty tests/bootstrap_resty.lua')
else
ok, code = os.execute('busted --helper=tests/bootstrap.lua '..flags..'tests/unit/* tests/functional/*')
end

if type(ok) == "number" then return ok end -- Lua 5.1 just returns the status code
return ok and 0 or 1 -- don't care about actual value
end

local function enable()
local name = 'sailor-'..arg[2]
local current_dir = lfs.currentdir()
local sailor_path = get_sailor_path(current_dir)

assert(os.execute('luarocks install '..name))

local ext_app = sailor_path.."/sailor/"..arg[2].."/app"
assert(os.execute("mkdir -p extensions"))
local err = assert(os.execute("cp -a '"..ext_app.."' extensions/"..arg[2]))
if err == 0 then
local index_file = assert(io.open ("index.lua" , "r"))
local src = index_file:read("*a")
index_file:close()

local package_path = "package.path = base_dir..'extensions/"..arg[2].."/?.lua;'..package.path"
src = string.gsub(src,"\nlocal sailor",package_path.."\n\nlocal sailor")
index_file = assert(io.open ("index.lua" , "w"))
index_file:write(src)
index_file:close()
print("New files:")
print("extensions/"..arg[2].."/*\n")
print("Files modified:")
print("index.lua\n")
print("done!")
end
end

local function run()

if (arg[1] == 'create' or arg[1] == 'c') and arg[2] then
create()
elseif arg[1] == 'test' or arg[1] == 't' then
return test()
elseif arg[1] == 'enable' and arg[2] then
enable()
else
help()
end
end

local exit_code = run()
if exit_code and exit_code ~= 0 then
-- exit code sometimes is > 255 and fails to be propagated
os.exit(1, true)
end
local argparse = require "argparse"
local colors = require "ansicolors"
local actions = require "sailor.cli"


local parser = argparse("script", colors("%{bright yellow}Sailor command line utility"))
:name(string.match(arg[0], "/*(%w+)/*$")) -- this file name, usually will be "sailor"
:epilog("For more info see http://sailorproject.org")
:require_command(false)

local create_cmd = parser:command("c create", "Generates web application in a directory.")
:action(actions.create)
create_cmd:usage(colors("%{bright red}Usage: sailor create NAME [PATH]"))
create_cmd:argument("name", "The name of your application.")
create_cmd:argument("path", "The path to where you wish your app to be created."):default(".")
create_cmd:epilog(colors([[
Example: %{bright red} sailor create 'Hey Arnold' /var/www %{reset}
This will create your web app under /var/www/hey_arnold.]]))

local test_cmd = parser:command("t test", "Runs the tests specified for an application. Must be called from the base dir of the application.")
:action(actions.test)
test_cmd:usage(colors"%{bright red}Usage: sailor test [--resty] [-- EXTRA_FLAGS]")
test_cmd:argument("EXTRA_FLAGS", "Flags that will be passed to the Busted library."):args("*")
test_cmd:flag("--resty", "Run the tests using the resty bootstrap.", false)

local enable_cmd = parser:command("e enable", "Installs an extension to Sailor and copy necessary files to your app. Must be called from the base dir of the application.")
:action(actions.enable)
enable_cmd:usage(colors("%{bright red}Usage: sailor enable NAME"))
enable_cmd:argument("name", "The name of the extension to be enabled.")


local gen_cmd = parser:command("g gen", "Generates some scaffolding for your app.")
gen_cmd:usage(colors("%{bright red}Usage: sailor gen COMMAND ARG"))
gen_cmd:epilog(colors([[
Example: %{bright red} sailor gen model users%{reset}
Given a table called 'users' exist in the database, this will generate a model based on it.]]))

local model_cmd = gen_cmd:command("m model", "Generates a basic model based on an existing table on the database.")
:action(actions.gen_model)
model_cmd:argument("table_name", "The name of the database table that the model should reflect.")
model_cmd:usage(colors("%{bright red}Usage: sailor gen model TABLE_NAME"))

local crud_cmd = gen_cmd:command("crud c", "Generates Create-Read-Update-Delete scaffolding for a given model name.")
:action(actions.gen_crud)
crud_cmd:argument("model_name", "The name of the model table that CRUD should act on.")
crud_cmd:usage(colors("%{bright red}Usage: sailor gen crud MODEL_NAME"))

local all_cmd = gen_cmd:command("a all", "Generates both the model and a CRUD for an existing table name.")
:action(actions.gen_all)
all_cmd:argument("table_name", "The name of the database table that the model and the CRUD should reflect.")
all_cmd:usage(colors("%{bright red}Usage: sailor gen all TABLE_NAME"))

local start_cmd = parser:command("s start", "Runs a Sailor app starting Xavante webserver.")
:action(actions.start)
enable_cmd:usage(colors("%{bright red}Usage: sailor start"))

parser:flag("-v --version", "Show the current Sailor version installed and exit.", false):action(actions.version)

parser:usage(parser:get_help())

local args = parser:parse()
4 changes: 2 additions & 2 deletions src/sailor.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--------------------------------------------------------------------------------
-- sailor.lua, v0.5.2.2: core functionalities of the framework
-- sailor.lua, v0.5.3: core functionalities of the framework
-- This file is a part of Sailor project
-- Copyright (c) 2014 Etiene Dalcol <dalcol@etiene.net>
-- License: MIT
Expand All @@ -13,7 +13,7 @@ local sailor = {
conf = conf.sailor,
_COPYRIGHT = "Copyright (C) 2014-2015 Etiene Dalcol",
_DESCRIPTION = "Sailor is a framework for creating MVC web applications.",
_VERSION = "Sailor 0.5.2",
_VERSION = require "sailor.version",
}

-- Loads Lua@client's settings from Sailor conf.
Expand Down
2 changes: 1 addition & 1 deletion src/sailor/blank-app/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ http {
}
}
location ~ \.(css|eot|js|json|gif|jpg|png|svg|ttf|woff)$ {
location ~ \.(css|eot|js|json|gif|jpg|png|svg|ttf|woff|map)$ {
}
}
}
1 change: 0 additions & 1 deletion src/sailor/blank-app/themes/default/main.lp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">

<title><%=page.title%></title>

Expand Down

0 comments on commit c96ee68

Please sign in to comment.