-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
nav.lua
56 lines (45 loc) · 1.17 KB
/
nav.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local GazetteMessages = require("gazettemessages")
local Item = require("libs/gazette/epub/package/item")
local xml2lua = require("libs/xml2lua/xml2lua")
local Nav = Item:new{
title = nil,
items = nil,
}
function Nav:new(o)
o = o or {}
self.__index = self
setmetatable(o, self)
o.title = GazetteMessages.DEFAULT_NAV_TITLE
o.path = "nav.xhtml"
o.properties = Item.PROPERTY.NAV
o.media_type = "application/xhtml+xml"
o.items = {},
o:generateId()
return o
end
function Nav:setTitle(title)
self.title = title
end
function Nav:addItem(item)
-- insert item, yes, but reference it by it's id...
table.insert(self.items, item)
end
function Nav:getContent()
-- TODO: Add error catching/display
local template, err = xml2lua.loadFile("plugins/gazette.koplugin/libs/gazette/epub/templates/nav.xhtml")
local items_list = "\n"
for _, item in ipairs(self.items) do
local part = item:getNavPart()
if part
then
items_list = items_list .. part
end
end
template = string.format(
template,
self.title,
items_list
)
return template
end
return Nav