सामग्री पर जाएँ

मॉड्यूल:cite-meta

विक्षनरी से

"इस मॉड्यूल हेतु प्रलेख मॉड्यूल:cite-meta/doc पर बनाया जा सकता है"

local export = {}

function export.show(frame)

	local list_with_holes = { list = true, allow_holes = true }
	local params = {
		[1] = { alias_of = 'year' },
		[2] = { alias_of = 'author' },
		[3] = { alias_of = 'title' },
		["year"] = list_with_holes,
		["author"] = list_with_holes,
		["last"] = list_with_holes,
		["first"] = list_with_holes,
		["authorlinks"] = list_with_holes,
		["title"] = {},
		["transtitle"] = {},
		["trans-title"] = { alias_of = 'transtitle' },
		["lang"] = {},
		["worklang"] = { alias_of = 'lang' },
		["coauthors"] = {},
		["type"] = { default = 'book' },
		["contributor"] = list_with_holes,
		["translator"] = list_with_holes,
		["editor"] = list_with_holes,
		["compiler"] = list_with_holes,
		["quotee"] = {},
		["entry"] = {},
		["chapter"] = { alias_of = 'entry' },
		["transentry"] = {},
		["trans-entry"] = { alias_of = 'transentry' },
		["trans-chapter"] = { alias_of = 'transentry' },
		["url"] = {},
		["location"] = {},
		["publisher"] = {},
		["yearpublished"] = {},
		["year_published"] = { alias_of = 'yearpublished' },
		["series"] = {},
		["seriesvolume"] = {},
		["version"] = {},
		["volume"] = {},
		["section"] = {},
		["edition"] = {},
		["issue"] = {},
		["others"] = {},
		["id"] = list_with_holes,
		["bibcode"] = {},
		["doi"] = {},
		["isbn"] = {},
		["issn"] = {},
		["jstor"] = {},
		["lccn"] = {},
		["oclc"] = {},
		["pmid"] = {},
		["ssrn"] = {},
		["archiveurl"] = {},
		["archivedate"] = {},
		["page"] = list_with_holes,
		["column"] = {},
		["passage"] = {},
		["translation"] = {},
		["blockquote"] = {},
		["noblockquote"] = {}
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local authors = {}
	local authorlinks = {}
	local contributors = {}

	local authors_full, authorlinks, editors, translators, years, ids, pages =
		args.author, args.authorlinks, args.editor, args.translator, args.year, args.id, args.page

	local maxindex = math.max(args.last.maxindex, args.first.maxindex)
	
	for index = 1, maxindex do
		table.insert(authors, table.concat({args.last[index],args.first[index],args.author[index],args.authorlinks[index]}, ", "));
	end
	
	for k,v in pairs(authors_full) do authors[k] = v end
	
	if args.coauthors then
		table.insert(authors, args.coauthors)
	end
	
	local author, quotee, year, entry, chapter, contributor, title, series, language, version, volume, others, issue, edition, publisher, id, archive, section, page, passage = ""
	
	if next(authors) ~= nil then
		author = table.concat(authors, '</li><li>; </li></ul><ul class="cm-author"><li></li><li>')
		author = '<ul class="cm-authors"><li></li><li><ul class="cm-author"><li></li><li>' .. author .. '</li><li></li></ul></li><li>, </li></ul>'
	end
	
	if args.quotee then
		quotee = '<ul class="cm-quotee"><li>quoting </li><li>' .. args.quotee .. '</li><li>&nbsp;</li></ul>'
	end
	
	if next(years) ~= nil then
		year = table.concat(years, '</li><li>, </li></ul><ul class="cm-year"><li></li><li>')
		year = '<ul class="cm-years"><li>(</li><li><ul class="cm-year"><li></li><li>' .. year .. '</li><li></li></ul></li><li>), </li></ul>'
	end
	
	if args.entry and not args.chapter then
		entry = args.entry
		if args.url then
			entry = '[' .. args.url .. ' ' .. entry .. ']'
		end
		if args.transentry then
			entry = entry .. '<ul class="cm-transentry"><li> [</li><li>' .. args.transentry .. '</li><li>]</li></ul>'
		end
		entry = '<ul class="cm-entry"><li>"</li><li>' .. entry .. '</li><li>", in </li></ul>'
	end
	
	if args.chapter and not args.entry then
		chapter = '<ul class="cm-chapter"><li>chapter </li><li>' .. args.chapter .. '</li><li>, in </li></ul>'
	end
	
	if next(contributors) ~= nil or next(translators) ~= nil or next(editors) ~= nil then
		
		if next(translators) ~= nil then
			contributor = table.concat(translators, '</li><li>; </li></ul><ul class="cm-translator"><li></li><li>')
			contributor = '<ul class="cm-translators"><li></li><li><ul class="cm-translator"><li></li><li>' .. contributor .. '</li><li></li></ul></li><li>, transl., </li></ul>'
		end
		
		if next(editors) ~= nil then
			contributor = contributor .. table.concat(editors, '</li><li>; </li></ul><ul class="cm-editor"><li></li><li>')
			contributor = '<ul class="cm-editors"><li></li><li><ul class="cm-editor"><li></li><li>' .. contributor .. '</li><li></li></ul></li><li>, editor, </li></ul>'
		end
		
		if next(contributors) ~= nil then
			contributor = contributor .. table.concat(contributors, '</li><li>; </li></ul><ul class="cm-contributor"><li></li><li>')
			contributor = '<ul class="cm-contributors"><li></li><li><ul class="cm-contributor"><li></li><li>' ..contributor .. '</li><li></li></ul></li><li>, contributor, </li></ul>'
		end

		contributor = '<ul class="cm-contributors"><li></li><li>' .. contributor .. '</li><li></li></ul>'
	end
	
	if args.title then
		title = args.title
		if args.transtitle then
			title = title .. '<ul class="cm-transtitle"><li> [</li><li>' .. args.transtitle .. '</li><li>] </li></ul>'
		end
		title = '<ul class="cm-title"><li></li><li>' .. title .. '</li><li>&nbsp;</li></ul>'
	end
	
	if args.series then
		series = args.series
		if args.seriesvolume then
			series = series .. '<ul class="cm-seriesvolume"><li>; </li><li>' .. args.seriesvolume .. '</li><li></li></ul>'
		end
		series = '<ul class="cm-series"><li>(</li><li>' .. series .. '</li><li>), </li></ul>'
	end
	
	if args.lang then
		local m_languages = require("Module:languages/code to canonical name")
		language = m_languages[args.lang] or args.lang
		language = '<ul class="cm-lang"><li>(in </li><li>' .. language .. '</li><li>), </li></ul>'
	end
	
	if args.version then
		version = '<ul class="cm-version"><li>version </li><li>' .. args.version .. '</li><li>, </li></ul>'
	end
	
	if args.volume then
		volume = '<ul class="cm-volume"><li>volume </li><li>' .. args.volume .. '</li><li>, </li></ul>'
	end
	
	if args.others then
		others = '<ul class="cm-others"><li></li><li>' .. args.others .. '</li><li>, </li></ul>'
	end
	
	if args.issue then
		issue = '<ul class="cm-issue"><li>issue </li><li>' .. args.issue .. '</li><li>, </li></ul>'
	end
	
	if args.edition then
		edition = '<ul class="cm-edition"><li></li><li>' .. args.edition .. '</li><li> edition, </li></ul>'
	end
	
	if args.publisher then
		publisher = args.publisher
		if args.location then
			publisher = '<ul class="cm-location"><li></li><li>' .. args.location .. '</li><li>: </li></ul>' .. publisher
		end
		if args.yearpublished then
			publisher = publisher .. '<ul class="cm-yearpublished"><li>, published </li><li>' .. args.yearpublished .. '</li><li></li></ul>'
		end
		publisher = '<ul class="cm-publisher"><li></li><li>' .. publisher .. '</li><li>, </li></ul>'
	end
	
	if args.bibcode then
		table.insert(ids, '[[w:Bibcode|Bibcode]]: [http://adsabs.harvard.edu/abs/' ..  mw.uri.encode(args.bibcode, 'PATH') .. ' ' .. args.bibcode .. ']')
	end
	if args.doi then
		table.insert(ids, '[[w:Digital object identifier|DOI]]: <ul class="neverexpand">[https://doi.org/' .. mw.uri.encode(args.doi, 'PATH') .. ' ' .. args.doi .. ']</ul>')
	end
	if args.isbn then
		table.insert(ids, frame:expandTemplate{title = 'ISBN', args = { args.isbn }})
	end
	if args.issn then
		table.insert(ids, frame:expandTemplate{title = 'ISSN', args = { args.issn }})
	end
	if args.jstor then
		table.insert(ids, '[[w:JSTOR|JSTOR]] [http://www.jstor.org/stable/' .. mw.uri.encode(args.jstor, 'PATH') .. ' ' .. args.jstor .. ']')
	end
	if args.lccn then
		table.insert(ids, '[[w:Library of Congress Control Number|LCCN]] [http://lccn.loc.gov/' .. mw.uri.encode(args.lccn, 'PATH') .. ' ' .. args.lccn .. ']')
	end
	if args.oclc then
		table.insert(ids, '[[w:OCLC|OCLC]] [http://worldcat.org/oclc/' .. mw.uri.encode(args.oclc, 'PATH') .. ' ' .. args.oclc .. ']')
	end
	if args.pmid then
		table.insert(ids, '[[w:PubMed Identifier|PMID]] [http://www.ncbi.nlm.nih.gov/pubmed/' .. mw.uri.encode(args.pmid, 'PATH') .. ' ' .. args.pmid .. ']')
	end
	if args.ssrn then
		table.insert(ids, '[[w:Social Science Research Network|SSRN]] [http://ssrn.com/abstract=' .. mw.uri.encode(args.ssrn, 'PATH') .. ' ' .. args.ssrn .. ']')
	end
	
	if next(ids) ~= nil then
		id = '<ul class="cm-id"><li></li><li>' .. table.concat(ids, '<span>, </span>') .. '</li><li></li>, </ul>'
	end
	
	if args.archiveurl and args.archivedate then
		archive = '<ul class="cm-archiveurl"><li>archived from the </li><li>[' .. args.archiveurl .. ' original]</li><li></li></ul>'
		archive = archive .. '<ul class="cm-archivedate"><li> on </li><li>' .. args.archivedate .. '</li><li></li></ul>'
		archive = '<ul class="cm-archive"><li></li><li>' .. archive .. '</li><li>, </li></ul>'
	end
	
	if args.section then
		section = '<ul class="cm-section"><li>section </li><li>' .. args.section .. '</li><li>, </li></ul>'
	end
	
	if next(pages) ~= nil then
		page = table.concat(pages, ', ')
		if args.column then
			page = page .. '<ul class="cm-column"><li>, column </li><li>' .. args.column .. '</li><li></li></ul>'
		end
		page = '<ul class="cm-page"><li>pages </li><li>' .. page .. '</li><li></li></ul>'
	end
	
	if args.passage then
		passage = args.passage
		if args.translation then
			passage = passage .. '<ul class="cm-translation"><li> [</li><li>' .. args.translation .. '</li><li>]</li></ul>'
		end
		if (args.blockquote or (#args.passage > 300)) and not args.noblockquote then
			passage = '<ul class="cm-passage blockquote"><li>:</li><li>' .. passage .. '</li><li></li></ul>'
		else
			passage = '<ul class="cm-passage"><li>: “</li><li>' .. passage .. '</li><li>”</li></ul>'
		end
	end
	
	local class = "cite-meta inline"
	
	if next(authors) == nil then
		class = class .. " no-author"
	end
	
	return '<div class="' .. class .. '">' .. require("Module:table").sparseConcat({author, quotee, year, entry, chapter, contributor, title, series, language, version, volume, others, issue, edition, publisher, id, archive, section, page, passage}) .. '</div>'

end

return export