Add support for entry aliases
This commit is contained in:
parent
c18a3c43f5
commit
1f0680803b
27
init.lua
27
init.lua
@ -22,6 +22,7 @@ function doc.new_category(id, def)
|
|||||||
doc.data.categories[id] = {}
|
doc.data.categories[id] = {}
|
||||||
doc.data.categories[id].entries = {}
|
doc.data.categories[id].entries = {}
|
||||||
doc.data.categories[id].def = def
|
doc.data.categories[id].def = def
|
||||||
|
doc.data.categories[id].entry_aliases = {}
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
@ -68,12 +69,27 @@ end
|
|||||||
-- * This category contains the specified entry
|
-- * This category contains the specified entry
|
||||||
function doc.entry_exists(category_id, entry_id)
|
function doc.entry_exists(category_id, entry_id)
|
||||||
if doc.data.categories[category_id] ~= nil then
|
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
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
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 ]]
|
--[[ Functions for internal use ]]
|
||||||
|
|
||||||
function doc.formspec_core(tab)
|
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 = "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]"
|
formstring = formstring .. "button[0,1;3,1;doc_button_goto_category;Go to entry list]"
|
||||||
else
|
else
|
||||||
|
|
||||||
local category = doc.data.categories[category_id]
|
local category = doc.data.categories[category_id]
|
||||||
local entry = category.entries[entry_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 = "label[0,0;Help > "..category.def.name.." > "..entry.name.."]"
|
||||||
formstring = formstring .. category.def.build_formspec(entry.data)
|
formstring = formstring .. category.def.build_formspec(entry.data)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user