Difference between revisions of "Module:TableBuilder"
Jump to navigation
Jump to search
m |
(FnControlOption changed the content model of the page Module:TableBuilder from "plain text" to "Scribunto") Tag: content model change |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
local HtmlBuilder = require('Module:HtmlBuilder') | local HtmlBuilder = require('Module:HtmlBuilder') | ||
− | |||
− | |||
− | |||
local methodtable = getmetatable(HtmlBuilder.create()).__index | local methodtable = getmetatable(HtmlBuilder.create()).__index | ||
local tablemetatable, rowmetatable, cellmetatable | local tablemetatable, rowmetatable, cellmetatable | ||
Line 24: | Line 21: | ||
builder.styles = {} | builder.styles = {} | ||
return builder | return builder | ||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 39: | Line 32: | ||
end | end | ||
return builder | return builder | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 71: | Line 43: | ||
__tostring = tostring, | __tostring = tostring, | ||
__index = { | __index = { | ||
− | _build = | + | _buildAttributes = methodtable._buildAttributes, |
− | addRow = | + | _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, | getAttr = methodtable.getAttr, | ||
attr = methodtable.attr, | attr = methodtable.attr, | ||
Line 84: | Line 66: | ||
__tostring = tostring, | __tostring = tostring, | ||
__index = { | __index = { | ||
− | _build = | + | _buildNodes = methodtable._buildNodes, |
+ | _build = function(t, ret) | ||
+ | table.insert(ret, '\n|-') | ||
+ | t:_buildNodes(ret) | ||
+ | end, | ||
addHeader = function(t, ...) return addCell(t, "!", ...) end, | addHeader = function(t, ...) return addCell(t, "!", ...) end, | ||
addData = function(t, ...) return addCell(t, "|", ...) end, | addData = function(t, ...) return addCell(t, "|", ...) end, | ||
Line 95: | Line 81: | ||
__tostring = tostring, | __tostring = tostring, | ||
__index = { | __index = { | ||
− | _build = | + | _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, | wikitext = methodtable.wikitext, | ||
+ | tag = methodtable.tag, | ||
getAttr = methodtable.getAttr, | getAttr = methodtable.getAttr, | ||
attr = methodtable.attr, | attr = methodtable.attr, | ||
+ | addClass = methodtable.addClass, | ||
css = methodtable.css, | css = methodtable.css, | ||
cssText = methodtable.cssText, | cssText = methodtable.cssText, |
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