diff --git a/README_ru.md b/README_ru.md index ebff3d4..b60cee2 100644 --- a/README_ru.md +++ b/README_ru.md @@ -131,11 +131,11 @@ AIO Launcher включает в себя интерпретатор LuaJ 3.0.1 * `get_index(table, value)` - возвращает индекс элемента таблицы; * `get_key(table, value)` - возвращает ключ элемента таблицы; * `round(x, n)` - округляет число; -* `md_colors` - таблица цветов Material Design (исходник есть в этом репозитории, [справка](https://materialui.co/colors)); В комплект также входят: -* url - функции для кодирования/декодирования строки в URL из библиотеки Lua Penlight; +* `md_colors` - модуль-таблица цветов Material Design (исходник есть в этом репозитории, [справка](https://materialui.co/colors)); +* `url` - модуль с функциями для кодирования/декодирования строки в URL из библиотеки Lua Penlight; * [luaDate](https://github.com/Tieske/date) - функции для работы со временем; * [json.lua](https://github.com/rxi/json.lua) - парзер JSON; * [SLAXDOM](https://github.com/Phrogz/SLAXML) - парзер XML; diff --git a/lib/md_colors.lua b/lib/md_colors.lua index 44a59f0..6debba1 100644 --- a/lib/md_colors.lua +++ b/lib/md_colors.lua @@ -293,3 +293,5 @@ md_colors = { blue_grey_800="#37474F", blue_grey_900="#263238", } + +return md_colors diff --git a/lib/url.lua b/lib/url.lua new file mode 100644 index 0000000..8c7cfeb --- /dev/null +++ b/lib/url.lua @@ -0,0 +1,51 @@ +--- Python-style URL quoting library. +-- +-- @module pl.url + +local url = {} + +local function quote_char(c) + return string.format("%%%02X", string.byte(c)) +end + +--- Quote the url, replacing special characters using the '%xx' escape. +-- @string s the string +-- @bool quote_plus Also escape slashes and replace spaces by plus signs. +-- @return The quoted string, or if `s` wasn't a string, just plain unaltered `s`. +function url.quote(s, quote_plus) + if type(s) ~= "string" then + return s + end + + s = s:gsub("\n", "\r\n") + s = s:gsub("([^A-Za-z0-9 %-_%./])", quote_char) + if quote_plus then + s = s:gsub(" ", "+") + s = s:gsub("/", quote_char) + else + s = s:gsub(" ", "%%20") + end + + return s +end + +local function unquote_char(h) + return string.char(tonumber(h, 16)) +end + +--- Unquote the url, replacing '%xx' escapes and plus signs. +-- @string s the string +-- @return The unquoted string, or if `s` wasn't a string, just plain unaltered `s`. +function url.unquote(s) + if type(s) ~= "string" then + return s + end + + s = s:gsub("+", " ") + s = s:gsub("%%(%x%x)", unquote_char) + s = s:gsub("\r\n", "\n") + + return s +end + +return url diff --git a/main/actions-widget.lua b/samples/actions-widget.lua similarity index 94% rename from main/actions-widget.lua rename to samples/actions-widget.lua index c37498c..1e34942 100644 --- a/main/actions-widget.lua +++ b/samples/actions-widget.lua @@ -4,6 +4,8 @@ -- author = "Evgeny Zobnin (zobnin@gmail.com)" -- version = "1.0" +md_colors = require "md_colors" + function on_resume() actions_names = { "Drawer", "Search", "Notify", "Menu" } actions_colors = { md_colors.purple_800, md_colors.purple_600, md_colors.purple_400, md_colors.purple_300 } diff --git a/samples/app-buttons-sample.lua b/samples/app-buttons-sample.lua index c2d1984..3aeb328 100644 --- a/samples/app-buttons-sample.lua +++ b/samples/app-buttons-sample.lua @@ -1,3 +1,5 @@ +md_colors = require "md_colors" + function on_resume() apps_names = { "Telegram", "WhatsApp", "Google PLay" } apps_pkgs = { "org.telegram.messenger.web", "com.whatsapp", "com.android.vending" }