モジュール:サンドボックス/Honeplus/sandbox

local p = {}
--
Template:Tnavbar
function p.tnavbar(frame)
	local args = frame.args
	if not args1 then return ' ' end
	
	local function tf(x)
		return x == '1' and true or false
	end
	args.plain = tf(args.plain)
	args.div = tf(args.div)
	args.nodiv = tf(args.nodiv)
	args.mini = tf(args.mini)
	args.viewplain = tf(args.viewplain)
	if args.miniv == '1' then args.mini, args.viewplain = true, true end
	args.fontstyle = args.fontcolor ~=  and ((args.fontstyle or ) .. ';color:' .. args.fontcolor .. ';') or args.fontstyle or 
	
	local r = {open = } --出力用
	if args.nodiv then
		r.open = r.open .. 'display:inline;padding:0 0.5em;'
	else
		r.open = r.open .. 'background-color:transparent;padding:0;color:#000;'
	end
	r.open = r.open .. args.fontstyle .. (args.style or ) .. '">'
	
	if not (args.plain or args.mini or args.viewplain) then
		r.content = 'このテンプレートを: '
	end
	
	local disp = args.mini and {'表', '話', '編', '歴'} or {'表示', 'ノート', '編集', '履歴'}
	local ns = {'Template:', 'Template‐ノート:', 'Template:', 'Template:'}
	local query = {nil, nil, 'action=edit', 'action=history'}
	local title = {'このテンプレートを表示します', 'このテンプレートのノートを表示します', 'このテンプレートを編集します。保存の前にプレビューを忘れずに。', 'このテンプレートの過去の版を表示します'}
	local color = {, 'color:#002bb8;', 'color:#002bb8;', 'color:#002bb8;'}
	local i = 0
	local i_end = args.viewplain and 1 or 4
	r.content = r.content .. 
	for i = 1, i_end do
		local l = {open = , link = , close = }
		if queryi then
			l.open = 
			l.link = mw.uri.decode(tostring(mw.uri.canonicalUrl(nsi .. args1, queryi))) .. ' '
			l.close = 
		else
			l.open = 
			l.link = nsi .. args1 .. '|'
			l.close = 
		end
		r.content = r.content ..  .. l.open .. l.link ..  .. dispi ..  .. l.close
	end
	r.content = r.content .. 
	
	return r.open .. r.content .. r.close
end
--
Define Arguments
local args = {}
local border
local child, none = false, false
local collapsible = 
local colspan, rowspan = 0, 0
local basestyle = 
local odd, even = 'odd', 'even'
local list, liststyle = {}, {}
local group, groupstyle = {}, {}
local colheader, colheadercolspan, colheaderstyle = {}, {}, {}
local col, colstyle, colwidth = {}, {}, {}
local colfooter, colfootercolspan, colfooterstyle = {}, {}, {}
local abbr, state = {}, {}
local sect, section = {}, {}
local secttitlestyle = {}
local content, contentstyle = {}
local image, imageleft = {}, {}
local result = 	--出力用
local function defArgs(frame)
	args = require('Module:Arguments').getArgs(frame, {parentOnly = true})
	border = args.border or args1
	child, none = (border == 'subgroup' or border == 'child'), (border == 'none')
	collapsible = (args.state == 'plain' or args.state == 'off') and  or 'collapsible '
	
	if args.basestyle then basestyle = args.basestyle .. ';' end
	
	local sortable_mt = {
		__lt = function(a, b) return a.index ') then
				line = prefix ..  .. content .. 
			end
			table.insert(lines, line)
		end
		item = table.concat(lines, '\n')
	end
	if item:match('^*:;#') then
		return '\n' .. item ..'\n'
	end
	return item
end
--
top
local function top()
	if child then
		result = result .. 
	elseif not none then
		result = result .. 
	end
	
	result = result .. 
end
--
title and navbar
local function title()
	if args.titlegroup then
		result = result ..  .. args.titlegroup .. 
	
	if (args.navbar == 'plain') or (not args.name and (child or none)) then
		result = result .. ' '
	elseif args.navbar ~= 'off' then
		local tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or ) .. ';border:none;', fontcolor = }}
		result = result ..  .. p.tnavbar(tbl) .. 
	end
	
	if args.titleclass then
		args.titleclass = ' class="' .. args.titleclass .. '"'
	else
		args.titleclass = 
	end
	result = result ..  .. args.title .. 
	
	if args.state == 'plain' then
		result = result .. ' '
	end
	result = result .. 
end
	
--
above
local function above()
	result = result .. '\n' .. args.above .. 
end
	
--
body
--first group/list and images
local function body1()
	result = result .. 
	if args.imageleft then
		result = result ..  .. args.imageleft .. 
	end
	local j = list1.index
	if groupj then
		result = result ..  .. groupj ..  .. processItem(list1.content) .. 
	if args.image then
		result = result ..  .. args.image .. 
	end
	result = result .. 
end
--remaining groups/lists
local function body2()
	for i = 2, #list do
		odd, even = even, odd
		local j = listi.index
		if groupj then
			result = result ..  .. groupj ..  .. processItem(listi.content) .. 
	end
end
--
below
local function below()
	result = result .. '\n' .. args.below .. 
end
	
--
close
local function close()
	result = result .. 
	
	if child then
		result = result .. 
	elseif not none then
		result = result .. 
	end
end
--
Template:Navbox
function p.navbox(frame)
	defArgs(frame)
	top()
	if args.title then title() end
	if args.above then above() end
	if list1 then body1() end
	body2()
	if args.below then below() end
	close()
	return result
end
--
Template:Navbox subgroup
function p.subgroup(frame)
	defArgs(frame)
	if not border then child = true end
	args.groupstyle = 'padding:' .. (args.grouppadding or '0 0.75em') .. ';' .. (args.groupstyle or )
	top()
	if args.title then title() end
	if args.above then above() end
	if list1 then body1() end
	body2()
	if args.below then below() end
	close()
	return result
end
--
Template:Navbox with columns
function p.with_columns(frame)
	defArgs(frame)
	table.sort(col)
	top()
	if args.title then title() end
	if args.above then above() end
	
	if col1 then
		local j = col1.index
		local cols = 
		--Header row
		if colheaderj then
			cols = cols .. 
			for i = 1, #col do
				local j = coli.index
				if colheaderj then
					cols = cols ..  .. colheaderj .. 
				end
			end
			cols = cols .. 
		end
		--Main columns
		cols = cols .. 
		if not (colheaderj or colfooterj or args.fullwidth) then
			local paddingoff = args.padding and string.find(args.padding, '^0ep?mx?%?;?')
			if not paddingoff then
				cols = cols .. '   '
			end
		end
		for i = 1, #col do
			local j = coli.index
			cols = cols ..  .. coli .. 
			args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyle
		end
		cols = cols .. 
		--Footer row
		if colfooterj then
			cols = cols .. 
			for i = 1, #col do
				local j = coli.index
				if colfooterj then
					cols = cols ..  .. colfooterj .. 
				end
			end
			cols = cols .. 
		end
		cols = cols .. 
		table.insert(list, 1, cols)
	end
	
	body1()
	body2()
	if args.below then below() end
	close()
	return result
end
--
Template:Navbox with collapsible groups
function p.with_collapsible_groups(frame)
	defArgs(frame)
	table.sort(content)
	top()
	if args.title then title() end
	if args.above then above() end
	
	local i = 1
	local function funcList()
		listi = listi or contenti
		local j = listi.index
		collapsible = (statej == 'plain' or statej == 'off') and  or 'collapsible '
		args.state = statej or args.selected and (args.selected == abbrj or args.selected == groupj) and  or 'collapsed'
		args.name = nil
		args.titlestyle = basestyle .. (args.groupstyle or ) .. ';' .. (args.secttitlestyle or ) .. ';' .. (groupstylej or )
		args.liststyle = (args.liststyle or ) .. ';' .. (args.contentstyle or ) .. ';' .. (liststylej or )
		args.title, groupj = groupj, nil
		args.image = imagej
		args.imageleft = imageleftj
		result = result .. 
		if args.title then
			none = true
			top()
			title()
			body1()
			close()
		else
			result = result .. (listi or )
		end
		result = result .. 
	end
	
	--i = 1
	result = result .. 
	if args.imageleft then
		result = result ..  .. args.imageleft .. 
	end
	funcList()
	if args.image then
		result = result ..  .. args.image .. 
	end
	--i > 2
	for i = 2, #list do
		result = result .. 
		list1 = listi
		funcList()
	end
	
	if args.below then below() end
	child, none = (border == 'subgroup' or border == 'child'), (border == 'none') --再定義
	close()
	return result
end
--
Template:NavboxYears
Template:NavboxYears2
local function calc_years(args, fmtLink)
	local numtab = tonumber(args.tab) or 0
	local numstart = tonumber(args.start)
	local numend = tonumber(args'end')
	local numstep = tonumber(args.step) or 1
	if numstart and numend then
		if numtab > 0 then
			for i = 2, numtab + 1 do
				argsi = nil
			end
		end
		local numD = numend - numstart + 1
		for i = 1, numD, numstep do
			argsi + numtab + 1 = numstart + i - 1
		end
	end
	local result =  
	local h = 1
	repeat
		h = h + 1
		result = result .. 
		for i = 2, 11 do
			result = result .. 
			if (tonumber(argsi) or -1) > 0 then
				result = result .. ( .. fmtLink(args1, argsi) .. '|' .. argsi .. )
			else
				result = result .. (argsi or )
			end
			result = result .. 
			argsi, argsi + 10 = argsi + 10, argsi + h * 10
		end
		result = result .. 
	until not args2
	result = result .. 
	return result
end
local function years(frame, fmtLink)
	defArgs(frame)
	if args.var then fmtLink = function(str, num) return str:gsub(args.var, num) end end
	if args.name then
		args.style = 'width:' .. (args.width or '38em') .. ';' .. (args.style or )
		top()
		if args.title then title() end
		if args.above then above() end
		if not list1 and args1 then list1 = calc_years(args, fmtLink) end
		if list1 then body1() end
		body2()
		if args.below then below() end
		close()
		return result
	else
		return calc_years(args, fmtLink)
	end
end
function p.years(frame)
	local fmtLink = function(str, num) return str .. num end
	return years(frame, fmtLink)
end
function p.years2(frame)
	local fmtLink = function(str, num) return num .. str end
	return years(frame, fmtLink)
end
return p