Completed first part of UVLDoc
[project/luci.git] / libs / uvldoc / luasrc / uvldoc / proto / xhtml / section.xml
1 <%+header.xml%>
2 <%
3 local table = require "table"
4
5 function _parse_ref( r )
6         local k, v = r:match("([^.]+)%.([^.]+)")
7         return k and self:_section_filename(k, v)
8 end 
9
10 function _parse_dep( r, c, s, o )
11         local ref  = { }
12         local vars = {
13                 config  = c,
14                 section = s,
15                 option  = o
16         }
17
18         for v in r:gmatch("[^.]+") do
19                 ref[#ref+1] = (v:gsub( "%$(.+)", vars ))
20         end
21         
22         if #ref < 2 then
23                 table.insert(ref, 1, s or '$section')
24         end
25         if #ref < 3 then
26                 table.insert(ref, 1, c or '$config')
27         end
28
29         return self:_variable_target(unpack(ref))
30 end
31
32 %>
33 <h1 class="section-title"><%=scheme-%>
34 <%-if package.title then%>: <%=package.title%><%end%></h1>
35 <h2 class="section-subtitle"><%=type-%>
36 <%-if section.title then%>: <%=section.title%><%end%></h2>
37 <div class="section-description"><%=section.description%></div>
38
39 <h3 class="section-attributes">Attributes:</h3>
40 <ul class="section-attributes-index">
41 <%- 
42 if section.required then %>
43         <li class="section-attributes-required">required: <dfn>A section of this type is required.</dfn></li>
44 <% end
45 if section.unique then %>
46         <li class="section-attributes-unique">unique: <dfn>There can be only one section of this type.</dfn></li>
47 <%- else -%>
48         <li class="section-attributes-multiple">multiple: <dfn>There can be more than one section of this type.</dfn></li>
49 <% end
50 if section.dynamic then %> 
51         <li class="section-attributes-dynamic">dynamic: <dfn>Sections of this type may contain user-defined options.</dfn></li>
52 <% end 
53 if section.named then %> 
54         <li class="section-attributes-named">named: <dfn>Sections of this type require a name.</dfn></li>
55 <% end -%>
56 </ul>
57
58 <% if section.depends then %>
59         <h3 class="section-depends">Requirements (one of):</h3>
60         <ul class="section-depends-index">
61                 <% for i, d in ipairs(section.depends) do 
62                         local nf = false%>
63                 <li>
64                 <% for k2, v in luci.util.kspairs(d) do
65                         local t = _parse_dep(k2, scheme, type)
66                 %>
67                         <% if nf then %>and<% end %>
68                         <%if t then%><a href="<%=t%>"><%end%><%=k2%><%if t then%></a><%end%><%if v~="" then%>=<%=v%><%end%>
69                 <% nf = true
70                         end %>
71                 </li>
72                 <% end %>
73         </ul>
74 <% end %>
75
76 <h3 class="section-variables">Options:</h3>
77 <table class="section-variables-index">
78 <% for k, v in luci.util.kspairs(package.variables[type]) do 
79 if v.required then%>
80 <tr class="section-variable-required">
81         <td><a href="#variable.<%=k%>"><%=k%></a></td>
82         <td><%=v.title%></td>
83 </tr>
84 <% end end
85 for k, v in luci.util.kspairs(package.variables[type]) do 
86 if not v.required then%>
87 <tr class="section-variable-mixed">
88         <td><a href="#variable.<%=k%>"><%=k%></a></td>
89         <td><%=v.title%></td>
90 </tr>
91 <% end end %>
92 </table>
93
94 <h3 class="section-variables">Options:</h3>
95 <%-
96 for i=0, 1 do
97 for k, v in luci.util.kspairs(package.variables[type]) do
98 if (i==0) == v.required then
99 %>
100 <hr />
101 <div class="variable-documentation">
102         <a name="variable.<%=k%>" />
103         <h4 class="variable-title"><%=k-%>
104         <%-if v.title then%>: <%=v.title%><%end%></h4>
105         <div class="variable-description"><%=v.description%></div>
106         <h5 class="variable-attributes">Attributes:</h5>
107         <ul class="varaible-attributes-index">
108         <% if v.required then %>
109                 <li class="variable-attribute-required"><strong>required</strong></li>
110         <% end %>
111                 <li class="variable-attribute-type"><strong>Type:</strong> <%=v.type%></li>
112                 <li class="variable-attribute-datatype"><strong>Datatype:</strong> <%=v.datatype%></li>
113         </ul>
114         <% if v.depends then %>
115                 <h5 class="variable-depends">Dependencies (one of):</h5>
116                 <ul class="variable-depends-index">
117                         <% for i, d in ipairs(v.depends) do 
118                                 local nf = false %>
119                         <li>
120                         <% for k2, v in luci.util.kspairs(d) do
121                                 local t = _parse_dep(k2, scheme, type, k)
122                         %>
123                                 <% if nf then %>and<% end %>
124                                 <%if t then%><a href="<%=t%>"><%end%><%=k2%><%if t then%></a><%end%><%if v~="" then%>=<%=v%><%end%>
125                         <% nf = true
126                         end %>
127                         </li>
128                         <% end %>
129                 </ul>
130         <% end %>
131         <% if v.type == "enum" then %>
132                 <h5 class="variable-values">Possible Values:</h5>
133                 <ul class="variable-values-index">
134                         <% for k, d in pairs(v.values) do %> 
135                         <li><strong><%=k%></strong><%if d then%> (<%=d%>)<%end%></li>
136                         <% end %>
137                 </ul>
138         <% elseif v.type == "reference" then %>
139                 <h5 class="variable-reference">Value references:</h5>
140                 <ul class="variable-reference-index">
141                         <% for k, d in ipairs(v.valueof) do %> 
142                         <li>
143                         <% local t = _parse_ref(d)
144                         if t then %>Section of type <a href="<%=t%>"><% end %>
145                         <%=d%>
146                         <% if t then%></a><% end %>
147                         </li>
148                         <% end %>
149                 </ul>
150         <% end %>
151 </div>
152 <% end end end -%>
153 <%+footer.xml%>