summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Mason <ms13sp@gmail.com>2007-11-28 22:04:59 +0000
committerMike Mason <ms13sp@gmail.com>2007-11-28 22:04:59 +0000
commita156a6951d673883333d19d5bd73df260451e58a (patch)
tree6975e1f2336fc7db45876d3ff49b966f24ad2693
parent118583621442b97aa0855b8e2d55d4ee1e8852a1 (diff)
downloadacf-core-a156a6951d673883333d19d5bd73df260451e58a.tar.bz2
acf-core-a156a6951d673883333d19d5bd73df260451e58a.tar.xz
Lots of changes. fs.lua now only has file/filesystem functions. format.lua added to be convert/sytle format changes. join.lua and split.lua put in format now. May delete later.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@385 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--lib/Makefile1
-rw-r--r--lib/README17
-rw-r--r--lib/date.lua6
-rw-r--r--lib/format.lua119
-rw-r--r--lib/fs.lua83
5 files changed, 135 insertions, 91 deletions
diff --git a/lib/Makefile b/lib/Makefile
index a424009..3089928 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -4,6 +4,7 @@ LIB_DIST=fs.lua\
html.lua\
join.lua\
date.lua\
+ format.lua\
menubuilder.lua\
pidof.lua\
privsep.lua\
diff --git a/lib/README b/lib/README
index 0d650dc..afd175c 100644
--- a/lib/README
+++ b/lib/README
@@ -1,12 +1,13 @@
Brief discription of libs so far. For more info see
http://wiki.alpinelinux.org/w/index.php?title=ACF_Libraries
+Also we use Lua Posix for the rest of the functionality.
+
+*** These are currently being worked on. ***
date.lua - Date and Time functions
-fs.lua - Many file,string,and table type functions. May need to be renamed
-join.lua - Takes a table and given a delimeter makes it into a string
+fs.lua - File and filesystem library
pidof.lua - Process libraries not provided by LPOSIX
-split.lua - Take a delimeted string and makes it into a table
-date.lua - Date and Time lua functions
+format.lua - Library to help reformat string,tables,files or any input. Good place for split and join
validator.lua - Validate web input for ACF.
html.lua - Helps with form building in ACF
@@ -15,4 +16,10 @@ web_elements.lua - More web functionality for ACF
privsep.lua - Helps with authorization with ACF
session.lua -Helps with Session mangement in ACF
-These are currently being worked on. Also we use Lua Posix for the rest of the functionality.
+*** THESE MAY GO AWAY. PUT IN format.lua ***
+
+join.lua - Takes a table and given a delimeter makes it into a string
+*** Added to format.lua as format.table_to_string ***
+split.lua - Take a delimeted string and makes it into a table
+*** Added to format.lua as format.string_to_table ***
+
diff --git a/lib/date.lua b/lib/date.lua
index 0a236cc..2d8dab6 100644
--- a/lib/date.lua
+++ b/lib/date.lua
@@ -3,7 +3,7 @@
module(..., package.seeall)
require("posix")
-require("fs")
+require("format")
--global for date formating see below for more information
--Mon Nov 26 19:56:10 UTC 2007 looks like most systems use this
@@ -96,7 +96,7 @@ end
function string_to_table (str)
if str == nil then str = os.date(format) end
g = {}
- temp = fs.string_to_table("%s",str)
+ temp = format.string_to_table("%s",str)
month = abr_month_num(temp[2])
g["month"] = month
day = temp[3]
@@ -105,7 +105,7 @@ function string_to_table (str)
tz = temp[5]
year = temp[6]
g["year"] = year
- temp2 = fs.string_to_table(":",temp[4])
+ temp2 = format.string_to_table(":",temp[4])
hour = temp2[1]
g["hour"] = hour
min = temp2[2]
diff --git a/lib/format.lua b/lib/format.lua
new file mode 100644
index 0000000..b650ca6
--- /dev/null
+++ b/lib/format.lua
@@ -0,0 +1,119 @@
+--[[
+ module for format changes in table,string,files...
+ try to keep non input specific
+]]--
+
+module (..., package.seeall)
+
+require ("posix")
+require ("fs")
+require ("session")
+
+-- find all return characters and removes them, may get this from a browser
+-- that is why didn't do file specific
+
+function dostounix ( a )
+ local data = string.gsub(a, "\r", "")
+ return data
+
+end
+
+-- search and remove all blank lines and commented lines in a file
+
+function remove_blanks_comments ( path )
+f = fs.read_file_as_array(path)
+local lines = {}
+for _,line in pairs(f) do
+local c = string.match(line, "^$") or string.match(line, "^%#")
+if c == nil then lines[#lines + 1] = line end
+end
+-- returns a table to iterate over without the blank or commented lines
+return lines
+end
+
+function cap_begin_word ( a )
+ --first need to do the first word
+ local data = string.gsub(a, "^%l", string.upper)
+ --word is any space cause no <> regex
+ data = string.gsub(data, " %l", string.upper)
+ return data
+end
+
+
+-- This code comes from http://lua-users.org/wiki/SplitJoin
+-- -- example: format.table_to_string(", ", {"Anna", "Bob", "Charlie", "Dolores"})
+function table_to_string (delimiter, list)
+ local len = getn(list)
+ if len == 0 then
+ return ""
+ end
+ local string = list[1]
+ for i = 2, len do
+ string = string .. delimiter .. list[i]
+ end
+ return string
+end
+
+-- This code comes from http://lua-users.org/wiki/SplitJoin
+-- example: format.string_to_table(",%s*", "Anna, Bob, Charlie,Dolores")
+function string_to_table (delimiter, text)
+ local list = {}
+ local pos = 1
+ -- this would result in endless loops
+ if string.find("", delimiter, 1) then
+ error("delimiter matches empty string!")
+ end
+ while 1 do
+ local first, last = string.find(text, delimiter, pos)
+ if first then -- found?
+ table.insert(list, string.sub(text, pos, first-1))
+ pos = last+1
+ else
+ table.insert(list, string.sub(text, pos))
+ break
+ end
+ end
+ return list
+end
+
+--these maybe moved to html or something like that
+
+-- give a cfe and get back a string of what is inside
+function cfe_unpack ( a )
+ if type(a) == "table" then
+ value = session.serialize("cfe", a)
+ return value
+ end
+
+end
+
+-- going to build more cfe to html functions below is just seeing what needed to be
+-- done for a test
+
+--give a lua table and unpack as html table
+--t = { {row1}, {row2} ,options= {border = 2,align="left" } }
+-- row one could technically be a title for the table ??? or t.title
+function table_unpack_html ( t )
+ --first need the options
+ if t.options ~= nil then
+ for a,b in pairs(t.options) do
+ if opt == nil then opt = a .. "=" .. "\"" .. b .. "\"" else
+ opt = opt .. " " .. a .. "=" .. "\"" .. b .. "\"" end
+
+ end
+ html_table = "<table " .. opt .. ">"
+ else
+ html_table = "<table>"
+ end
+
+ for i = 1,table.maxn(t) do
+ html_table = html_table .. "<tr>"
+ for a,b in ipairs(t[i]) do
+ html_table = html_table .. "<td>" .. b .. "</td>"
+ end
+ html_table = html_table .. "</tr>"
+
+ end
+ html_table = html_table .. "</table>"
+ return html_table
+end
diff --git a/lib/fs.lua b/lib/fs.lua
index 79d0cdc..abcb03d 100644
--- a/lib/fs.lua
+++ b/lib/fs.lua
@@ -51,53 +51,6 @@ function read_file_as_array ( path )
file:close()
return f
end
-
--- find all return characters and removes them, may get this from a browser
--- that is why didn't do file specific
-
-function dostounix ( a )
-local data = string.gsub(a, "\r", "")
-return data
-
-end
-
--- read a file without blank lines and commented lines
-
-function remove_blanks_comments ( path )
-local f = io.open(path)
-local lines = {}
-for line in f:lines() do
-local c = string.match(line, "^$") or string.match(line, "^%#")
-if c == nil then lines[#lines + 1] = line end
-end
--- returns a table to iterate over without the blank or commented lines
-return lines
-end
-
---will search and replace through the whole of the file and return a table
-
-function search_replace (path , find, replace)
-local f = fs.read_file_as_array(path)
-local lines = {}
-for a,b in ipairs(f) do
-local c = string.gsub(b, find, replace)
-lines[#lines + 1] = c end
-return lines
-end
-
---will interate over a ipairs(table) and make it into a string to be used by write_file
-function ipairs_string ( t )
- for a,b in ipairs(t) do
- if a == 1 then
- c = b
- else
- c = c .. "\n" .. b
- end
- end
- --add a friendly \n for EOF
- c = c .. "\n"
- return c
-end
-- write a string to a file !! MM-will replace file contents
@@ -155,39 +108,3 @@ function find ( what, where )
end
end
--- This code comes from http://lua-users.org/wiki/SplitJoin
--- -- example: strjoin(", ", {"Anna", "Bob", "Charlie", "Dolores"})
-function table_to_string (delimiter, list)
- local len = getn(list)
- if len == 0 then
- return ""
- end
- local string = list[1]
- for i = 2, len do
- string = string .. delimiter .. list[i]
- end
- return string
-end
-
--- This code comes from http://lua-users.org/wiki/SplitJoin
--- example: strsplit(",%s*", "Anna, Bob, Charlie,Dolores")
-function string_to_table (delimiter, text)
- local list = {}
- local pos = 1
- -- this would result in endless loops
- if string.find("", delimiter, 1) then
- error("delimiter matches empty string!")
- end
- while 1 do
- local first, last = string.find(text, delimiter, pos)
- if first then -- found?
- table.insert(list, string.sub(text, pos, first-1))
- pos = last+1
- else
- table.insert(list, string.sub(text, pos))
- break
- end
- end
- return list
-end
-