Difference between revisions of "Module:TableBuilder"
Jump to navigation
Jump to search
m (Updated references to helper methods) |
(FnControlOption changed the content model of the page Module:TableBuilder from "plain text" to "Scribunto") Tag: content model change |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 43: | Line 43: | ||
__tostring = tostring, | __tostring = tostring, | ||
__index = { | __index = { | ||
+ | _buildAttributes = methodtable._buildAttributes, | ||
+ | _buildStyles = methodtable._buildStyles, | ||
+ | _buildNodes = methodtable._buildNodes, | ||
_build = function(t, ret) | _build = function(t, ret) | ||
table.insert(ret, '{|') | table.insert(ret, '{|') | ||
Line 63: | Line 66: | ||
__tostring = tostring, | __tostring = tostring, | ||
__index = { | __index = { | ||
+ | _buildNodes = methodtable._buildNodes, | ||
_build = function(t, ret) | _build = function(t, ret) | ||
table.insert(ret, '\n|-') | table.insert(ret, '\n|-') | ||
Line 77: | Line 81: | ||
__tostring = tostring, | __tostring = tostring, | ||
__index = { | __index = { | ||
+ | _buildAttributes = methodtable._buildAttributes, | ||
+ | _buildStyles = methodtable._buildStyles, | ||
+ | _buildNodes = methodtable._buildNodes, | ||
_build = function(t, ret) | _build = function(t, ret) | ||
table.insert(ret, '\n' .. t.mark) | table.insert(ret, '\n' .. t.mark) |
Latest revision as of 17:41, 7 June 2022
Documentation for this module may be created at Module:TableBuilder/doc
local TableBuilder = {} local HtmlBuilder = require('Module:HtmlBuilder') local methodtable = getmetatable(HtmlBuilder.create()).__index local tablemetatable, rowmetatable, cellmetatable local function createBuilder(metatable, parent) local builder = {} setmetatable(builder, metatable) builder.nodes = {} if parent then builder.parent = parent table.insert(parent.nodes, builder) end return builder end function TableBuilder.create() local builder = createBuilder(tablemetatable) builder.attributes = {} builder.styles = {} return builder end local function addCell(t, mark, ...) local builder = createBuilder(cellmetatable, t) builder.attributes = {} builder.styles = {} builder.mark = mark if ... then builder:wikitext(...) end return builder end local function tostring(t) local ret = {} t:_build(ret) return table.concat(ret) end tablemetatable = { __tostring = tostring, __index = { _buildAttributes = methodtable._buildAttributes, _buildStyles = methodtable._buildStyles, _buildNodes = methodtable._buildNodes, _build = function(t, ret) table.insert(ret, '{|') t:_buildAttributes(ret) t:_buildStyles(ret) t:_buildNodes(ret) table.insert(ret, '\n|}') end, addCaption = function(t, ...) return addCell(t, "|+", ...) end, addRow = function(t) return createBuilder(rowmetatable, t) end, getAttr = methodtable.getAttr, attr = methodtable.attr, addClass = methodtable.addClass, css = methodtable.css, cssText = methodtable.cssText } } rowmetatable = { __tostring = tostring, __index = { _buildNodes = methodtable._buildNodes, _build = function(t, ret) table.insert(ret, '\n|-') t:_buildNodes(ret) end, addHeader = function(t, ...) return addCell(t, "!", ...) end, addData = function(t, ...) return addCell(t, "|", ...) end, done = methodtable.done, allDone = methodtable.allDone } } cellmetatable = { __tostring = tostring, __index = { _buildAttributes = methodtable._buildAttributes, _buildStyles = methodtable._buildStyles, _buildNodes = methodtable._buildNodes, _build = function(t, ret) table.insert(ret, '\n' .. t.mark) t:_buildAttributes(ret) t:_buildStyles(ret) table.insert(ret, '|') t:_buildNodes(ret) end, node = methodtable.node, wikitext = methodtable.wikitext, tag = methodtable.tag, getAttr = methodtable.getAttr, attr = methodtable.attr, addClass = methodtable.addClass, css = methodtable.css, cssText = methodtable.cssText, done = methodtable.done, allDone = methodtable.allDone } } return TableBuilder