aboutsummaryrefslogtreecommitdiff
path: root/helpers.lua
diff options
context:
space:
mode:
authorArvydas Sidorenko <asido4@gmail.com>2012-06-15 17:34:25 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2012-06-18 01:26:24 +0200
commitb6b52900930ddb2a5b958a6d314766b455358164 (patch)
tree462746dac9357edca9a9216827529db557002ebe /helpers.lua
parent0741531efd4bec3bd6836f8ea535e14daf5e2146 (diff)
downloadvicious-legacy-b6b52900930ddb2a5b958a6d314766b455358164.tar.xz
Ported vicious module to lua 5.2
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com> Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
Diffstat (limited to 'helpers.lua')
-rw-r--r--helpers.lua22
1 files changed, 13 insertions, 9 deletions
diff --git a/helpers.lua b/helpers.lua
index 223c5f1..93a701b 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -23,7 +23,8 @@ local string = {
-- Helpers: provides helper functions for vicious widgets
-module("vicious.helpers")
+-- vicious.helpers
+local helpers = {}
-- {{{ Variable definitions
@@ -32,14 +33,14 @@ local scroller = {}
-- {{{ Helper functions
-- {{{ Loader of vicious modules
-function wrequire(table, key)
+function helpers.wrequire(table, key)
local module = rawget(table, key)
return module or require(table._NAME .. "." .. key)
end
-- }}}
-- {{{ Expose path as a Lua table
-function pathtotable(dir)
+function helpers.pathtotable(dir)
return setmetatable({ _path = dir },
{ __index = function(table, index)
local path = table._path .. '/' .. index
@@ -61,7 +62,7 @@ end
-- }}}
-- {{{ Format a string with args
-function format(format, args)
+function helpers.format(format, args)
for var, val in pairs(args) do
format = format:gsub("$" .. (tonumber(var) and var or
var:gsub("[-+?*]", function(i) return "%"..i end)),
@@ -73,7 +74,7 @@ end
-- }}}
-- {{{ Format units to one decimal point
-function uformat(array, key, value, unit)
+function helpers.uformat(array, key, value, unit)
for u, v in pairs(unit) do
array["{"..key.."_"..u.."}"] = string.format("%.1f", value/v)
end
@@ -83,7 +84,7 @@ end
-- }}}
-- {{{ Escape a string
-function escape(text)
+function helpers.escape(text)
local xml_entities = {
["\""] = "&quot;",
["&"] = "&amp;",
@@ -97,7 +98,7 @@ end
-- }}}
-- {{{ Capitalize a string
-function capitalize(text)
+function helpers.capitalize(text)
return text and text:gsub("([%w])([%w]*)", function(c, s)
return string.upper(c) .. s
end)
@@ -105,7 +106,7 @@ end
-- }}}
-- {{{ Truncate a string
-function truncate(text, maxlen)
+function helpers.truncate(text, maxlen)
local txtlen = text:len()
if txtlen > maxlen then
@@ -117,7 +118,7 @@ end
-- }}}
-- {{{ Scroll through a string
-function scroll(text, maxlen, widget)
+function helpers.scroll(text, maxlen, widget)
if not scroller[widget] then
scroller[widget] = { i = 1, d = true }
end
@@ -146,4 +147,7 @@ function scroll(text, maxlen, widget)
return text
end
-- }}}
+
+return helpers
+
-- }}}