PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/doc/us/makedoc.lua

http://github.com/keplerproject/orbit
Lua | 112 lines | 90 code | 22 blank | 0 comment | 6 complexity | ba95b7309b40df7235fa9103f11cf490 MD5 | raw file
  1local cosmo = require "cosmo"
  2local markdown = require "markdown"
  3
  4local pages = {
  5  { name = "Home", file = "index", sections = {} },
  6  { name = "Pages", file = "pages", sections = {} },
  7  { name = "Reference", file = "reference", sections = {} },
  8  { name = "Tutorial", file = "example", sections = {} },
  9  { name = "License", file = "license", sections = {} }
 10}
 11
 12local project = {
 13  name = "Orbit",
 14  blurb = "MVC for Lua Web Development",
 15  logo = "orbit.png",
 16}
 17
 18local template = [==[
 19
 20<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 21   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 22<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 23<head>
 24	<title>$name</title>
 25    <link rel="stylesheet" href="doc.css" type="text/css"/>
 26	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
 27</head>
 28
 29<body>
 30
 31<div id="container">
 32
 33<div id="product">
 34
 35	<div id="product_logo">
 36		<img alt="$name" src="$logo"/>
 37    </div>
 38	<div id="product_name"><big><strong>$name</strong></big></div>
 39	<div id="product_description">$blurb</div>
 40</div> <!-- id="product" -->
 41
 42<div id="main">
 43	
 44<div id="navigation">
 45<h1>$name</h1>
 46	<ul>
 47$pages[[
 48		<li>$namelink
 49			<ul> 
 50                            $sections[=[<li><a href="$anchor">$name</a></li>]=]
 51			</ul>
 52		</li>
 53]]
 54	</ul>
 55</div> <!-- id="navigation" -->
 56
 57<div id="content">
 58
 59$content
 60
 61</div> <!-- id="content" -->
 62
 63</div> <!-- id="main" -->
 64
 65<div id="about">
 66	<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
 67</div> <!-- id="about" -->
 68
 69</div> <!-- id="container" -->
 70
 71</body>
 72</html>
 73
 74]==]
 75
 76local function readfile(filename)
 77  local file = io.open(filename)
 78  local contents = file:read("*a")
 79  file:close()
 80  return contents
 81end
 82
 83local function writefile(filename, contents)
 84  local file = io.open(filename, "w+")
 85  file:write(contents)
 86  file:close()
 87end
 88
 89local function gen_page(project, pages, p)
 90  project.pages = function ()
 91    for _, page in ipairs(pages) do
 92      local namelink
 93      if page.file == p.file then
 94        namelink = cosmo.fill([[<strong>$name</strong>]], { name = page.name})
 95      else
 96        namelink = cosmo.fill([[<a href="$file.html">$name</a>]], { name = page.name, file = page.file})
 97      end
 98      cosmo.yield{ namelink = namelink, sections = function ()
 99                                                     for _, s in ipairs(page.sections) do
100                                                       cosmo.yield{ name = s.name, anchor = 
101                                                         page.file .. ".html#" .. s.anchor }
102                                                     end
103                                                   end }
104    end  
105  end
106  return (cosmo.fill(template, project))
107end
108
109for _, p in ipairs(pages) do
110  project.content = markdown(readfile(p.file .. ".md"))
111  writefile(p.file .. ".html", gen_page(project, pages, p))
112end