Module:Story info: Difference between revisions

From Sekaipedia
Content added Content deleted
(separate blocks into functions)
(test using functions)
Line 85: Line 85:
local args = getArgs(frame)
local args = getArgs(frame)
local root = mw.html.create('div')
local image = args['image']
local characters = args['character'] or args['characters']
:addClass('story-chapter')
local image = ''
local title = string.format(
local title = string.format(
Line 104: Line 102:
end
end
local translators = args['translator'] or args['translators']
local top = root:tag('div')
local sources = args['source'] or args['sources']
:addClass('chapter-info')

:tag('div')
local root = mw.html.create('div')
:css({
:addClass('story-chapter')
['align-self'] = 'center',
['width'] = '280px',
root
['text-align'] = 'center'
:node(makeStoryInfo(image, title, characters))
})
:node(makeTranslationInfo(translators, sources))
:wikitext(utils.editIfNil(
args['image'],
-- local top = root:tag('div')
function (img)
-- :addClass('chapter-info')
return string.format(
-- :tag('div')
'[[File:%s|280px|center]]',
-- :css({
img
-- ['align-self'] = 'center',
)
-- ['width'] = '280px',
end
-- ['text-align'] = 'center'
))
:done()
-- })
-- :wikitext(utils.editIfNil(
:tag('div')
-- args['image'],
:css({
-- function (img)
['flex-grow'] = 1,
-- return string.format(
['text-align'] = 'center',
-- '[[File:%s|280px|center]]',
})
-- img
:tag('div')
:css({
-- )
-- end
['border-bottom'] = '1px solid #00cdba',
-- ))
['border-top-right-radius'] = '6px',
-- :done()
['padding-bottom'] = '10px'
-- :tag('div')
})
-- :css({
:wikitext(title)
-- ['flex-grow'] = 1,
:done()
-- ['text-align'] = 'center',
:tag('div')
-- })
:css({
-- :tag('div')
['line-height'] = '2',
-- :css({
['padding-top'] = '10px'
-- ['border-bottom'] = '1px solid #00cdba',
})
-- ['border-top-right-radius'] = '6px',
:wikitext(
-- ['padding-bottom'] = '10px'
string.format(
-- })
"'''Character appearances:'''<br/> %s",
-- :wikitext(title)
utils.editIfNil(
-- :done()
args['characters'],
-- :tag('div')
formatCharacters
)
-- :css({
-- ['line-height'] = '2',
)
-- ['padding-top'] = '10px'
)
:done()
-- })
:done()
-- :wikitext(
-- string.format(
:done()
-- "'''Character appearances:'''<br/> %s",
-- utils.editIfNil(
-- args['characters'],
-- formatCharacters
-- )
-- )
-- )
-- :done()
-- :done()
-- :done()
local bottom = root:tag('div')
-- local bottom = root:tag('div')
:addClass('translation-info')
-- :addClass('translation-info')
:tag('div')
-- :tag('div')
:css('text-align', 'right')
-- :css('text-align', 'right')
:wikitext("'''Translator(s):'''")
-- :wikitext("'''Translator(s):'''")
:done()
-- :done()
:tag('div')
-- :tag('div')
:wikitext(utils.editIfNil(args['translator']))
-- :wikitext(utils.editIfNil(args['translator']))
:done()
-- :done()
:tag('div')
-- :tag('div')
:css('text-align', 'right')
-- :css('text-align', 'right')
:wikitext("'''Source(s):'''")
-- :wikitext("'''Source(s):'''")
:done()
-- :done()
:tag('div')
-- :tag('div')
:wikitext(utils.editIfNil(args['source']))
-- :wikitext(utils.editIfNil(args['source']))
:done()
-- :done()
:done()
-- :done()


return
return

Revision as of 04:50, 16 April 2022

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

local getArgs   = require('Module:Arguments').getArgs
local cicon     = require('Module:Character icon')._main
local utils     = require('Module:Utilities')

local p = {}

local function formatCharacters(characters)
	local characterArr = utils.splitWithDelim(',')(characters)
	local charArr = utils.splitWithDelim(';')(characters)
	
	local resArr = {}
	for _,v in ipairs(characterArr) do
		table.insert(resArr, cicon({ v, size = '40px' }))
	end
	for _,v in ipairs(charArr) do
		table.insert(resArr, cicon({ v, size = '40px' }))
	end
	
	return table.concat(resArr, " ")
end

local function makeStoryInfo(image, title, characters)
	local root = mw.html.create('div')
		:addClass('story-info')
		
	local image = mw.html.create('div')
		:addClass('image')
		:wikitext(utils.editIfNil(
			image,
			function (image)
				return string.format(
					'[[File:%s|280px|center]]',
					image
				)
			end
		))
		:done()
			
	local info = mw.html.create('div')
		:addClass('info')
		:tag('div')
			:addClass('title')
			:wikitext(title)
			:done()
		:tag('div')
			:addClass('characters')
			:wikitext(string.format(
				"'''Character appearances:'''<br/> %s",
				utils.editIfNil(characters, formatCharacters)
			))
			:done()
		:done()
		
	root
		:node(image)
		:node(info)
		
	return root
end

local function makeTranslationInfo(translators, sources)
	local root = mw.html.create('div')
		:addClass('translation-info')
		:tag('div')
			:css('text-align', 'right')
			:wikitext("'''Translator(s):'''")
			:done()
		:tag('div')
			:wikitext(utils.editIfNil(translators))
			:done()
		:tag('div')
			:css('text-align', 'right')
			:wikitext("'''Source(s):'''")
			:done()
		:tag('div')
			:wikitext(utils.editIfNil(sources))
			:done()
		:done()
		
	return root
end


function p.main(frame)
	local args = getArgs(frame)
	
	local image = args['image']
	local characters = args['character'] or args['characters']
	
	local title = string.format(
		"'''%s: %s'''",
		utils.editIfNil(args['chapter']),
		utils.editIfNil(args['english'])
	)
	
	if args['japanese'] or args['romaji'] then
		title = title .. string.format(
			"<br>'''%s (%s)'''",
			utils.editIfNil(args['japanese']),
			utils.editIfNil(args['romaji'])
		)
	end
	
	local translators = args['translator'] or args['translators']
	local sources = args['source'] or args['sources']

	local root = mw.html.create('div')
		:addClass('story-chapter')
	
	root
		:node(makeStoryInfo(image, title, characters))
		:node(makeTranslationInfo(translators, sources))
	
	-- local top = root:tag('div')
	-- 	:addClass('chapter-info')
	-- 	:tag('div')
	-- 		:css({
	-- 			['align-self'] = 'center',
	-- 			['width'] = '280px',
	-- 			['text-align'] = 'center'
	-- 		})
	-- 		:wikitext(utils.editIfNil(
	-- 			args['image'],
	-- 			function (img)
	-- 				return string.format(
	-- 					'[[File:%s|280px|center]]',
	-- 					img
	-- 				)
	-- 			end
	-- 		))
	-- 		:done()
	-- 	:tag('div')
	-- 		:css({
	-- 			['flex-grow'] = 1,
	-- 			['text-align'] = 'center',
	-- 		})
	-- 		:tag('div')
	-- 			:css({
	-- 				['border-bottom'] = '1px solid #00cdba',
	-- 				['border-top-right-radius'] = '6px',
	-- 				['padding-bottom'] = '10px'
	-- 			})
	-- 			:wikitext(title)
	-- 			:done()
	-- 		:tag('div')
	-- 			:css({
	-- 				['line-height'] = '2',
	-- 				['padding-top'] = '10px'
	-- 			})
	-- 			:wikitext(
	-- 				string.format(
	-- 					"'''Character appearances:'''<br/> %s",
	-- 					utils.editIfNil(
	-- 						args['characters'],
	-- 						formatCharacters
	-- 					)
	-- 				)
	-- 			)
	-- 			:done()
	-- 		:done()
	-- 	:done()
			
	-- local bottom = root:tag('div')
	-- 	:addClass('translation-info')
	-- 	:tag('div')
	-- 		:css('text-align', 'right')
	-- 		:wikitext("'''Translator(s):'''")
	-- 		:done()
	-- 	:tag('div')
	-- 		:wikitext(utils.editIfNil(args['translator']))
	-- 		:done()
	-- 	:tag('div')
	-- 		:css('text-align', 'right')
	-- 		:wikitext("'''Source(s):'''")
	-- 		:done()
	-- 	:tag('div')
	-- 		:wikitext(utils.editIfNil(args['source']))
	-- 		:done()
	-- 	:done()

	return 
		mw.getCurrentFrame():extensionTag{
			name = 'templatestyles',
			args = { src = 'Template:Story info/styles.css' }
		} .. tostring(root)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.