-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes logic from inspect.lp and puts on the page object, creating an useful function that can be used for tracing errors. Page.tostring will pass variables recursively to readable form. For example, breaking lines for table rows and indenting on multi-levels tables.
- Loading branch information
Showing
3 changed files
with
24 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-------------------------------------------------------------------------------- | ||
-- sailor.lua, v0.4.10: core functionalities of the framework | ||
-- sailor.lua, v0.4.11: core functionalities of the framework | ||
-- This file is a part of Sailor project | ||
-- Copyright (c) 2014 Etiene Dalcol <[email protected]> | ||
-- License: MIT | ||
|
@@ -98,6 +98,7 @@ function sailor.init(r) | |
redirect = Page.redirect, | ||
include = Page.include, | ||
inspect = Page.inspect, | ||
tostring = Page.tostring, | ||
write = function(_,...) r:write(...) end, | ||
print = function(_,...) r:puts(...) end, | ||
GET = GET, | ||
|
@@ -240,6 +241,26 @@ function Page:inspect(value,message) | |
end | ||
end | ||
|
||
function Page:tostring (val, indent, sep, ln, inspect) | ||
indent = indent or 0 | ||
inspect = inspect or '' | ||
sep = sep or ' ' | ||
ln = ln or "<br/>" | ||
|
||
if type(val) ~= "table" then | ||
inspect = inspect .. tostring(val) | ||
else | ||
for k, v in pairs(val) do | ||
if(k ~= "__newindex") then | ||
local formatting = ln..string.rep(sep, indent) .. k .. ": " | ||
inspect = inspect.. formatting | ||
inspect = self:tostring(v, indent+8, sep, ln, inspect) | ||
end | ||
end | ||
end | ||
return inspect | ||
end | ||
|
||
-- Auxiliary function to open the autogen page for models and CRUDs | ||
-- page: our page object | ||
local function autogen(page) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters