Module:User:Vorziblix/test

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Vorziblix, for his own experimentation. Items in this module may be added and removed at Vorziblix's discretion; do not rely on this module's stability.


local export = {}

function export.concat(frame)
	return frame.args[1] .. frame.args[2]
end

function export.blahblahdebug(frame)
	local default_title = frame.args['head'] or mw.title.getCurrentTitle().text
	default_title = 'Alternative hieroglyphic writings of ' .. frame:expandTemplate{title = 'lang', args = {'egy', default_title, face = 'term'}}
	local tabletitle = frame.args['title'] or default_title
	local text = '<div class="NavFrame" style="clear:both;display:inline-block;">\n<div class="NavHead" style="">' .. tabletitle .. '&nbsp;&nbsp;</div>\n<div class="NavContent">\n{| style="text-align:center;"'
	local i = 1
	while frame.args[i] do
		text = text .. '\n| style="background-color:#efefef"|<span style="margin:0px 6px;">' .. frame.args[i] .. '</span>'
		i = i + 1
	end
	text = text .. '\n| nothing\n|}</div></div>'
	return text
end

function export.hieroforms(frame)
	local default_title = frame.args['head'] or mw.title.getCurrentTitle().text
	default_title = 'Alternative hieroglyphic writings of ' .. frame:expandTemplate{title = 'lang', args = {'egy', default_title, face = 'term'}}
	local tabletitle = frame.args['title'] or default_title
	local text = '<div class="NavFrame" style="clear:both;display:inline-block;">\n<div class="NavHead" style="">' .. tabletitle .. '&nbsp;&nbsp;</div>\n<div class="NavContent">\n{| style="text-align:center;"'
	local i = 1
	while frame.args[i] do
		text = text .. '\n| style="background-color:#efefef"|<span style="margin:0px 6px;">' .. frame.args[i] .. '</span>'
		i = i + 1
	end
	local j = 1
	local no_read = true
	local since_last = 1
	local read = 'read1'
	while j < i do
		if frame.args[read] then
			if no_read then
				text = text .. '\n|-'
				no_read = false
			end
			while since_last > 0 do
				text = text .. '\n|'
				since_last = since_last - 1
			end
			text = text .. 'style="background-color:#efefef"|' .. frame:expandTemplate{title = 'm-self', args = {'egy', frame.args[read]}}
		end
		since_last = since_last + 1
		j = j + 1
		read = 'read' .. j
	end
	j = 1
	local no_date = true
	since_last = 1
	local date = 'date1'
	while j < i do
		if frame.args[date] then
			if no_date then
				text = text .. '\n|-'
				no_date = false
			end
			while since_last > 0 do
				text = text .. '\n|'
				since_last = since_last - 1
			end
			text = text .. 'style="background-color:#efefef"|' .. frame:expandTemplate{title = 'defdate', args = {frame.args[date]}}
		end
		since_last = since_last + 1
		j = j + 1
		date = 'date' .. j
	end
	j = 1
	local no_note = true
	since_last = 1
	local since_note = 1
	local note = 'note1'
	while j < i do
		if frame.args[note] then
			if no_note then
				text = text .. '\n|- style="font-size:70%"'
				no_note = false
			end
			while since_last > 0 do
				text = text .. '\n|'
				since_last = since_last - 1
			end
			text = text .. 'style="background-color:#efefef"|' .. frame.args[note]
		end
		since_last = since_last + 1
		j = j + 1
		note = 'note' .. j
	end
	text = text .. '\n|}</div></div>'
	return text
end

function export.remove_comments(input)
	return mw.ustring.gsub(input, '<!%-%-(.-)%-%->', '')
end

function export.tokenize_hiero(input)
	input = mw.ustring.gsub(input, ' ', '-')
	input = mw.ustring.gsub(input, '\n', '-')
	input = mw.ustring.gsub(input, '\r', '-')
	input = mw.ustring.gsub(input, '\t', '-')
	input = mw.ustring.gsub(input, '%-%-+', '-')
	local quadrats = {}
	local i = 1
	while true do
		j = string.find(input, '-', i, true)
		if j ~= nil then
			table.insert(quadrats, string.sub(input, i, j - 1))
			i = j + 1
		else
			table.insert(quadrats, string.sub(input, i))
			break
		end
	end
	return quadrats
end

function export.mdc_to_image(mdc, height_in)
	local height = height_in or '38'
	local mirrored = ''
	if string.sub(mdc, -1) == '\\' then
		mirrored = '|class=mw-mirrored'
		mdc = string.sub(mdc, 1, -2)
	end
	local image = '<span style="margin: 1px;">\[\[File:Abydos-Bold-hieroglyph-' .. mdc .. '.png|' .. mdc .. '|x' .. height .. 'px|link=' .. mirrored .. '\]\]</span>'
	return image
end

function export.render_quadrat(unrendered)
	if unrendered == '!' then
		rendered = '</tr></table><table class="mw-hiero-table"><tr>'
	elseif unrendered == '<' then
		rendered = '<td>' .. '<span style="margin: 1px;">\[\[File:Hiero Ca1.svg|&lt;|x46px|link=\]\]</span>' .. '</td><td><table class="mw-hiero-table"><tr><td class="mw-hiero-box" style="height:2px;"></td></tr><tr><td><table class="mw-hiero-table"><tr><td>'
	elseif unrendered == '>' then
		rendered = '</td></tr></table></td></tr><tr><td class="mw-hiero-box" style="height:2px;"></td></tr></table></td><td>' .. '<span style="margin: 1px;">\[\[File:Hiero Ca2.svg|&gt;|x46px|link=\]\]</span>' .. '</td>'
	else
		stack = string.find(unrendered, ':')
		if stack ~= nil then
			upper = export.mdc_to_image(string.sub(unrendered, 1, stack - 1), '19')
			lower = export.mdc_to_image(string.sub(unrendered, stack + 1), '19')
			rendered = '<td height="40">' .. upper .. '<br>' .. lower .. '</td>'
		else
			rendered = export.mdc_to_image(unrendered)
			rendered = '<td height="40">' .. rendered .. '</td>'
		end
	end
	return rendered
end

function export.hiero(frame)
	local output = {}
	local hieros = frame.args[1]
	hieros = export.remove_comments(hieros)
	local tokenized = export.tokenize_hiero(hieros)
	for k, v in ipairs(tokenized) do
		v = export.render_quadrat(v)
		table.insert(output, v)
	end
	return '<table class="mw-hiero-table mw-hiero-outer" style="display:inline-table;vertical-align:middle;" dir="ltr"><tr><td><table class="mw-hiero-table"><tr>' .. table.concat(output) .. '</tr></table></td></tr></table>'
end

return export