This repository was archived by the owner on Jul 11, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathmakedoc.lua
More file actions
112 lines (90 loc) · 2.83 KB
/
Copy pathmakedoc.lua
File metadata and controls
112 lines (90 loc) · 2.83 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
local cosmo = require "cosmo"
local markdown = require "markdown"
local pages = {
{ name = "Home", file = "index", sections = {} },
{ name = "Pages", file = "pages", sections = {} },
{ name = "Reference", file = "reference", sections = {} },
{ name = "Tutorial", file = "example", sections = {} },
{ name = "License", file = "license", sections = {} }
}
local project = {
name = "Orbit",
blurb = "MVC for Lua Web Development",
logo = "orbit.png",
}
local template = [==[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>$name</title>
<link rel="stylesheet" href="doc.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo">
<img alt="$name" src="$logo"/>
</div>
<div id="product_name"><big><strong>$name</strong></big></div>
<div id="product_description">$blurb</div>
</div> <!-- id="product" -->
<div id="main">
<div id="navigation">
<h1>$name</h1>
<ul>
$pages[[
<li>$namelink
<ul>
$sections[=[<li><a href="$anchor">$name</a></li>]=]
</ul>
</li>
]]
</ul>
</div> <!-- id="navigation" -->
<div id="content">
$content
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
]==]
local function readfile(filename)
local file = io.open(filename)
local contents = file:read("*a")
file:close()
return contents
end
local function writefile(filename, contents)
local file = io.open(filename, "w+")
file:write(contents)
file:close()
end
local function gen_page(project, pages, p)
project.pages = function ()
for _, page in ipairs(pages) do
local namelink
if page.file == p.file then
namelink = cosmo.fill([[<strong>$name</strong>]], { name = page.name})
else
namelink = cosmo.fill([[<a href="$file.html">$name</a>]], { name = page.name, file = page.file})
end
cosmo.yield{ namelink = namelink, sections = function ()
for _, s in ipairs(page.sections) do
cosmo.yield{ name = s.name, anchor =
page.file .. ".html#" .. s.anchor }
end
end }
end
end
return (cosmo.fill(template, project))
end
for _, p in ipairs(pages) do
project.content = markdown(readfile(p.file .. ".md"))
writefile(p.file .. ".html", gen_page(project, pages, p))
end