Module:Formatted appearance: Difference between revisions
NeonWabbit (talk | contribs) Created page with "-- This module requires the use of Module:List. local list = require('Module:List') local p = {} -- Local function which is used to get a correctly formatted entry. -- Function checks if the array had a value added by checking the counter, -- and returns the relevant result. local function getFormattedEntry(args, counter) if (counter == 1) then -- Check if the counter stayed the same. return "" -- Nothing was added to array; R..." |
NeonWabbit (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
require("strict") | |||
-- This module requires the use of Module:List. | -- This module requires the use of Module:List. | ||
local list = require( | local list = require("Module:List") | ||
local p = {} | local p = {} | ||
| Line 8: | Line 10: | ||
-- and returns the relevant result. | -- and returns the relevant result. | ||
local function getFormattedEntry(args, counter) | local function getFormattedEntry(args, counter) | ||
if (counter == 1) then | if (counter == 1) then -- Check if the counter stayed the same. | ||
return "" | return "" -- Nothing was added to array; Return empty string. | ||
elseif (counter == 2) then | elseif (counter == 2) then -- Check if only one value was added to the array. | ||
return args[1] | return args[1] -- Only one value was added to array; Return that value. | ||
else | else -- The array had more than one value added. | ||
return list.makeList("unbulleted", args) | return list.makeList("unbulleted", args) -- Call list.makeList() to retrieve the formatted plainlist. | ||
end | end | ||
end | end | ||
| Line 34: | Line 36: | ||
--]] | --]] | ||
local function createComicEntry(appearanceMajor, appearanceMinor, appearanceDate) | local function createComicEntry(appearanceMajor, appearanceMinor, appearanceDate) | ||
local fullString = {} | local fullString = {} -- Variable to save the array. | ||
local counter = 1 | local counter = 1 -- Variable to save the array counter. | ||
if (appearanceMajor ~= nil) then | if (appearanceMajor ~= nil) then -- Check if a comic book title was entered. | ||
if (appearanceMinor == nil) then | if (appearanceMinor == nil) then -- A comic book title was entered; Check if a issue number was entered. | ||
fullString[counter] = appearanceMajor | fullString[counter] = appearanceMajor -- A issue was not entered; Add only the comic book title to the array. | ||
counter = counter + 1 | counter = counter + 1 -- Increment counter by one. | ||
else | else | ||
fullString[counter] = appearanceMajor .. " " .. appearanceMinor | fullString[counter] = appearanceMajor .. " " .. appearanceMinor -- A issue was entered; Add both to the array. | ||
counter = counter + 1 | counter = counter + 1 -- Increment counter by one. | ||
end | end | ||
end | end | ||
if (appearanceDate ~= nil) then | if (appearanceDate ~= nil) then -- Check if a release date was entered. | ||
fullString[counter] = appearanceDate | fullString[counter] = appearanceDate -- A release date was entered; Add it to the array. | ||
counter = counter + 1 | counter = counter + 1 -- Increment counter by one. | ||
end | end | ||
return getFormattedEntry(fullString, counter) | return getFormattedEntry(fullString, counter) -- Call getFormattedEntry() to get a correctly formatted entry. | ||
end | end | ||
| Line 77: | Line 79: | ||
--]] | --]] | ||
local function createGenericEntry(appearanceMajor, appearanceMinor, appearanceDate) | local function createGenericEntry(appearanceMajor, appearanceMinor, appearanceDate) | ||
local fullString = {} | local fullString = {} -- Variable to save the array. | ||
local counter = 1 | local counter = 1 -- Variable to save the array counter. | ||
if (appearanceMinor ~= nil) then | if (appearanceMinor ~= nil) then -- Check if a minor appearance was entered. | ||
fullString[counter] = appearanceMinor | fullString[counter] = appearanceMinor -- A minor appearance was entered; Add it to the array. | ||
counter = counter + 1 | counter = counter + 1 -- Increment counter by one. | ||
end | end | ||
if (appearanceMajor ~= nil) then | if (appearanceMajor ~= nil) then -- Check if a major appearance was entered. | ||
fullString[counter] = appearanceMajor | fullString[counter] = appearanceMajor -- A major appearance was entered; Add it to the array. | ||
counter = counter + 1 | counter = counter + 1 -- Increment counter by one. | ||
end | end | ||
if (appearanceDate ~= nil) then | if (appearanceDate ~= nil) then -- Check if a release date was entered. | ||
fullString[counter] = appearanceDate | fullString[counter] = appearanceDate -- A release date was entered; Add it to the array. | ||
counter = counter + 1 | counter = counter + 1 -- Increment counter by one. | ||
end | end | ||
return getFormattedEntry(fullString, counter) | return getFormattedEntry(fullString, counter) -- Call getFormattedEntry() to get a correctly formatted entry. | ||
end | end | ||
| Line 101: | Line 103: | ||
-- For other minor works, see getFormattedGenericMinorWork(). | -- For other minor works, see getFormattedGenericMinorWork(). | ||
local function getFormattedComicMinorWorkTitle(issue) | local function getFormattedComicMinorWorkTitle(issue) | ||
if (issue ~= nil) then | if (issue ~= nil) then -- Check if the issue is not nil. | ||
if (string.find(issue, "#")) then | if (string.find(issue, "#")) then -- Check if the issue already has a hash symbol. | ||
return issue | return issue -- Hash symbol already present; Return issue. | ||
else | else | ||
local formattedString = string.gsub(issue, "%d+", "#%1") | local formattedString = string.gsub(issue, "%d+", "#%1") -- Hash symbol not found; Add the symbol before the issue number. | ||
return formattedString | return formattedString -- Return issue. | ||
end | end | ||
else | else | ||
return nil | return nil -- issue is nil; Return nil. | ||
end | end | ||
end | end | ||
| Line 116: | Line 118: | ||
-- For comic book issues, see getFormattedComicMinorWork() (see [MOS:MINORWORK]). | -- For comic book issues, see getFormattedComicMinorWork() (see [MOS:MINORWORK]). | ||
local function getFormattedGenericMinorWorkTitle(title) | local function getFormattedGenericMinorWorkTitle(title) | ||
if (title ~= nil) then | if (title ~= nil) then -- Check if the title is not nil. | ||
return "\"" .. title .. "\"" | return "\"" .. title .. "\"" -- Title is not nil; Add quotes to the title. | ||
else | else | ||
return nil | return nil -- Title is nil; Return nil. | ||
end | end | ||
end | end | ||
| Line 125: | Line 127: | ||
-- Local function which is used to format with italics a major work title (see [MOS:MAJORWORK]). | -- Local function which is used to format with italics a major work title (see [MOS:MAJORWORK]). | ||
local function getFormattedMajorWorkTitle(title) | local function getFormattedMajorWorkTitle(title) | ||
if (title ~= nil) then | if (title ~= nil) then -- Check if the title is not nil. | ||
return "''" .. title .. "''" | return "''" .. title .. "''" -- Title is not nil; Add italics to the title. | ||
else | else | ||
return nil | return nil -- Title is nil; Return nil. | ||
end | end | ||
end | end | ||
| Line 134: | Line 136: | ||
-- Local function which does the actual main process. | -- Local function which does the actual main process. | ||
local function _getFormattedAppearance(args) | local function _getFormattedAppearance(args) | ||
local appearanceMajor = args | local appearanceMajor = args.major_work -- Get the title of the major work. | ||
local appearanceMinor = args | local appearanceMinor = args.minor_work -- Get the title of the minor work. | ||
local isComic = false | local isComic = false -- Variable to save the status of wether the appearence is from a comic book. | ||
if (args | if (args.issue ~= nil) then -- Check if the comic specific issue is not nil. | ||
appearanceMinor = args | appearanceMinor = args.issue -- Issue is not nil; Get the issue number. | ||
isComic = true | isComic = true -- Set isComic to true. | ||
end | end | ||
local appearanceDate = args | local appearanceDate = args.date -- Get the release date of the minor work. | ||
local formattedAppearanceMajor = getFormattedMajorWorkTitle(appearanceMajor) -- Call getFormattedMajorWorkTitle() to get a formatted major work title. | local formattedAppearanceMajor = getFormattedMajorWorkTitle(appearanceMajor) -- Call getFormattedMajorWorkTitle() to get a formatted major work title. | ||
| Line 172: | Line 174: | ||
--]] | --]] | ||
function p.getFormattedAppearance(frame) | function p.getFormattedAppearance(frame) | ||
local getArgs = require( | local getArgs = require("Module:Arguments").getArgs -- Use Module:Arguments to access module arguments. | ||
local args = getArgs(frame) | local args = getArgs(frame) -- Get the arguments sent via the template. | ||
return _getFormattedAppearance(args) | return _getFormattedAppearance(args) -- Call _getFormattedAppearance() to perform the actual process. | ||
end | end | ||
return p | return p | ||