Module:Sandbox/1ctinus
Appearance
local p = {}
local plain = require('Module:Plain text')._main
local isInLead = require('Module:Is_infobox_in_lead')._main
local getArgs = require('Module:Arguments').getArgs
function p.shortdesc(text, frame)
return frame:expandTemplate{title = 'Short description', args = {text, 'noreplace'}}
end
function p.firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
function p.main(frame)
if(isInLead("[Ii]nfobox [Bb]ook")) then
local args = getArgs (frame, {parentOnly = true})
local short_description = plain(args.short_description)
local output = ""
local published = plain(args.pub_date or args.release_date or args.published)
if not(string.find(published, "–")) and string.len(published) < 40 then
if string.match(published, "%d%d%d%d") then
output = string.match(published, "%d%d%d%d") .. " "
end
end
local type = "literary work"
local specificfound = false
local genres = {"encyclopedia",
"memoir",
"anthology",
"autobiography",
"biography",
"collection of short stories",
"collection of poems",
"guide",
"short story",
"graphic novel",
"short-story",
"handbook",
"reference work",
"cookbook",
"textbook",
"essay",
"novella",
"novel",
"book"
}
local i = 1
if args.genre then
local given = string.lower(plain(args.genre))
while(i <= #genres and not(specificfound)) do
if string.find(given,genres[i],1, true) then
specificfound = true
type = genres[i]
end
i = i + 1
end
end
if not(specificfound) then
local content = mw.title.getCurrentTitle():getContent()
local start = string.find(content, "'''''"..mw.title.getCurrentTitle().text:gsub("%([^)]*%)", "").."'''''", 1 , true)
local fin = string.find(content, "==", 1, true)
if start and fin then
local lead = string.lower(mw.text.split(plain(string.sub(content, start, fin)), ".", true)[1])
output = "("..lead..")" .. output
i = 1
while(i <= #genres and not(specificfound)) do
if string.find(lead,genres[i],1, true) then
specificfound = true
type = genres[i]
end
i = i + 1
end
end
end
output = output .. type
local author = plain(args.author)
if author and string.len(author) < 40 then
output = output .. " by " .. author
end
return p.firstToUpper(output)
else
return "N/A"
end
end
return p