File: makedoc.lua

package info (click to toggle)
lua-orbit 2.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 1,956 kB
  • ctags: 638
  • sloc: sql: 78; sh: 32; makefile: 31; xml: 20
file content (114 lines) | stat: -rw-r--r-- 2,987 bytes parent folder | download | duplicates (4)
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
113
114
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="http://www.keplerproject.org/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">
        <a href="http://www.keplerproject.org">
		<img alt="$name" src="$logo"/>
	    </a>
    </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