Module:Columns

local getArgs = require('Module:Arguments').getArgs

local p = {}

local class = {} local style = {} local text = {} local add_default = true

-- _class processes class. local function _class(value) if value == nil or value == "" then return "" end

class[#class + 1] = "class='" class[#class + 1] = value class[#class + 1] = "' " end

-- _append_style appends the given property and value to the style table. local function _append_style(property, value) style[#style + 1] = property style[#style + 1] = ":" style[#style + 1] = value style[#style + 1] = ";" end

-- _text processes text. local function _text(value) if value == nil or value == "" then return end

text[#text + 1] = value end

-- _columns processes columns. local function _columns(value) if value == nil or value == "" then return end

-- Treat long unnamed parameters as content. if string.len(value) >= 10 then _text(value) return end

_append_style("-webkit-columns", value) _append_style("-moz-columns", value) _append_style("columns", value) add_default = false end

-- _count processes column-count. local function _count(value) if value == nil or value == "" then return end

if tonumber(value) == nil and value ~= "auto" then error("Parameter error - count must be a number or 'auto'.") end _append_style("-webkit-column-count", value) _append_style("-moz-column-count", value) _append_style("column-count", value) add_default = false end

-- _end_tag returns the div end tag. local function _end_tag return " " end

-- _gap processes column-gap. local function _gap(value) if value == nil or value == "" then return end

_append_style("-webkit-column-gap", value) _append_style("-moz-column-gap", value) _append_style("column-gap", value) end

-- _rule processes column-rule. local function _rule(value) if value == nil or value == "" then return end

_append_style("-webkit-column-rule", value) _append_style("-moz-column-rule", value) _append_style("column-rule", value) end

-- _rules processes Div_col rules default value. local function _rules(value) if string.lower(value) == "yes" then _rule("1px solid #AAA") end end

-- _rule_color processes column-rule-color. local function _rule_color(value) if value == nil or value == "" then return end

_append_style("-webkit-column-rule-color", value) _append_style("-moz-column-rule-color", value) _append_style("column-rule-color", value) end

-- _rule_style processes column-rule-style. local function _rule_style(value) if value == nil or value == "" then return end

_append_style("-webkit-column-rule-style", value) _append_style("-moz-column-rule-style", value) _append_style("column-rule-style", value) end

-- _rule_width processes column-rule-width. local function _rule_width(value) if value == nil or value == "" then return end

_append_style("-webkit-column-rule-width", value) _append_style("-moz-column-rule-width", value) _append_style("column-rule-width", value) end

-- _start_tag returns the div start tag. local function _start_tag return "" end

-- _style processes style. local function _style(value) if value == nil or value == "" then return end

if string.sub(value, -1) ~= ";" then value = value .. ";"	end

style[#style + 1] = value end

-- _small processes Div_col small default value. local function _small(value) if string.lower(value) == "yes" then _style("font-size:90%;") end end

-- _width processes column-width. local function _width(value) if value == nil or value == "" then return end

_append_style("-webkit-column-width", value) _append_style("-moz-column-width", value) _append_style("column-width", value) add_default = false end

-- _columns_break processes Columns|columns_break. local function _columns_break(args) local div = { " "

return table.concat(div) end

-- _columns_manual process Columns.|columns_manual. local function _columns_manual(args) local div = { "",		""	}

-- TODO: Add width and style parameters.

return table.concat(div) end

-- _columns__span processes Columns|columns_span. -- Not supported in Firefox as of November 2016. local function _columns_span(args) local parameters = { [1] = _text, ['style'] = _style, ['text'] = _text, }

_style("-webkit-column-span:all;column-span:all;") for key, value in pairs(args) do		if parameters[key] == nil then error("Unexpected parameter " .. key .. ".") end -- Call parameter function passing parameter value parameters[key](value) end

return "" .. 		table.concat(text) .. " " end

-- _columns_start processes Columns|column_start. function _columns_start(args) local parameters = { [1] = _columns, [2] = _columns, ['columns'] = _columns, ['count'] = _count, ['gap'] = _gap, ['rule'] = _rule, ['rulecolor'] = _rule_color, ['rulestyle'] = _rule_style, ['rulewidth'] = _rule_width, ['style'] = _style, ['text'] = _text, ['width'] = _width, ['cols'] = _columns,     -- To replace Div_col template. ['colwidth'] = _width,   -- To replace Div_col template. ['rules'] = _rules,      -- To replace Div_col template. ['small'] = _small       -- To replace Div_col template. }

for key, value in pairs(args) do		if parameters[key] == nil then error("Unexpected parameter " .. key .. ".") end -- Call parameter function passing parameter value parameters[key](value) end

if add_default == true then _columns("2") end

return _start_tag end

function p.columns(frame) return _columns_start(getArgs(frame)) .. " " ..		table.concat(text) .. _end_tag end

function p.columns_break(frame) return _columns_break(getArgs(frame)) end

function p.columns_manual(frame) return _columns_manual(getArgs(frame)) end

function p.columns_end(frame) return _end_tag end

function p.columns_span(frame) return _columns_span(getArgs(frame)) end

function p.columns_start(frame) return _columns_start(getArgs(frame)) .. " " end

return p