/doc/us/makedoc.lua

http://github.com/keplerproject/orbit · Lua · 112 lines · 102 code · 10 blank · 0 comment · 1 complexity · ba95b7309b40df7235fa9103f11cf490 MD5 · raw file

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