<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.limswiki.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AHtmlBuilder%2Fdoc</id>
	<title>Module:HtmlBuilder/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.limswiki.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AHtmlBuilder%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Module:HtmlBuilder/doc&amp;action=history"/>
	<updated>2026-04-05T22:31:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://www.limswiki.org/index.php?title=Module:HtmlBuilder/doc&amp;diff=13167&amp;oldid=prev</id>
		<title>Shawndouglas: Created as needed.</title>
		<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Module:HtmlBuilder/doc&amp;diff=13167&amp;oldid=prev"/>
		<updated>2013-10-30T23:55:35Z</updated>

		<summary type="html">&lt;p&gt;Created as needed.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
HtmlBuilder provides a way to construct complex HTML and CSS markup by creating a tree of nodes, similar to the Document Object Model. The result is a list of codes that are more comprehensible and maintainable than if you simply concatenated strings together.  It offers a fluent interface that should look familiar to any user of jQuery.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
First, you need to load the module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;local HtmlBuilder = require('Module:HtmlBuilder')&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, create the root HtmlBuilder instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;local builder = HtmlBuilder.create()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you can build HTML using the methods of the HtmlBuilder instance, listed below.&lt;br /&gt;
&lt;br /&gt;
Finally, get the resulting HTML markup as a string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;local s = tostring(builder)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Methods ==&lt;br /&gt;
To allow chaining, all methods return a reference to the builder, unless otherwise stated.&lt;br /&gt;
&lt;br /&gt;
===tag===&lt;br /&gt;
&amp;lt;code&amp;gt;local div = builder.tag('div')&amp;lt;/code&amp;gt;&lt;br /&gt;
Appends a new child node to the builder, and returns an HtmlBuilder instance representing that new node.&lt;br /&gt;
&lt;br /&gt;
===done===&lt;br /&gt;
&amp;lt;code&amp;gt;builder = div.done()&amp;lt;/code&amp;gt;&lt;br /&gt;
Returns the parent node under which the current node was created.  Like [http://api.jquery.com/end/ jQuery.end], this is a convenience function to allow the construction of several child nodes to be chained together into a single statement.&lt;br /&gt;
&lt;br /&gt;
===allDone===&lt;br /&gt;
&amp;lt;code&amp;gt;builder = div.allDone()&amp;lt;/code&amp;gt;&lt;br /&gt;
Like &amp;lt;code&amp;gt;.done()&amp;lt;/code&amp;gt;, but traverses all the way to the root node of the tree and returns it.&lt;br /&gt;
&lt;br /&gt;
===wikitext===&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;div.wikitext('This is some [[example]] text.')&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
Appends some markup to the node. It may include plain text, wiki markup, and even HTML markup.&lt;br /&gt;
&lt;br /&gt;
===newline===&lt;br /&gt;
&amp;lt;code&amp;gt;div.newline()&amp;lt;/code&amp;gt;&lt;br /&gt;
Appends a newline character to the node. Equivalent to &amp;lt;code&amp;gt;.wikitext('\n')&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===attr===&lt;br /&gt;
&amp;lt;code&amp;gt;div.attr('title', 'Attr value')&amp;lt;/code&amp;gt;&lt;br /&gt;
Set an HTML attribute on the node.&lt;br /&gt;
&lt;br /&gt;
===css===&lt;br /&gt;
&amp;lt;code&amp;gt;div.css('color', '#f00')&amp;lt;/code&amp;gt;&lt;br /&gt;
Set a CSS property to be added to the node's &amp;lt;code&amp;gt;style&amp;lt;/code&amp;gt; attribute.&lt;br /&gt;
&lt;br /&gt;
===cssText===&lt;br /&gt;
&amp;lt;code&amp;gt;div.cssText('color:#f00; font-size:1.5em')&amp;lt;/code&amp;gt;&lt;br /&gt;
Add some raw CSS to the node's &amp;lt;code&amp;gt;style&amp;lt;/code&amp;gt; attribute. This is typically used when a template allows some CSS to be passed in as a parameter, such as the &amp;lt;code&amp;gt;liststyle&amp;lt;/code&amp;gt; parameter of {{tl|Navbox}}.&lt;br /&gt;
&lt;br /&gt;
===addClass===&lt;br /&gt;
&amp;lt;code&amp;gt;div.addClass('even')&amp;lt;/code&amp;gt;&lt;br /&gt;
Adds a class name to the node's &amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; attribute. Spaces will be automatically added to delimit each added class name.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local HtmlBuilder = require('Module:HtmlBuilder')&lt;br /&gt;
&lt;br /&gt;
local root = HtmlBuilder.create()&lt;br /&gt;
&lt;br /&gt;
root&lt;br /&gt;
    .wikitext('Lorem ')&lt;br /&gt;
    .tag('span')&lt;br /&gt;
        .css('color', 'red')&lt;br /&gt;
        .attr('title', 'ipsum dolor')&lt;br /&gt;
        .wikitext('sit amet')&lt;br /&gt;
        .done()&lt;br /&gt;
    .tag('div')&lt;br /&gt;
        .wikitext('consectetur adipisicing')&lt;br /&gt;
&lt;br /&gt;
local s = tostring(root)&lt;br /&gt;
-- s = 'Lorem &amp;lt;span style=&amp;quot;color:red;&amp;quot; title=&amp;quot;ipsum dolor&amp;quot;&amp;gt;sit amet&amp;lt;/span&amp;gt;&amp;lt;div&amp;gt;consectetur adipisicing&amp;lt;/div&amp;gt;'&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For more examples, please see the [[Module:HtmlBuilder/testcases|test cases page]] and the [[Module talk:HtmlBuilder/testcases|test cases results]].&lt;/div&gt;</summary>
		<author><name>Shawndouglas</name></author>
	</entry>
</feed>