uvldoc: Added preliminary section support, optimized menu generating
authorSteven Barth <steven@midlink.org>
Tue, 9 Sep 2008 21:55:54 +0000 (21:55 +0000)
committerSteven Barth <steven@midlink.org>
Tue, 9 Sep 2008 21:55:54 +0000 (21:55 +0000)
libs/uvldoc/luasrc/uvldoc/proto/xhtml/footer.xml
libs/uvldoc/luasrc/uvldoc/proto/xhtml/menu.xml
libs/uvldoc/luasrc/uvldoc/proto/xhtml/section.xml [new file with mode: 0644]
libs/uvldoc/luasrc/uvldoc/renderer.lua

index 5f8c0b9b4babd02e5f30394e63754dfe90766c7f..d353ced18e0e1ea7edabe3bee636855f6a15ea4f 100644 (file)
@@ -2,7 +2,7 @@
 </div>
 
 <div id="copy">
-generated on <%=os.date("%c")%> with <a href="http://luci.freifunk-halle.net"><abbr title="Lua Configuration Interface">LuCI</abbr> UVLDoc</a> - written by Steven Barth and Jo-Philipp Wich
+generated on <%=require "os".date("%c")%> with <a href="http://luci.freifunk-halle.net"><abbr title="Lua Configuration Interface">LuCI</abbr> UVLDoc</a> - written by Steven Barth and Jo-Philipp Wich
 </div>
 
 </body>
index 402e6388ed88c116e409c22099b5d18e12236041..7a03002694ef80b32c6a31b332810dbbbfe2c2ec 100644 (file)
@@ -1,7 +1,20 @@
 <h2>LuCI UVLDoc</h2>
 <ul>
-<li><a href="<%=self:_index_filename()%>">Index</a></li>
+<li<%-if not scheme then%> class="menu-active"<%-end-%>>
+       <a href="<%=self:_index_filename()%>">Index</a>
+</li>
 <% for k, v in luci.util.kspairs(self.schemes) do %>
-<li><a href="<%=self:_scheme_filename(k)%>"><%=k%></a></li>
+<li<%-if scheme == k then%> class="menu-active"<%-end-%>>
+       <a href="<%=self:_scheme_filename(k)%>"><%=k%></a>
+       <%-if scheme == k then-%>
+       <ul>
+       <%-for k2, v2 in luci.util.kspairs(v.sections) do-%>
+               <li>
+                       <a href="<%=self:_section_filename(k, k2)%>"><%=k2%></a>
+               </li>
+       <%-end-%>
+       </ul>
+       <%-end-%>
+</li>
 <% end %>
 </ul>
\ No newline at end of file
diff --git a/libs/uvldoc/luasrc/uvldoc/proto/xhtml/section.xml b/libs/uvldoc/luasrc/uvldoc/proto/xhtml/section.xml
new file mode 100644 (file)
index 0000000..985809e
--- /dev/null
@@ -0,0 +1,2 @@
+<%+header.xml%>
+<%+footer.xml%>
\ No newline at end of file
index 5fce5ec51cbe9dad2f825b42022341905cbebce2..f881032c20bf44c22f44122eff3879e62adafe9e 100644 (file)
@@ -20,7 +20,8 @@ local util = require "luci.util"
 local ltn12 = require "luci.ltn12"
 local template = require "luci.template"
 
-local ipairs = ipairs
+local ipairs, getfenv, pairs, require = ipairs, getfenv, pairs, require
+local luci = luci
 
 module "luci.uvldoc.renderer"
 
@@ -52,11 +53,19 @@ function Generator.make(self)
 
        template.compiler_mode = "memory"
        template.viewdir = self.sourcedir
+       template.context.viewns = {
+               include = function(name) template.Template(name):render(getfenv(2)) end,
+               luci = luci,
+               require = require
+       }
 
        self:_make_index()
 
-       for scheme, file in util.kspairs(self.schemes) do
+       for scheme, package in pairs(self.schemes) do
                self:_make_package(scheme)
+               for type, section in pairs(package.sections) do
+                       self:_make_section(scheme, type)
+               end
        end
 end
 
@@ -78,6 +87,18 @@ function Generator._make_package(self, scheme)
        sink()
 end
 
+function Generator._make_section(self, scheme, section)
+       local t = template.Template("section.xml")
+       local sink = ltn12.sink.file(
+               io.open(self.output .. "/" .. self:_section_filename(scheme, section), "w")
+       )
+       local pkg = self.schemes[scheme]
+       t:render({self = self, package = pkg,
+               scheme = scheme, type=section, section=pkg.sections[section],
+               write = sink})
+       sink()
+end
+
 function Generator._index_filename(self)
        return "index%s" % self.extension
 end
@@ -85,3 +106,7 @@ end
 function Generator._scheme_filename(self, scheme)
        return "scheme.%s%s" % {scheme, self.extension}
 end
+
+function Generator._section_filename(self, scheme, section)
+       return "section.%s.%s%s" % {scheme, section, self.extension}
+end