Content added Content deleted
mNo edit summary |
m (Undo revision 36344 by ChaoticShadow (talk)) Tag: Undo |
||
(30 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local cicon = require('Module:Character icon')._main |
||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
local p = {} |
local p = {} |
||
function |
local function formatCharacters(characters) |
||
local |
local characterArr = utils.splitWithDelim(',')(characters) |
||
local charArr = utils.splitWithDelim(';')(characters) |
|||
local |
local resArr = {} |
||
for _,v in ipairs(characterArr) do |
|||
local box_css = { |
|||
table.insert(resArr, cicon({ v, size = '40px' })) |
|||
['color'] = '#424362', |
|||
end |
|||
['margin'] = '20px 3px 20px 0', |
|||
for _,v in ipairs(charArr) do |
|||
['border'] = '2px solid #00cdba', |
|||
table.insert(resArr, cicon({ v, size = '40px' })) |
|||
['border-radius'] = '10px', |
|||
end |
|||
['box-shadow'] = '2px 3px #00cdba', |
|||
['padding'] = '20px' |
|||
} |
|||
return table.concat(resArr, " ") |
|||
local image = '' |
|||
end |
|||
local function formatList(str) |
|||
local list = utils.splitWithDelim(',')(str) |
|||
return table.concat(list, '<br>') |
|||
local top = root:tag('div') |
|||
end |
|||
:css(box_css) |
|||
:css({ |
|||
local function makeStoryInfo(image, title, characters) |
|||
['display'] = 'flex', |
|||
local root = mw.html.create('div') |
|||
['flex-wrap'] = 'wrap', |
|||
:addClass('story-info') |
|||
['gap'] = '20px', |
|||
['justify-content'] = 'center' |
|||
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') |
:tag('div') |
||
:addClass('characters') |
|||
:css({ |
|||
:wikitext(string.format( |
|||
['align-self'] = 'center', |
|||
"'''Character appearances:'''<br/> %s", |
|||
['width'] = '280px' |
|||
utils.editIfNil(characters, formatCharacters) |
|||
}) |
|||
:wikitext(utils.editIfNil( |
|||
args['image'], |
|||
function (img) |
|||
return string.format( |
|||
'[[File:%s|280px|center]]', |
|||
img |
|||
) |
|||
end |
|||
)) |
)) |
||
:done() |
: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') |
:tag('div') |
||
:css( |
:css('text-align', 'right') |
||
:wikitext("'''Translator(s):'''") |
|||
['flex-grow'] = 1, |
|||
:done() |
|||
['text-align'] = 'center', |
|||
:tag('div') |
|||
:wikitext(utils.editIfNil(translators, formatList)) |
|||
:tag('div') |
|||
:done() |
|||
:tag('div') |
|||
['border-bottom'] = '1px solid #00cdba', |
|||
:css('text-align', 'right') |
|||
['border-top-right-radius'] = '6px', |
|||
:wikitext("'''Source(s):'''") |
|||
['color'] = '#424362', |
|||
:done() |
|||
['padding-bottom'] = '10px' |
|||
:tag('div') |
|||
:wikitext(utils.editIfNil(sources, formatList)) |
|||
"'''%s:'''<br />'''%s'''<br />'''%s'''", |
|||
utils.editIfNil(args['chapter']), |
|||
utils.editIfNil(args['english']), |
|||
utils.editIfNil(args['japanese']) |
|||
)) |
|||
:done() |
|||
:tag('div') |
|||
:css({ |
|||
['color'] = '#424362', |
|||
['line-height'] = '2', |
|||
['padding-top'] = '10px' |
|||
}) |
|||
:wikitext("'''Characters that appear:'''<br/> {{{Charas}}}") |
|||
:done() |
|||
:done() |
:done() |
||
:done() |
:done() |
||
return root |
|||
local bottom = root:tag('div') |
|||
end |
|||
:css(box_css) |
|||
:css({ |
|||
function p.main(frame) |
|||
['display'] = 'grid', |
|||
local args = getArgs(frame) |
|||
['grid-template-columns'] = 'repeat(2, 1fr)', |
|||
return p._main(args) |
|||
['gap'] = '10px' |
|||
end |
|||
}) |
|||
:tag('div'):css('text-align', 'right'):wikitext("'''Translator(s):'''"):done() |
|||
function p._main(args) |
|||
:tag('div'):wikitext(args['translator']):done() |
|||
local image = args['image'] |
|||
:tag('div'):css('text-align', 'right'):wikitext("'''Source(s):'''"):done() |
|||
local characters = args['character'] or args['characters'] |
|||
:tag('div'):wikitext(args['source']):done() |
|||
:done() |
|||
local title = args['title'] |
|||
if args['title'] == nil then |
|||
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 |
|||
end |
|||
local translators = args['translator'] or args['translators'] |
|||
local sources = args['source'] or args['sources'] |
|||
local root = mw.html.create('div') |
|||
:addClass('story-info-wrapper') |
|||
root |
|||
:node(makeStoryInfo(image, title, characters)) |
|||
:node(makeTranslationInfo(translators, sources)) |
|||
return |
return |
||
mw.getCurrentFrame():extensionTag{ |
|||
name = 'templatestyles', |
|||
args = { src = 'Template:Story info/styles.css' } |
|||
} .. tostring(root) |
|||
end |
end |
||
Latest revision as of 08:17, 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 formatList(str)
local list = utils.splitWithDelim(',')(str)
return table.concat(list, '<br>')
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, formatList))
:done()
:tag('div')
:css('text-align', 'right')
:wikitext("'''Source(s):'''")
:done()
:tag('div')
:wikitext(utils.editIfNil(sources, formatList))
:done()
:done()
return root
end
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local image = args['image']
local characters = args['character'] or args['characters']
local title = args['title']
if args['title'] == nil then
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
end
local translators = args['translator'] or args['translators']
local sources = args['source'] or args['sources']
local root = mw.html.create('div')
:addClass('story-info-wrapper')
root
:node(makeStoryInfo(image, title, characters))
:node(makeTranslationInfo(translators, sources))
return
mw.getCurrentFrame():extensionTag{
name = 'templatestyles',
args = { src = 'Template:Story info/styles.css' }
} .. tostring(root)
end
return p