From b6b52900930ddb2a5b958a6d314766b455358164 Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Fri, 15 Jun 2012 17:34:25 +0200 Subject: Ported vicious module to lua 5.2 Signed-off-by: Arvydas Sidorenko Signed-off-by: Adrian C. (anrxc) --- helpers.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'helpers.lua') 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 = { ["\""] = """, ["&"] = "&", @@ -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 + -- }}} -- cgit v1.2.3