layout.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <%#
  2. Copyright 2008 Steven Barth <steven@midlink.org>
  3. Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. -%>
  9. <%
  10. local uci = require("simple-uci").cursor()
  11. local disp = require "gluon.web.dispatcher"
  12. local fs = require "nixio.fs"
  13. local pretty_hostname = require "pretty_hostname"
  14. local hostname = pretty_hostname.get(uci)
  15. local release = fs.readfile("/lib/gluon/release")
  16. local root = node()
  17. local rnode = node(unpack(request))
  18. local category = request[1]
  19. local cattree = category and node(category)
  20. local categories = disp.node_children(root)
  21. http:prepare_content("application/xhtml+xml")
  22. local function append(xs, x)
  23. local r = {unpack(xs)}
  24. r[#r+1] = x
  25. return r
  26. end
  27. local function subtree(prefix, node, name, ...)
  28. if not node then return end
  29. local children = disp.node_children(node)
  30. if #children == 0 then return end
  31. %>
  32. <div class="tabmenu<%=#prefix%>">
  33. <ul class="tabmenu l<%=#prefix%>">
  34. <%
  35. for i, v in ipairs(children) do
  36. local child = node.nodes[v]
  37. local active = (v == name)
  38. %>
  39. <li class="tabmenu-item-<%=v%><% if active then %> active<% end %>">
  40. <a href="<%=url(append(prefix, v))%>"><%=pcdata(translate(child.title))%></a>
  41. </li>
  42. <%
  43. end
  44. %>
  45. </ul>
  46. <br style="clear:both" />
  47. <%
  48. subtree(append(prefix, name), node.nodes[name], ...)
  49. %>
  50. </div>
  51. <%
  52. end
  53. local function menutree(path, ...)
  54. subtree({path}, root.nodes[category], ...)
  55. end
  56. -%>
  57. <!DOCTYPE html>
  58. <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
  59. <head>
  60. <meta charset="UTF-8" />
  61. <link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css" />
  62. <title><%=pcdata( hostname .. ( (rnode and rnode.title) and ' - ' .. translate(rnode.title) or '')) %></title>
  63. </head>
  64. <body>
  65. <div id="menubar">
  66. <div class="hostinfo">
  67. <a href="<%=url({})%>">
  68. <%=pcdata(hostname)%>
  69. <% if release then %>
  70. / <%=pcdata(release)%>
  71. <% end %>
  72. </a>
  73. </div>
  74. <% if #categories > 1 and not hidenav then %>
  75. <ul id="topmenu">
  76. <% for i, r in ipairs(categories) do %>
  77. <li><a class="topcat<% if request[1] == r then %> active<%end%>" href="<%=url({r})%>"><%=pcdata(translate(root.nodes[r].title))%></a></li>
  78. <% end %>
  79. </ul>
  80. <% end %>
  81. </div>
  82. <div id="maincontainer">
  83. <%
  84. if not hidenav then
  85. menutree(unpack(request))
  86. end
  87. %>
  88. <div id="maincontent">
  89. <noscript>
  90. <div class="errorbox">
  91. <strong><%:JavaScript required!%></strong><br />
  92. <%:You must enable JavaScript in your browser or the web interface will not work properly.%>
  93. </div>
  94. </noscript>
  95. <%
  96. ok, err = pcall(include, content)
  97. if not ok then
  98. renderer.render('error500', {message = err})
  99. end
  100. %>
  101. </div>
  102. </div>
  103. </body>
  104. </html>