Module:Columns

From Night's End

Mark sections of text with column-count css.

Functions

begin

{{#invoke:Columns|begin|cols=2}}

This function marks the beginning of a section.

Parameters
cols The number of columns (2 to 4). Defaults to 2.


stop

{{#invoke:Columns|stop}}

This function marks the end of a section. It has no parameters.


div

{{#invoke:Columns|div|cols=2}}

This function is basically "stop" immediately followed by "begin". This creates a break between two sections.

Parameters
cols The number of columns (2 to 4). Defaults to 2.

local p = {}

function p.begin(frame)
	local cols = getCols(frame)
	return "<div style=\"column-count:" .. cols .. "; column-width:" .. getWidth(cols) .. "; column-gap:40px; column-rule: 2px solid #d6d6d6;\">"
end

function p.div(frame)
	local cols = getCols(frame)
	return "</div><div style=\"column-count:" .. cols .. "; column-width:" .. getWidth(cols) .. "; column-gap:40px; column-rule: 2px solid #d6d6d6;\">"
end

function p.stop(frame)
	return "</div>"
end

function getCols(frame)
	local cols = frame.args['cols']
	if cols == nil then
		return "2"
	end
	return cols
end

function getWidth(cols)
	if cols == "2" then
		return "300px"
	elseif cols == "3" then
      return "200px"
    elseif cols == "4" then
      return "150px"
    end
end

return p