Código fuente wiki de $services.localization.render("help.syntaxpage.title")
Versión 2.1 por Administrator el 2024/06/05 19:09
Mostrar los últimos autores
author | version | line-number | content |
---|---|---|---|
1 | {{velocity output="false"}} | ||
2 | #set($SUPPORTED_SYNTAXES = {}) | ||
3 | #set($void = $SUPPORTED_SYNTAXES.put(1.0, 'XWiki Syntax 1.0')) | ||
4 | #set($void = $SUPPORTED_SYNTAXES.put(2.0, 'XWiki Syntax 2.0')) | ||
5 | #set($void = $SUPPORTED_SYNTAXES.put(2.1, 'XWiki Syntax 2.1')) | ||
6 | |||
7 | #if ($request.xaction == 'switchContext') | ||
8 | $response.sendRedirect($request.target) | ||
9 | #stop | ||
10 | #end | ||
11 | |||
12 | #set ($crtCategoryId = "$!{request.category}") | ||
13 | #if ($crtCategoryId != '') | ||
14 | #set ($crtCategoryId = $mathtool.toInteger($crtCategoryId)) | ||
15 | #end | ||
16 | #set ($crtSectionId = "$!{request.section}") | ||
17 | #set ($crtSyntaxVer = $mathtool.toDouble($request.syntax)) | ||
18 | #if ($crtSyntaxVer && $SUPPORTED_SYNTAXES.containsKey($crtSyntaxVer)) | ||
19 | #set ($crtSyntaxVer = $mathtool.toDouble($crtSyntaxVer)) | ||
20 | |||
21 | #else | ||
22 | #set ($crtSyntaxVer = 2.1) ## Default to Syntax 2.1 | ||
23 | #end | ||
24 | |||
25 | #set ($extraParamList = []) | ||
26 | #if ($request.language) | ||
27 | #set ($discard = $extraParamList.add("language=$escapetool.url($request.language)")) | ||
28 | #end | ||
29 | #if ($request.xpage) | ||
30 | #set ($discard = $extraParamList.add("xpage=$escapetool.url($request.xpage)")) | ||
31 | #end | ||
32 | #if ($extraParamList.isEmpty()) | ||
33 | #set ($extraParams = '') | ||
34 | #else | ||
35 | #set ($extraParams = '&'+$stringtool.join($extraParamList,'&')) | ||
36 | #end | ||
37 | |||
38 | ## | ||
39 | ## Syntax menu map | ||
40 | ## | ||
41 | #set($syntaxMenu = []) | ||
42 | #set($catCount = -1) | ||
43 | #set($catName = "") | ||
44 | #set($catChildren = []) | ||
45 | #set($results = $services.query.xwql('from doc.object(XWiki.XWikiSyntaxClass) as syntax order by syntax.category, syntax.section').addFilter('currentlanguage').addFilter('unique').execute()) | ||
46 | |||
47 | #if($results.empty) | ||
48 | No syntax sections found! | ||
49 | #else | ||
50 | #foreach ($item in $results) | ||
51 | #set($sectionDoc = $xwiki.getDocument($item)) | ||
52 | #set($obj = $sectionDoc.getObject("XWiki.XWikiSyntaxClass")) | ||
53 | |||
54 | ## detect if we entered a new category | ||
55 | #if($catCount < $obj.getProperty("category").value)) | ||
56 | ## Put previous category into map (if existing), and reset children map | ||
57 | #if($catId) | ||
58 | #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren }) | ||
59 | $syntaxMenu.add($cat) | ||
60 | #set($catChildren = []) | ||
61 | #end | ||
62 | ## extract new catId and catName values, and sectionTitle as we are already traveling the DOM | ||
63 | #foreach($headerBlock in $sectionDoc.getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) | ||
64 | #if($headerBlock.getLevel().getAsInt() == 1) | ||
65 | #set($catId = $headerBlock.getId().substring(1)) | ||
66 | #set($catName = $services.rendering.render($headerBlock, 'plain/1.0')) | ||
67 | #elseif($headerBlock.getLevel().getAsInt() == 2) | ||
68 | #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) | ||
69 | #break | ||
70 | #end | ||
71 | #end | ||
72 | #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) | ||
73 | #if($headerBlock.getLevel().getAsInt() == 1) | ||
74 | #set($catName = $services.rendering.render($headerBlock, 'plain/1.0')) | ||
75 | #elseif($headerBlock.getLevel().getAsInt() == 2) | ||
76 | #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) | ||
77 | #break ## otherwise finds nested example headlines | ||
78 | #end | ||
79 | #end | ||
80 | #set($catCount = $obj.getProperty("category").value) | ||
81 | #else | ||
82 | ## still in same category, only need new section title | ||
83 | #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) | ||
84 | #if($headerBlock.getLevel().getAsInt() == 2) | ||
85 | #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) | ||
86 | #break | ||
87 | #end | ||
88 | #end | ||
89 | #end | ||
90 | |||
91 | ## Add new sections to category children map | ||
92 | #set($child = {'id' : $sectionDoc.getName().substring(11), 'minSyntax' : $obj.getProperty("minSyntaxVersion").value, 'maxSyntax' : $obj.getProperty("maxSyntaxVersion").value, 'name' : $sectionTitle}) | ||
93 | $catChildren.add($child) | ||
94 | #end | ||
95 | #end | ||
96 | #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren }) | ||
97 | $syntaxMenu.add($cat) | ||
98 | |||
99 | |||
100 | ## | ||
101 | ## Filter only the sections that are valid for a Syntax | ||
102 | ## | ||
103 | #set ($categoriesToRemove = []) | ||
104 | #foreach ($category in $syntaxMenu) | ||
105 | #set ($sectionsToRemove = []) | ||
106 | #foreach ($section on $category.children) | ||
107 | #if ($section.minSyntax > $crtSyntaxVer) | ||
108 | #set ($discard = $sectionsToRemove.add($section)) | ||
109 | #if ($section.id == $crtSectionId) | ||
110 | #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.0 to 2.1 syntax) | ||
111 | #end | ||
112 | #end | ||
113 | #end | ||
114 | #set ($discard = $category.children.removeAll($sectionsToRemove)) | ||
115 | #if ($category.children.size() == 0) | ||
116 | #set ($discard = $categoriesToRemove.add($category)) | ||
117 | #end | ||
118 | #end | ||
119 | #set ($discard = $syntaxMenu.removeAll($categoriesToRemove)) | ||
120 | #if ("$!crtCategoryId" != '' && $crtCategoryId >= $syntaxMenu.size()) | ||
121 | #set ($crtCategoryId = '') | ||
122 | #end | ||
123 | |||
124 | #if ($crtSectionId != '') | ||
125 | #set ($crtItemId = $crtSectionId) | ||
126 | #elseif ($crtCategoryId != '') | ||
127 | #set ($crtItemId = $syntaxMenu.get($crtCategoryId).id) | ||
128 | #end | ||
129 | #set ($crtSection = $util.null) | ||
130 | #set ($crtCategory = $util.null) | ||
131 | |||
132 | |||
133 | ## | ||
134 | ## Prepare the Syntax menu map for processing | ||
135 | ## | ||
136 | #foreach ($category in $syntaxMenu) | ||
137 | ## "Standard" URLs and icons for categories | ||
138 | #set ($category.url = "?syntax=$escapetool.url(${crtSyntaxVer})&category=${mathtool.sub($velocityCount, 1)}${extraParams}") | ||
139 | #set ($category.cssClass = "${category.id}Icon") | ||
140 | #if ("$!{crtCategoryId}" != '' && $velocityCount == $mathtool.add($crtCategoryId, 1)) | ||
141 | #set ($crtCategory = $category) | ||
142 | #end | ||
143 | ## | ||
144 | ## Process each syntax section | ||
145 | #foreach ($section in $category.children) | ||
146 | #if ($xwiki.exists("XWiki.XWikiSyntax${section.id}")) | ||
147 | #if ($crtSectionId == $section.id) | ||
148 | #set ($crtSection = $section) | ||
149 | #set ($crtCategory = $category) | ||
150 | #end | ||
151 | #set ($section.url = "?syntax=$escapetool.url(${crtSyntaxVer})§ion=$escapetool.url(${section.id})${extraParams}") | ||
152 | #end | ||
153 | #end | ||
154 | #end | ||
155 | |||
156 | #** | ||
157 | * Displays the sections from a syntax category | ||
158 | * | ||
159 | * Expected format: | ||
160 | * sections = vector of items | ||
161 | * item = map with the following fields: | ||
162 | * 'id' : mandatory | ||
163 | * 'name' : the text displayed for the corresponding menu item; | ||
164 | * optional, defaults to | ||
165 | * $services.localization.render("$!{translationPrefix}${item.id}") | ||
166 | * | ||
167 | * @param $sections the sections list, in the format described above | ||
168 | * @param $translationPrefix the translation prefix added to the id of each | ||
169 | * item, in order to generate the name and description; ignored when | ||
170 | * name or description are specified | ||
171 | * @param $heading the heading syntax | ||
172 | *# | ||
173 | #macro(syntax_displayCategory $sections $translationPrefix $heading) | ||
174 | #foreach ($section in $sections) | ||
175 | #set ($displayVersion = $crtSyntaxVer) | ||
176 | #if ($crtSyntaxVer > $section.maxSyntax) | ||
177 | #set ($displayVersion = $section.maxSyntax) | ||
178 | #end | ||
179 | (% class="sectionheader" %) | ||
180 | $heading $section.name $heading | ||
181 | |||
182 | {{include reference="XWiki.XWikiSyntax${section.id}" section="H${displayVersion}${section.id}"/}} | ||
183 | #end | ||
184 | #end | ||
185 | |||
186 | |||
187 | #** | ||
188 | * Displays the syntax categories | ||
189 | * | ||
190 | * Expected format: | ||
191 | * sections = vector of items | ||
192 | * item = map with the following fields: | ||
193 | * 'id' : mandatory | ||
194 | * 'name' : the text displayed for the corresponding menu item; | ||
195 | * optional, defaults to | ||
196 | * $services.localization.render("$!{translationPrefix}${item.id}") | ||
197 | * | ||
198 | * @param $sections the sections list, in the format described above | ||
199 | * @param $translationPrefix the translation prefix added to the id of each | ||
200 | * item, in order to generate the name and description; ignored when | ||
201 | * name or description are specified | ||
202 | *# | ||
203 | #macro(syntax_displayCategories $syntaxMenu $translationPrefix) | ||
204 | #set ($subHeading = '====') | ||
205 | #foreach ($category in $syntaxMenu) | ||
206 | == $category.name == | ||
207 | |||
208 | #syntax_displayCategory($category.children 'syntax.' '===') | ||
209 | #end | ||
210 | #end | ||
211 | |||
212 | #** | ||
213 | * Displays the drop down allowing to switch the syntax. | ||
214 | *# | ||
215 | #macro (syntaxSwitch) | ||
216 | #set ($crtSelection = "") | ||
217 | #if ("$!{crtCategoryId}" != '') | ||
218 | #set ($crtSelection = "category=$escapetool.url($!{crtCategoryId})") | ||
219 | #elseif ($crtSectionId != '') | ||
220 | #set ($crtSelection = "section=$escapetool.url($!{crtSectionId})") | ||
221 | #end | ||
222 | #if ($crtSelection != "") | ||
223 | #set ($crtSelection = "${crtSelection}${extraParams}") | ||
224 | #else | ||
225 | #set ($crtSelection = "$extraParams") | ||
226 | #end | ||
227 | {{html}} | ||
228 | <form id="change-context" class="xformInline" action=""> | ||
229 | <div> | ||
230 | <input type="hidden" name="xaction" value="switchContext" /> | ||
231 | #if ($request.language) | ||
232 | <input type="hidden" name="language" value="$escapetool.xml($request.language)" /> | ||
233 | #end | ||
234 | #if ($request.xpage) | ||
235 | <input type="hidden" name="xpage" value="$escapetool.xml($request.xpage)" /> | ||
236 | #end | ||
237 | <select id="goto-select" name="target" title="$escapetool.xml($services.localization.render("help.changesyntax"))"> | ||
238 | <optgroup label="$services.localization.render('help.choose_syntax')"> | ||
239 | #set ($query = "syntax=1.0&${crtSelection}") | ||
240 | <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==1.0)selected="selected"#end>$SUPPORTED_SYNTAXES.get(1.0)</option> | ||
241 | #set ($query = "syntax=2.0&${crtSelection}") | ||
242 | <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==2.0)selected="selected"#end>$SUPPORTED_SYNTAXES.get(2.0)</option> | ||
243 | #set ($query = "syntax=2.1&${crtSelection}") | ||
244 | <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==2.1)selected="selected"#end>$SUPPORTED_SYNTAXES.get(2.1)</option> | ||
245 | </optgroup> | ||
246 | </select> | ||
247 | <span class="buttonwrapper"><input type="submit" value="$escapetool.xml($services.localization.render('admin.switchContext'))" class="button" /></span> | ||
248 | </div> | ||
249 | </form> | ||
250 | {{/html}} | ||
251 | #end | ||
252 | {{/velocity}} | ||
253 | |||
254 | {{velocity}} | ||
255 | ##************************************************************************************************** | ||
256 | ## From the Administration Sheet, used to display a common UI for some wiki features | ||
257 | ## here used to display all categories / sections of the syntax guide | ||
258 | ##************************************************************************************************** | ||
259 | $xwiki.get('jsx').use($doc.getFullName())## | ||
260 | $xwiki.get('ssx').use($doc.getFullName())## | ||
261 | #if ($crtSectionId != '') | ||
262 | #set ($sectionName = ${crtSection.name}) | ||
263 | #elseif ($crtCategoryId != '') | ||
264 | #set ($sectionName = ${crtCategory.name}) | ||
265 | #else | ||
266 | #set ($sectionName = $services.localization.render("help.syntaxall")) | ||
267 | #end | ||
268 | #set ($syntaxTitle = $services.localization.render("help.syntaxtitle", ["${crtSyntaxVer}"])) | ||
269 | #syntaxSwitch() | ||
270 | ((( | ||
271 | #set ($query = "syntax=$escapetool.url(${crtSyntaxVer})${extraParams}") | ||
272 | #if ($crtCategory){{html}}<a href="${doc.getURL('view', ${query})}">$syntaxTitle</a>{{/html}}#{else}(% class="current" %)$syntaxTitle#{end}#if ($crtCategory) (% class="separator" %)» #if ($crtSection){{html}}<a href="${crtCategory.url}">${crtCategory.name}</a>{{/html}}#{else}(% class="current" %)${crtCategory.name}#{end}#if ($crtSection) (% class="separator" %)» (% class="current" %)${crtSection.name}#end#end | ||
273 | ))) | ||
274 | == $syntaxTitle: $sectionName == | ||
275 | |||
276 | #verticalNavigation($syntaxMenu {'translationPrefix' : 'syntax.', 'crtItemId' : "$!crtItemId", 'cssClass' : 'syntax-menu'}) | ||
277 | ##----------------------------------------- | ||
278 | ## syntax-page display | ||
279 | ##----------------------------------------- | ||
280 | (% id="syntax-page-content" %)((( | ||
281 | #if(!$crtSection && !$crtCategory) | ||
282 | #syntax_displayCategories($syntaxMenu 'syntax.') | ||
283 | #elseif (!$crtSection) | ||
284 | #set ($subHeading = '===') | ||
285 | #syntax_displayCategory($crtCategory.children 'syntax.' '==') | ||
286 | #else | ||
287 | #set ($displayVersion = $crtSyntaxVer) | ||
288 | #if ($crtSyntaxVer > $crtSection.maxSyntax) | ||
289 | #set ($displayVersion = $crtSection.maxSyntax) | ||
290 | #end | ||
291 | #set ($subHeading = '==') | ||
292 | {{include reference="XWiki.XWikiSyntax${crtSection.id}" section="H${displayVersion}${crtSection.id}"/}} | ||
293 | #end | ||
294 | ))) ## syntax-page-content | ||
295 | {{/velocity}} |