Module:Flatlist

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules


Usage

[edit]
{{#invoke:Flatlist|flatlist}}
local flatlist = require('Module:Flatlist')._flatlist


Code

require('strict')

local p = {} --p stands for package
local getArgs = require('Module:Arguments').getArgs
local make_attribute_string = require('Module:Optional CSS attribute').make_attribute_string

function p._flatlist(args)
	local class = make_attribute_string('class', {['class'] = 'hlist ' .. (args.class or '')})
	local indent = tonumber(args.indent)
	if indent then
		indent = indent * 1.6 .. 'em'
	end
	local style = make_attribute_string('style', {['margin-left'] = indent, ['style'] = args.style})
	
	local content = args[1]
	
	local list = mw.getCurrentFrame():preprocess('<templatestyles src="Template:Flatlist/styles.css"/>') .. '<div ' .. class .. ' ' .. style .. '>'
	if content then
		list = list .. '\n' .. content .. '\n</div>'
	end
	return list
end

function p.flatlist(frame)
	return p._flatlist(getArgs(frame))
end

return p