Content added Content deleted
mNo edit summary |
(move header to own function) |
||
Line 3: | Line 3: | ||
local p = {} |
local p = {} |
||
local function makeHeader(video_type) |
|||
local header = mw.html.create('div') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return header |
|||
end |
|||
local function makeVideo(frame, link) |
local function makeVideo(frame, link) |
||
local video = mw.html.create('div') |
local video = mw.html.create('div') |
||
:css({ |
:css({ |
||
Line 104: | Line 119: | ||
}) |
}) |
||
local header = |
local header = makeHeader(video_type) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local body = root:tag('div') |
local body = root:tag('div') |
||
Line 122: | Line 128: | ||
['gap'] = '5px' |
['gap'] = '5px' |
||
}) |
}) |
||
⚫ | |||
:done() |
|||
⚫ | |||
⚫ | |||
:done() |
|||
⚫ | |||
⚫ | |||
body:node(info) |
|||
return tostring(root) |
return tostring(root) |
Revision as of 04:55, 30 October 2021
Documentation for this module may be created at Module:Song video/doc
local getArgs = require('Module:Arguments').getArgs
local utils = require('Module:Utilities')
local p = {}
local function makeHeader(video_type)
local header = mw.html.create('div')
:css({
['border-radius'] = '6px',
['background-color'] = '#FFA900',
['font-weight'] = 'bold',
['text-align'] = 'center',
['margin-bottom'] = '5px',
['padding'] = '5px'
})
:wikitext('Hard Preview')
:done()
return header
end
local function makeVideo(frame, link)
local video = mw.html.create('div')
:css({
['flex'] = '1 1 320px',
['text-align'] = 'center',
['min-width'] = '320px',
['height'] = '180px'
})
if link then
local is_yt = string.find(link, '^' .. ('[a-zA-Z0-9_-]'):rep(11) .. '$') ~= nil
local is_file = string.find(link, '.+\.mp4') ~= nil
if is_yt then
video:wikitext(frame:extensionTag{
name = 'youtube',
args = { width = "320", height= "180" },
content = link
})
elseif is_file then
video:wikitext('[[File:' .. link .. '|320px]]')
else
video:wikitext(utils.editIfNil(nil))
end
else
video:wikitext(utils.editIfNil(nil))
end
return video
end
local function makeInfo(release_date, illustrator, animator)
local infoHeaderCss = {
['border-radius'] = '6px',
['background-color'] = '#a7ee75',
['padding'] = '5px 10px'
}
local infoCellCss = {
['padding'] = '5px'
}
local info = mw.html.create('div')
:css({
['display'] = 'grid',
['grid-template-columns'] = '1fr 1fr',
['grid-auto-rows'] = 'min-content',
['gap'] = '5px'
})
info:tag('div')
:css(infoHeaderCss)
:wikitext('Release Date')
:done()
:tag('div')
:css(infoCellCss)
:wikitext(utils.editIfNil(release_date))
:done()
if illustrator and illustrator ~= '' then
info:tag('div')
:css(infoHeaderCss)
:wikitext('Illustrator')
:done()
:tag('div')
:css(infoCellCss)
:wikitext(illustrator)
:done()
end
if animator and animator ~= '' then
info:tag('div')
:css(infoHeaderCss)
:wikitext('Movie')
:done()
:tag('div')
:css(infoCellCss)
:wikitext('Lye')
:done()
end
return info
end
function p.main(frame)
local args = getArgs(frame)
local video_type = args['type']
local link = args['link']
local release_date = args['date']
local illustrator = args['illustrator']
local animator = args['animator']
local root = mw.html.create('div')
:css({
['display'] = 'inline-grid',
['margin-right'] = '10px',
['margin-bottom'] = '10px'
})
local header = makeHeader(video_type)
root:node(header)
local body = root:tag('div')
:css({
['display'] = 'flex',
['flex-wrap'] = 'wrap',
['gap'] = '5px'
})
:node(makeVideo(frame, link))
:done()
:node(makeInfo(release_date, illustrator, animator))
:done()
return tostring(root)
end
return p