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