layout.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 title(node)
  28. return i18n(node.pkg).translate(node.title)
  29. end
  30. local function subtree(prefix, node, name, ...)
  31. if not node then return end
  32. local children = disp.node_children(node)
  33. if #children == 0 then return end
  34. %>
  35. <div class="tabmenu<%=#prefix%>">
  36. <ul class="tabmenu l<%=#prefix%>">
  37. <%
  38. for i, v in ipairs(children) do
  39. local child = node.nodes[v]
  40. local active = (v == name)
  41. %>
  42. <li class="tabmenu-item-<%=v%><% if active then %> active<% end %>">
  43. <a href="<%|url(append(prefix, v))%>"><%|title(child)%></a>
  44. </li>
  45. <%
  46. end
  47. %>
  48. </ul>
  49. <br style="clear:both" />
  50. <%
  51. subtree(append(prefix, name), node.nodes[name], ...)
  52. %>
  53. </div>
  54. <%
  55. end
  56. local function menutree(path, ...)
  57. subtree({path}, root.nodes[category], ...)
  58. end
  59. -%>
  60. <!DOCTYPE html>
  61. <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
  62. <head>
  63. <meta charset="UTF-8" />
  64. <link rel="stylesheet" type="text/css" media="screen" href="<%|media%>/cascade.css" />
  65. <title><%| hostname .. ((rnode and rnode.title) and ' - ' .. title(rnode) or '') %></title>
  66. </head>
  67. <body>
  68. <div id="menubar">
  69. <div class="hostinfo">
  70. <a href="<%|url({})%>">
  71. <%|hostname%>
  72. <% if release then %>
  73. / <%|release%>
  74. <% end %>
  75. </a>
  76. </div>
  77. <% if #categories > 1 and not hidenav then %>
  78. <ul id="topmenu">
  79. <% for i, r in ipairs(categories) do %>
  80. <li><a class="topcat<% if request[1] == r then %> active<%end%>" href="<%|url({r})%>"><%|title(root.nodes[r])%></a></li>
  81. <% end %>
  82. </ul>
  83. <% end %>
  84. </div>
  85. <div id="maincontainer">
  86. <%
  87. if not hidenav then
  88. menutree(unpack(request))
  89. end
  90. %>
  91. <div id="maincontent">
  92. <noscript>
  93. <div class="errorbox">
  94. <strong><%:JavaScript required!%></strong><br />
  95. <%:You must enable JavaScript in your browser or the web interface will not work properly.%>
  96. </div>
  97. </noscript>
  98. <%
  99. ok, err = pcall(renderer.render, content, env, pkg)
  100. if not ok then
  101. renderer.render('error500', {message = err}, 'gluon-web')
  102. end
  103. %>
  104. </div>
  105. </div>
  106. </body>
  107. </html>