summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2016-07-25 18:28:51 +0200
committerWuzzy <almikes@aol.com>2016-07-25 18:28:51 +0200
commit1f0680803b6e93b7958f7743b4dcf0f5e17af90b (patch)
tree0baa96a09a931347bbc10f517d73d95599965550
parentc18a3c43f51321e44dc22e6b38ae5816a29cef9c (diff)
Add support for entry aliases
-rw-r--r--init.lua27
1 files changed, 26 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index f2c2f56..80d510d 100644
--- a/init.lua
+++ b/init.lua
@@ -22,6 +22,7 @@ function doc.new_category(id, def)
doc.data.categories[id] = {}
doc.data.categories[id].entries = {}
doc.data.categories[id].def = def
+ doc.data.categories[id].entry_aliases = {}
return true
else
return false
@@ -68,12 +69,27 @@ end
-- * This category contains the specified entry
function doc.entry_exists(category_id, entry_id)
if doc.data.categories[category_id] ~= nil then
- return doc.data.categories[category_id].entries[entry_id] ~= nil
+ if doc.data.categories[category_id].entries[entry_id] ~= nil then
+ -- Entry exists
+ return true
+ else
+ -- Entry of this ID does not exist, so we check if there's an alis for it
+ return doc.data.categories[category_id].entry_aliases[entry_id] ~= nil
+ end
else
return false
end
end
+-- Adds aliases for an entry. Attempting to open an entry by an alias name
+-- results in opening the entry of the original name.
+-- Aliases are true within one category only.
+function doc.add_entry_aliases(category_id, entry_id, aliases)
+ for a=1,#aliases do
+ doc.data.categories[category_id].entry_aliases[aliases[a]] = entry_id
+ end
+end
+
--[[ Functions for internal use ]]
function doc.formspec_core(tab)
@@ -165,8 +181,17 @@ function doc.formspec_entry(category_id, entry_id)
formstring = "label[0,0;You haven't selected an help entry yet. Please select one in the list of entries first.]"
formstring = formstring .. "button[0,1;3,1;doc_button_goto_category;Go to entry list]"
else
+
local category = doc.data.categories[category_id]
local entry = category.entries[entry_id]
+ -- Check if entry has an alias
+ if entry == nil then
+ local resolved_alias = doc.data.categories[category_id].entry_aliases[entry_id]
+ if resolved_alias ~= nil then
+ entry = category.entries[resolved_alias]
+ end
+ end
+
formstring = "label[0,0;Help > "..category.def.name.." > "..entry.name.."]"
formstring = formstring .. category.def.build_formspec(entry.data)
end