UVLDoc: Rendering optimizations and CSS style
[project/luci.git] / libs / uvldoc / luasrc / uvldoc / proto / xhtml / section.xml
1 <%- title = scheme .. "." .. type -%> 
2 <%+header.xml%>
3 <%
4 local table = require "table"
5
6 types = {
7         list = "List",
8         variable = "Variable",
9         lazylist = "Mixed",
10         enum = "Enumerator",
11         reference = "Reference"
12 }
13
14 datatypes = {
15         boolean = "Boolean",
16         string = "String",
17         uint = "Unsigned Integer",
18         integer = "Integer",
19         float = "Real Number",
20         ipaddr = "IP-Address",
21         ip4addr = "IPv4-Address",
22         ip6addr = "IPv6-Address",
23         ip4prefix = "IPv4-Prefix",
24         ip6prefix = "IPv6-Prefix",
25         hostname = "Hostname",
26         host = "Host (Hostname or IP-Address)",
27         directory = "Filesystem path (to directory)",
28         file = "Filesystem path (to file)",
29         macaddr = "MAC-Address",
30         port = "Port",
31         portrange = "Single Port or Portrange (First-Last)"
32 }
33
34 function _parse_ref( r )
35         local k, v, h = r:match("([^.]+)%.([^.]+)%.([^.]+)")
36         if not k then
37                 k, v = r:match("([^.]+)%.([^.]+)")
38         end
39         if k then
40                 if h then
41                         return self:_variable_target(k, v, h), true
42                 else
43                         return self:_section_filename(k, v)
44                 end
45         end
46 end 
47
48 function _parse_dep( r, c, s, o )
49         local ref  = { }
50         local vars = {
51                 config  = c,
52                 section = s,
53                 option  = o
54         }
55
56         for v in r:gmatch("[^.]+") do
57                 ref[#ref+1] = (v:gsub( "%$(.+)", vars ))
58         end
59         
60         if #ref < 2 then
61                 table.insert(ref, 1, s or '$section')
62         end
63         if #ref < 3 then
64                 table.insert(ref, 1, c or '$config')
65         end
66
67         return self:_variable_target(unpack(ref))
68 end
69
70 %>
71 <a name="top" />
72 <h1 class="section-title"><%=scheme-%>
73 <%-if package.title then%><dfn> - <%=package.title%></dfn><%end%></h1>
74 <h2 class="section-subtitle"><%=type-%>
75 <%-if section.title then%><dfn> - <%=section.title%></dfn><%end%></h2>
76 <div class="section-description"><%=section.description%></div>
77
78 <h3 class="section-attributes">Attributes:</h3>
79 <ul class="section-attributes-index">
80 <%- 
81 if section.required then %>
82         <li class="section-attributes-required">required: <dfn>A section of this type is required.</dfn></li>
83 <% end
84 if section.unique then %>
85         <li class="section-attributes-unique">unique: <dfn>There can be only one section of this type.</dfn></li>
86 <%- else -%>
87         <li class="section-attributes-multiple">multiple: <dfn>There can be more than one section of this type.</dfn></li>
88 <% end
89 if section.dynamic then %> 
90         <li class="section-attributes-dynamic">dynamic: <dfn>Sections of this type may contain user-defined options.</dfn></li>
91 <% end 
92 if section.named then %> 
93         <li class="section-attributes-named">named: <dfn>Sections of this type require a name.</dfn></li>
94 <% end -%>
95 </ul>
96
97 <% if section.depends then %>
98         <h3 class="section-depends">Requirements (one of):</h3>
99         <ul class="section-depends-index">
100                 <% for i, d in ipairs(section.depends) do 
101                         local nf = false%>
102                 <li>
103                 <% for k2, v in luci.util.kspairs(d) do
104                         local t = _parse_dep(k2, scheme, type)
105                 %>
106                         <% if nf then %>and<% end %>
107                         <%if t then%><a href="<%=t%>"><%end%><%=k2%><%if t then%></a><%end%><%if v~=true then%>=<%=v%><%end%>
108                 <% nf = true
109                         end %>
110                 </li>
111                 <% end %>
112         </ul>
113 <% end %>
114
115 <h3 class="section-variables">Overview:</h3>
116 <table class="section-variables-index">
117 <% for k, v in luci.util.kspairs(package.variables[type]) do 
118 if v.required then%>
119 <tr class="section-variable-required">
120         <th><a href="#variable.<%=k%>"><%=k%></a></th>
121         <td><%=v.title%></td>
122 </tr>
123 <% end end
124 for k, v in luci.util.kspairs(package.variables[type]) do 
125 if not v.required then%>
126 <tr class="section-variable-mixed">
127         <th><a href="#variable.<%=k%>"><%=k%></a></th>
128         <td><%=v.title%></td>
129 </tr>
130 <% end end %>
131 </table>
132
133 <h3 class="section-variables">Options:</h3>
134 <%-
135 for i=0, 1 do
136 for k, v in luci.util.kspairs(package.variables[type]) do
137 if (i==0) == v.required then
138 %>
139 <hr />
140 <div class="variable-documentation">
141         <a name="variable.<%=k%>" />
142         <h4 class="variable-title"><%=k-%>
143         <%-if v.title then%><dfn> - <%=v.title%></dfn><%end%></h4>
144         <div class="variable-description"><%=v.description%></div>
145         <div class="variable-declaration">
146         <h5 class="variable-attributes">Attributes:</h5>
147         <ul class="varaible-attributes-index">
148         <% if v.required then %>
149                 <li class="variable-attribute-required"><strong>required</strong></li>
150         <% end %>
151                 <li class="variable-attribute-type"><strong>Type:</strong> <%=types[v.type] or v.type%></li>
152                 <li class="variable-attribute-datatype"><strong>Datatype:</strong> <%=datatypes[v.datatype] or v.datatype%></li>
153         <% if v.multival then %>
154                 <li class="variable-attribute-multiple"><strong>multiple values:</strong> space-separated</li>
155         <% end %>
156         </ul>
157         <% if v.depends then %>
158                 <h5 class="variable-depends">Dependencies (one of):</h5>
159                 <ul class="variable-depends-index">
160                         <% for i, d in ipairs(v.depends) do 
161                                 local nf = false %>
162                         <li>
163                         <% for k2, v in luci.util.kspairs(d) do
164                                 local t = _parse_dep(k2, scheme, type, k)
165                         %>
166                                 <% if nf then %>and<% end %>
167                                 <%if t then%><a href="<%=t%>"><%end%><%=k2%><%if t then%></a><%end%><%if v~=true then%>=<%=v%><%end%>
168                         <% nf = true
169                         end %>
170                         </li>
171                         <% end %>
172                 </ul>
173         <% end %>
174         <% if v.type == "enum" then %>
175                 <h5 class="variable-values">Possible Values:</h5>
176                 <ul class="variable-values-index">
177                         <% for k, d in pairs(v.values) do %> 
178                         <li><strong><%=k%></strong><%if d then%> (<%=d%>)<%end%></li>
179                         <% end %>
180                 </ul>
181         <% elseif v.type == "reference" then %>
182                 <h5 class="variable-reference">Value references:</h5>
183                 <ul class="variable-reference-index">
184                         <% for k, d in ipairs(v.valueof) do %> 
185                         <li>
186                         <% local t, x = _parse_ref(d)
187                         if t then %><%=x and "Value of" or "Section of type"%> <a href="<%=t%>"><% end %>
188                         <%=d%>
189                         <% if t then%></a><% end %>
190                         </li>
191                         <% end %>
192                 </ul>
193         <% end %>
194         </div>
195         <a href="#top">&#8657;</a>
196 </div>
197 <% end end end -%>
198 <%+footer.xml%>