Module:Grid: Difference between revisions

From Night's End
mNo edit summary
mNo edit summary
Line 68: Line 68:


function getBorder(frame)
function getBorder(frame)
if frame.args['border'] == true then  
if frame.args['border'] == "true" then  
return "border:1px solid #DDDDDD;"
return "border:1px solid #DDDDDD;"
else
else
Line 78: Line 78:
if not frame.args['background'] == nil then  
if not frame.args['background'] == nil then  
return "background-color: " .. frame.args['background'] .. ";"
return "background-color: " .. frame.args['background'] .. ";"
elseif frame.args['border'] == true then  
elseif frame.args['border'] == "true" then  
return "background-color:#ffffff;"
return "background-color:#ffffff;"
else
else
Line 86: Line 86:


function getTextAlignment(frame)
function getTextAlignment(frame)
if frame.args['center'] == true then  
if frame.args['center'] == "true" then  
return "text-align:center;"
return "text-align:center;"
else
else
Line 94: Line 94:


function getPadding(frame)
function getPadding(frame)
if frame.args['nomargin'] == true then  
if frame.args['nomargin'] == "true" then  
return "padding:0px;;"
return "padding:0px;;"
elseif frame.args['center'] == true then  
elseif frame.args['center'] == "true" then  
return "padding:20px;"
return "padding:20px;"
else
else
Line 104: Line 104:


function getMargin(frame)
function getMargin(frame)
if frame.args['nomargin'] == true then  
if frame.args['nomargin'] == "true" then  
return "margin:0px;;"
return "margin:0px;;"
elseif frame.args['border'] == true then  
elseif frame.args['border'] == "true" then  
return "margin:4px;"
return "margin:4px;"
else
else

Revision as of 16:21, 9 June 2023

Documentation for this module may be created at Module:Grid/doc

local p = {}

function p.begin(frame)
	return getBeginDiv(frame)
end

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

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

function getBeginDiv(frame)
	local cols = getCols(frame)
	
	return "<div style=\"display:inline-table;width:" .. getWidth(cols) .. ";min-width:" .. getMinWidth(frame, cols) .. ";\">" .. 
	"<div style=\"" .. getBorder(frame) .. getBackground(frame) .. getTextAlignment(frame) ..  getPadding(frame) ..  getMargin(frame) .. "\">"
end

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

function getWidth(cols)
	if cols == "0" then
		return "auto"
	elseif cols == "1" then
		return "100%"
	elseif cols == "2" then
		return "49%"
	elseif cols == "3" then
      return "32%"
    elseif cols == "4" then
      return "24%"
    elseif cols == "5" then
      return "19%"
    elseif cols == "6" then
      return "16%"
    end
end

function getMinWidth(frame, cols)
	if frame.args['ignoreminwidth'] == nil or frame.args['ignoreminwidth'] == false then
		if cols == "0" then
			return "auto"
		elseif cols == "1" then
			return "100%"
		elseif cols == "2" then
			return "400px"
		elseif cols == "3" then
			return "270px"
		elseif cols == "4" then
	      return "200px"
	    elseif cols == "5" then
	      return "150px"
	    elseif cols == "6" then
	      return "125px"
	    end
	end
	return 0
end

function getBorder(frame)
	if frame.args['border'] == "true" then 
		return "border:1px solid #DDDDDD;"
	else
		return ""
	end
end

function getBackground(frame)
	if not frame.args['background'] == nil then 
		return "background-color: " .. frame.args['background'] .. ";"
	elseif frame.args['border'] == "true" then 
		return "background-color:#ffffff;"
	else
		return "background-color:#FFFFFF00;"
	end
end

function getTextAlignment(frame)
	if frame.args['center'] == "true" then 
		return "text-align:center;"
	else
		return ""
	end
end

function getPadding(frame)
	if frame.args['nomargin'] == "true" then 
		return "padding:0px;;"
	elseif frame.args['center'] == "true" then 
		return "padding:20px;"
	else
		return "padding:10px;"
	end
end

function getMargin(frame)
	if frame.args['nomargin'] == "true" then 
		return "margin:0px;;"
	elseif frame.args['border'] == "true" then 
		return "margin:4px;"
	else
		return ""
	end
end

return p