summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-10-20 14:29:04 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-10-20 14:29:04 +0200
commitc48cde4aedfae253a14163f28477c131afc9be43 (patch)
tree121b30539894a5824983c71d3d93ec77acc15c02
parentdbf48bf9f572908d39ca30c0f3975926ab1efeb8 (diff)
docs: move write_include out of the writer backend
This is a large chunk shared between backends.
-rw-r--r--src/scripts/elua/apps/docgen/util.lua4
-rw-r--r--src/scripts/elua/apps/docgen/writer.lua150
2 files changed, 78 insertions, 76 deletions
diff --git a/src/scripts/elua/apps/docgen/util.lua b/src/scripts/elua/apps/docgen/util.lua
index 7e14a37b6d..48e375da95 100644
--- a/src/scripts/elua/apps/docgen/util.lua
+++ b/src/scripts/elua/apps/docgen/util.lua
@@ -22,8 +22,8 @@ M.nspace_to_path = function(ns)
22 return ns:gsub(":", path_sep):gsub(rep_sep, path_sep):lower() 22 return ns:gsub(":", path_sep):gsub(rep_sep, path_sep):lower()
23end 23end
24 24
25M.make_page = function(path) 25M.make_page = function(path, ext)
26 return M.path_join(doc_root, "auto", path .. ".txt") 26 return M.path_join(doc_root, "auto", path .. "." .. ext)
27end 27end
28 28
29M.get_root_ns = function() 29M.get_root_ns = function()
diff --git a/src/scripts/elua/apps/docgen/writer.lua b/src/scripts/elua/apps/docgen/writer.lua
index 6dc47c1e39..67b6765596 100644
--- a/src/scripts/elua/apps/docgen/writer.lua
+++ b/src/scripts/elua/apps/docgen/writer.lua
@@ -63,6 +63,79 @@ local Buffer = {
63 end 63 end
64} 64}
65 65
66local write_include = function(self, tp, name, flags)
67 local it_to_tp = {
68 [self.INCLUDE_PAGE] = "page",
69 [self.INCLUDE_SECTION] = "section",
70 [self.INCLUDE_NAMESPACE] = "namespace",
71 [self.INCLUDE_TAG] = "tagtopic"
72 }
73 if type(name) == "table" then
74 if name[#name] == true then
75 name[#name] = nil
76 name = ":" .. root_nspace .. ":auto:"
77 .. table.concat(name, ":")
78 elseif name[#name] == false then
79 name[#name] = nil
80 name = ":" .. root_nspace .. ":user:"
81 .. table.concat(name, ":")
82 else
83 name = table.concat(name, ":")
84 end
85 end
86 self:write_raw("{{", it_to_tp[tp], ">", name);
87 if flags then
88 if tp == self.INCLUDE_SECTION and flags.section then
89 self:write_raw("#", flags.section)
90 end
91 flags.section = nil
92 local flstr = {}
93 for k, v in pairs(flags) do
94 local allow = allowed_incflags[k]
95 if allow ~= nil then
96 if type(allow) == "boolean" then
97 flstr[#flstr + 1] = k
98 elseif type(allow) == "number" or type(allow) == "string" then
99 if type(v) ~= type(allow) then
100 error("invalid value type for flag " .. k)
101 end
102 flstr[#flstr + 1] = k .. "=" .. v
103 elseif type(allow) == "table" then
104 if type(allow[1]) == "table" then
105 local valid = false
106 for i, vv in ipairs(allow[1]) do
107 if v == vv then
108 flstr[#flstr + 1] = k .. "=" .. v
109 valid = true
110 break
111 end
112 end
113 if not valid then
114 error("invalid value " .. v .. " for flag " .. k)
115 end
116 elseif type(allow[1]) == "string" and
117 type(allow[2]) == "string" then
118 if v then
119 flstr[#flstr + 1] = allow[1]
120 else
121 flstr[#flstr + 1] = allow[2]
122 end
123 end
124 end
125 else
126 error("invalid include flag: " .. tostring(k))
127 end
128 end
129 flstr = table.concat(flstr, "&")
130 if #flstr > 0 then
131 self:write_raw("&", flstr)
132 end
133 end
134 self:write_raw("}}")
135 self:write_nl()
136 return self
137end
138
66M.set_backend = function(bend) 139M.set_backend = function(bend)
67 M.Writer = assert(writers[bend], "invalid generation backend") 140 M.Writer = assert(writers[bend], "invalid generation backend")
68 M.Buffer = M.Writer:clone(Buffer) 141 M.Buffer = M.Writer:clone(Buffer)
@@ -82,7 +155,7 @@ writers["dokuwiki"] = util.Object:clone {
82 subs = dutil.nspace_to_path(path) 155 subs = dutil.nspace_to_path(path)
83 end 156 end
84 dutil.mkdir_p(subs) 157 dutil.mkdir_p(subs)
85 self.file = assert(io.open(dutil.make_page(subs), "w")) 158 self.file = assert(io.open(dutil.make_page(subs, "txt"), "w"))
86 if title then 159 if title then
87 if M.has_feature("title") then 160 if M.has_feature("title") then
88 self:write_raw("<title>", title, "</title>") 161 self:write_raw("<title>", title, "</title>")
@@ -112,79 +185,8 @@ writers["dokuwiki"] = util.Object:clone {
112 return self 185 return self
113 end, 186 end,
114 187
115 write_include = function(self, tp, name, flags, nonl) 188 write_include = function(self, tp, name, flags)
116 local it_to_tp = { 189 return write_include(self, tp, name, flags)
117 [self.INCLUDE_PAGE] = "page",
118 [self.INCLUDE_SECTION] = "section",
119 [self.INCLUDE_NAMESPACE] = "namespace",
120 [self.INCLUDE_TAG] = "tagtopic"
121 }
122 if type(name) == "table" then
123 if name[#name] == true then
124 name[#name] = nil
125 name = ":" .. root_nspace .. ":auto:"
126 .. table.concat(name, ":")
127 elseif name[#name] == false then
128 name[#name] = nil
129 name = ":" .. root_nspace .. ":user:"
130 .. table.concat(name, ":")
131 else
132 name = table.concat(name, ":")
133 end
134 end
135 self:write_raw("{{", it_to_tp[tp], ">", name);
136 if flags then
137 if tp == self.INCLUDE_SECTION and flags.section then
138 self:write_raw("#", flags.section)
139 end
140 flags.section = nil
141 local flstr = {}
142 for k, v in pairs(flags) do
143 local allow = allowed_incflags[k]
144 if allow ~= nil then
145 if type(allow) == "boolean" then
146 flstr[#flstr + 1] = k
147 elseif type(allow) == "number" or type(allow) == "string" then
148 if type(v) ~= type(allow) then
149 error("invalid value type for flag " .. k)
150 end
151 flstr[#flstr + 1] = k .. "=" .. v
152 elseif type(allow) == "table" then
153 if type(allow[1]) == "table" then
154 local valid = false
155 for i, vv in ipairs(allow[1]) do
156 if v == vv then
157 flstr[#flstr + 1] = k .. "=" .. v
158 valid = true
159 break
160 end
161 end
162 if not valid then
163 error("invalid value " .. v .. " for flag " .. k)
164 end
165 elseif type(allow[1]) == "string" and
166 type(allow[2]) == "string" then
167 if v then
168 flstr[#flstr + 1] = allow[1]
169 else
170 flstr[#flstr + 1] = allow[2]
171 end
172 end
173 end
174 else
175 error("invalid include flag: " .. tostring(k))
176 end
177 end
178 flstr = table.concat(flstr, "&")
179 if #flstr > 0 then
180 self:write_raw("&", flstr)
181 end
182 end
183 self:write_raw("}}")
184 if not nonl then
185 self:write_nl()
186 end
187 return self
188 end, 190 end,
189 191
190 write_editable = function(self, ns, name) 192 write_editable = function(self, ns, name)