277 | 277 |
quit("template not found at '"..args.template.."' Use -l to specify directory containing ldoc.ltp")
|
278 | 278 |
end
|
279 | 279 |
|
|
280 |
-- Runs a template on a module to generate HTML page.
|
|
281 |
local function templatize(template_str, ldoc, module)
|
|
282 |
local out, err = template.substitute(template_str, {
|
|
283 |
ldoc = ldoc,
|
|
284 |
module = module,
|
|
285 |
_escape = ldoc.template_escape
|
|
286 |
})
|
|
287 |
if not out then
|
|
288 |
quit(("template failed for %s: %s"):format(
|
|
289 |
module and module.name or ldoc.output or "index",
|
|
290 |
err))
|
|
291 |
end
|
|
292 |
if ldoc.postprocess_html then
|
|
293 |
out = ldoc.postprocess_html(out, module)
|
|
294 |
end
|
|
295 |
return cleanup_whitespaces(out)
|
|
296 |
end
|
|
297 |
|
280 | 298 |
local css = ldoc.css
|
281 | 299 |
ldoc.output = args.output
|
282 | 300 |
ldoc.ipairs = ipairs
|
|
298 | 316 |
save_and_set_ldoc(ldoc.module.tags.set)
|
299 | 317 |
end
|
300 | 318 |
set_charset(ldoc)
|
301 | |
local out,err = template.substitute(module_template,{
|
302 | |
ldoc = ldoc,
|
303 | |
module = ldoc.module,
|
304 | |
_escape = ldoc.template_escape
|
305 | |
})
|
|
319 |
local out = templatize(module_template, ldoc, ldoc.module)
|
306 | 320 |
ldoc.root = false
|
307 | |
if not out then quit("template failed: "..err) end
|
308 | 321 |
restore_ldoc()
|
309 | 322 |
|
310 | 323 |
check_directory(args.dir) -- make sure output directory is ok
|
|
351 | 364 |
if ldoc.body and m.postprocess then
|
352 | 365 |
ldoc.body = m.postprocess(ldoc.body)
|
353 | 366 |
end
|
354 | |
out,err = template.substitute(module_template,{
|
355 | |
module=m,
|
356 | |
ldoc = ldoc,
|
357 | |
_escape = ldoc.template_escape
|
358 | |
})
|
359 | |
if not out then
|
360 | |
quit('template failed for '..m.name..': '..err)
|
361 | |
else
|
362 | |
out = cleanup_whitespaces(out)
|
363 | |
writefile(args.dir..lkind..'/'..m.name..args.ext,out)
|
364 | |
end
|
|
367 |
local out = templatize(module_template, ldoc, m)
|
|
368 |
writefile(args.dir..lkind..'/'..m.name..args.ext,out)
|
365 | 369 |
restore_ldoc()
|
366 | 370 |
end
|
367 | 371 |
end
|