Tims_blog_2025-11-29_14:23:12.40_transforms >> Tims_blog_2026-04-25_16:01:26.25_transforms >> garage_door_opener_transforms >> _bug9HuMcJvz_transforms >> Business_Ideas 

TB Wiki

Login

Regression Test

Expected HTML for page "DocMacros"


expected html
nothing
t1 t
2<table align="right"><tr><td><div class="toc">
3Contents:
4<ul>
5  <li><a href="#Introduction">Introduction</a></li>
6  <li><a href="#Name_and_Location">Name&nbsp;and&nbsp;Location</a></li>
7  <li><a href="#Declaration_in_a_TBWiki_Page">Declaration&nbsp;in&nbsp;a&nbsp;TBWiki&nbsp;Page</a></li>
8  <li><a href="#Interface_from_TBWiki_to_the_macro">Interface&nbsp;from&nbsp;TBWiki&nbsp;to&nbsp;the&nbsp;macro</a></li>
9  <ul>
10    <li><a href="#main()_function">main()&nbsp;function</a></li>
11    <ul>
12      <li><a href="#Example_main()">Example&nbsp;main()</a></li>
13      <li><a href="#Example_declaration_(of_Error_macro)">Example&nbsp;declaration&nbsp;(of&nbsp;Error&nbsp;macro)</a></li>
14    </ul>
15    <li><a href="#help()_and_help_oneline()_actions">help()&nbsp;and&nbsp;help_oneline()&nbsp;actions</a></li>
16    <li><a href="#macro_side_effects_or_operations">macro&nbsp;side&nbsp;effects&nbsp;or&nbsp;operations</a></li>
17  </ul>
18  <li><a href="#Interface_from_the_macro_to_TBWiki">Interface&nbsp;from&nbsp;the&nbsp;macro&nbsp;to&nbsp;TBWiki</a></li>
19  <ul>
20    <li><a href="#request_object">request&nbsp;object</a></li>
21    <li><a href="#req_functions">req&nbsp;functions</a></li>
22    <li><a href="#tbwiki_functions">tbwiki&nbsp;functions</a></li>
23    <li><a href="#return_value">return&nbsp;value</a></li>
24  </ul>
25  <li><a href="#Basic_Sample_-_'Include'_macro">Basic&nbsp;Sample&nbsp;-&nbsp;'Include'&nbsp;macro</a></li>
26  <ul>
27    <li><a href="#macro_code">macro&nbsp;code</a></li>
28    <li><a href="#processor_invocation">processor&nbsp;invocation</a></li>
29    <li><a href="#macro_result">macro&nbsp;result</a></li>
30  </ul>
31</ul>
32</div></td></tr></table>
33<h1><a name="Introduction">Introduction</a>
34<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=Introduction">edit section</a>]</font></span>
35</h1>
36TBWiki supports two kinds of extension mechanisms:  "macros" and "processors".
37<p>
38There are a few builtin macros, but add-on macros and processors
39can be created and are "run" when a page is parsed and sent by TBWiki.
40<p>
41The function of both of these extension mechanisms (or plugins) is
42to allow for dynamic creation of page content at the time a page
43is read by a user.  Thus, these act like a kind of embedded CGI-script
44inside of the TBWiki framework.
45<p>
46<h1><a name="Name_and_Location">Name and Location</a>
47<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=Name_and_Location">edit section</a>]</font></span>
48</h1>
49By convention, the name of a macro is in CamelCase (words strung
50together with the first letter of each word capitalized).
51<p>
52Plugin macros are placed in the data/plugin
53directory.  They are python files and must have a filename starting with
54the "Macro", then the macro name, and ending in the extension
55".py".  For example the  "Foo" macro would have the path and filename
56<p>
57<code>&lt;data_dir_for_this_wiki&gt;/plugin/MacroFoo.py</code>
58<p>
59Often, the plugin directory will merely be a symlink to the main plugin
60directory offered by the tbwiki engine (e.g. at <code>&lt;tbwiki_dir&gt;/cgi-bin/plugins</code>)
61<p>
62<h1><a name="Declaration_in_a_TBWiki_Page">Declaration in a TBWiki Page</a>
63<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=Declaration_in_a_TBWiki_Page">edit section</a>]</font></span>
64</h1>
65A macro is declared on a tbwiki page on a single line with the syntax:
66<pre>
67{{Foo}}
68</pre>
69<p>
70The macro name in the declaration must match the
71name part of the filename for the macro python module
72in the plugin directory.  Thus, the macro "Foo" above would
73invoke code in the <code>plugins/MacroFoo.py</code> module.
74<p>
75Macro arguments (if any) can be specified in the macro declaration, using
76parenthesis, like so:
77<pre>
78{{Foo(arg1, arg2, etc.)}}
79</pre>
80<p>
81TBwiki delivers the arguments as a single string, consisting of exactly
82the characters inside the parens.  Parsing this string into separate
83arguments (e.g. splitting it on comma, and eliminating white space) are
84performed by the macro itself.
85<p>
86Note that macros can be declared on a line by themselves, or embedded
87inline along with other markup, like so:
88<pre>
89   This is a line with an embedded {{Foo(arg1)}} macro
90</pre>
91<p>
92<h1><a name="Interface_from_TBWiki_to_the_macro">Interface from TBWiki to the macro</a>
93<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=Interface_from_TBWiki_to_the_macro">edit section</a>]</font></span>
94</h1>
95A macro must be an importable python module, with some specifically-named
96function definitions.  The TBWiki calls functions in the macro to perform
97actions, usually resulting in the transformation or creation of new content
98that will be returned to the user as part of the page where the macro is
99declared.
100<p>
101<h2><a name="main()_function">main() function</a>
102<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=main()_function">edit section</a>]</font></span>
103</h2>
104A macro must define a function named "main".  As a page is rendered by
105TBWiki, when the macro declaration is encountered
106in the wiki page, TBWiki calls the 'main'
107function to invoke the macro functionality.
108<p>
109This <code>main</code> function takes two arguments, which are
110the request object and the args string.
111<p>
112The macro performs its operation, possibly using the
113information and functions provided in the request object and its
114argument string, and returns a string of HTML data, for output as part of the returned page.
115<p>
116<h3><a name="Example_main()">Example main()</a>
117<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=Example_main()">edit section</a>]</font></span>
118</h3>
119Here is an example definition of <code>main()</code> for a hypothetical macro called <code>MacroError.py</code>:
120<p>
121<pre>
122def main(req, args=""):
123    # do something with args
124    msg = "Error: " + args
125    req.debug_log(msg)
126    html = req.html_error(msg)
127    return html
128</pre>
129<p>
130In this case, the macro creates an error message by
131prepending the string "Error:" to the macro argument.
132Then it logs the error to the debug log,
133and calls <code>html_error()</code> function to color the indicated text
134red, and returns the transformed string to TBWiki for inclusion
135on the page.
136<p>
137<h3><a name="Example_declaration_(of_Error_macro)">Example declaration (of Error macro)</a>
138<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=Example_declaration_(of_Error_macro)">edit section</a>]</font></span>
139</h3>
140The example <code>Error</code> macro might be invoked like so:
141<p>
142<pre>
143  The following text should be red: {{Error(what happened!!)}}  Back to normal.
144</pre>
145<p>
146The text of the macro declaration on a page is replaced
147with the result of executing the macro code, when the page is rendered.
148<p>
149This might result in the following line appearing on the page:
150<p>
151The following text should be red: <font color="red">Error: what happened!! </font>  Back to normal.
152<p>
153<hr size=2>
154<p>
155If no arguments are provided in the macro declaration, like this:
156<pre>
157 {{Error}}
158</pre>
159<p>
160then the value of the "args" argument to <code>main()</code> will be the empty string.
161<p>
162<h2><a name="help()_and_help_oneline()_actions">help() and help_oneline() actions</a>
163<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=help()_and_help_oneline()_actions">edit section</a>]</font></span>
164</h2>
165If a macro defines the special functions "help" and "help_oneline",
166then the system can provide online help for the processor, from a page
167displaying the SystemInfo.  This function is accessed via a URL with
168the name: &lt;page_url&gt;?action=&lt;macro_name&gt;.help
169<p>
170The 'help' function should return text in html format with helpful
171information about the macro.  The 'help_oneline' function should
172return a single-line description of the processor.
173<p>
174<h2><a name="macro_side_effects_or_operations">macro side effects or operations</a>
175<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=macro_side_effects_or_operations">edit section</a>]</font></span>
176</h2>
177Often, a macro is used to place newly-created or transformed content
178onto a page, during rendering.  But it may also be used to perform
179some operation, such as logging, counting items, or performing some
180processing on the wiki or the site where it resides.
181<p>
182For more complicated processing, consider using a "processor"
183instead of a macro.  See <a href="/tbwiki/DocProcessors">DocProcessors</a>.
184<p>
185<h1><a name="Interface_from_the_macro_to_TBWiki">Interface from the macro to TBWiki</a>
186<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=Interface_from_the_macro_to_TBWiki">edit section</a>]</font></span>
187</h1>
188<h2><a name="request_object">request object</a>
189<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=request_object">edit section</a>]</font></span>
190</h2>
191The request object has all the data available to tbwiki about the request
192for this page.  This includes the page_name, the entire tbwiki config, and
193other stuff.
194<p>
195Here are some functions and fields that a macro might use:
196<p>
197<h2><a name="req_functions">req functions</a>
198<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=req_functions">edit section</a>]</font></span>
199</h2>
200Some useful functions of the request object are:
201<ul><li>req.read_page(page_name) - read a page of the wiki
202</ul>
203<p>
204<ul><li>req.form = the CGI form data for the request (in the format provided by the python cgi module)
205<li>req.add_to_message = a function to add to the status message for the page.
206 This is often used for debugging purposes, since it appears separately from the
207 page content
208<li>req.page_filename = filename (including full path) of the requested page
209<li>req.page_name = name of the requested page
210<li>req.config.data_dir = location in the local file system where the data
211 pages are located.
212<li>req.config = configuration settings for this wiki
213<li>req.data = data values (and data value functions) for this wiki
214<ul><li>req.data.version - version of the tbwiki engine
215<li>req.data.asctime - current time in ascii (human readable) format
216</ul><li>req.block_to_html - convert a block of text from tbwiki markup to HTML
217</ul>
218<p>
219<h2><a name="tbwiki_functions">tbwiki functions</a>
220<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=tbwiki_functions">edit section</a>]</font></span>
221</h2>
222You can also import the tbwiki_engine module, to access other helper
223functions for use by the macro plugin.  Here are some that are helpful:
224<ul><li>tbwiki_engine.make_url()
225<li>tbiki_engine.html_error()
226<li>tbiki_engine.parse_state = state used for processing lines during page parsing
227<li>tbiki_engine.show_line() = function used to parse a line of TBWIKI-format text and
228 convert it into HTML output (which is printed by show_line)
229</ul>
230<p>
231<h2><a name="return_value">return value</a>
232<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=return_value">edit section</a>]</font></span>
233</h2>
234The 'main function should return a single string consisting of HTML
235to be output as part of the returned page HTML.
236<p>
237If you want tbwiki to process markup text for you into HTML,
238you can call <code>req.block_to_html(content)</code>, and return the
239result of that.
240<p>
241<h1><a name="Basic_Sample_-_'Include'_macro">Basic Sample - 'Include' macro</a>
242<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=Basic_Sample_-_'Include'_macro">edit section</a>]</font></span>
243</h1>
244Here is sample code for a very simple macro which includes the content
245of another wiki page in the rendered output for the page with the macro.
246<p>
247<h2><a name="macro_code">macro code</a>
248<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=macro_code">edit section</a>]</font></span>
249</h2>
250This would be in the file MacroInclude.py
251<pre>
252import tbwiki_engine
253 
254def main(req, args=""):
255    page_name = args[0]
256    page_data = req.read_page(page_name)
257 
258    html = tbwiki_engine.block_to_html(req, page_data)
259    html += tbwiki_engine.html_close(req.state)
260    return html
261</pre>
262<p>
263<h2><a name="processor_invocation">processor invocation</a>
264<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=processor_invocation">edit section</a>]</font></span>
265</h2>
266To use this processor, a user would place the following on a page:
267<p>
268<pre>
269{{Include(other_page)}}
270</pre>
271<p>
272Assuming the entire page containing the macro looked like this:
273<p>
274<ul><div style="background-color:#ffffe0; padding:5px; border-style: solid solid solid solid; border-width: 1px 1px 1px 1px;">
275<pre>This is data from the page.
276 
277{{Include(other_page)}}
278 
279This is more data from the first page.</pre></div></ul>
280 
281<p>
282And assuming 'other_page' had this content:
283<p>
284<ul><div style="background-color:#ffffe0; padding:5px; border-style: solid solid solid solid; border-width: 1px 1px 1px 1px;">
285<pre>This is content from other_page.</pre></div></ul>
286 
287<p>
288<h2><a name="macro_result">macro result</a>
289<span align=right class="section_edit_link">[<a href="/tbwiki/DocMacros?action=edit&section=macro_result">edit section</a>]</font></span>
290</h2>
291Here is what the resulting output would look like on the page:
292<p>
293<ul><div style="background-color:#ffffe0; padding:5px; border-style: solid solid solid solid; border-width: 1px 1px 1px 1px;">
294<pre>This is data from the page.
295 
296This is content from other_page.
297 
298This is more data from the first page.</pre></div></ul>
299 
300<p>
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

Differences for page "DocMacros"


expected html
generated html
t No Differences Found t No Differences Found 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

Update saved output

Back to diff page

Return to Regression_Test page
TBWiki engine 1.9.3 by Tim Bird