Module:Formatted appearance: Difference between revisions

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..."
 
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('Module:List')
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 -- Check if the counter stayed the same.
if (counter == 1) then -- Check if the counter stayed the same.
return "" -- Nothing was added to array; Return empty string.
return "" -- Nothing was added to array; Return empty string.
elseif (counter == 2) then -- Check if only one value was added to the array.
elseif (counter == 2) then -- Check if only one value was added to the array.
return args[1] -- Only one value was added to array; Return that value.
return args[1] -- Only one value was added to array; Return that value.
else -- The array had more than one value added.
else -- The array had more than one value added.
return list.makeList("unbulleted", args) -- Call list.makeList() to retrieve the formatted plainlist.
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 = {} -- Variable to save the array.
local fullString = {} -- Variable to save the array.
local counter = 1 -- Variable to save the array counter.
local counter = 1 -- Variable to save the array counter.
if (appearanceMajor ~= nil) then -- Check if a comic book title was entered.
if (appearanceMajor ~= nil) then -- Check if a comic book title was entered.


if (appearanceMinor == nil) then -- A comic book title was entered; Check if a issue number was entered.
if (appearanceMinor == nil) then -- A comic book title was entered; Check if a issue number was entered.
fullString[counter] = appearanceMajor -- A issue was not entered; Add only the comic book title to the array.
fullString[counter] = appearanceMajor -- A issue was not entered; Add only the comic book title to the array.
counter = counter + 1 -- Increment counter by one.
counter = counter + 1 -- Increment counter by one.
else  
else  
fullString[counter] = appearanceMajor .. " " .. appearanceMinor -- A issue was entered; Add both to the array.
fullString[counter] = appearanceMajor .. " " .. appearanceMinor -- A issue was entered; Add both to the array.
counter = counter + 1 -- Increment counter by one.
counter = counter + 1 -- Increment counter by one.
end
end
end
end
if (appearanceDate ~= nil) then -- Check if a release date was entered.
if (appearanceDate ~= nil) then -- Check if a release date was entered.
fullString[counter] = appearanceDate -- A release date was entered; Add it to the array.
fullString[counter] = appearanceDate -- A release date was entered; Add it to the array.
counter = counter + 1 -- Increment counter by one.
counter = counter + 1 -- Increment counter by one.
end
end


return getFormattedEntry(fullString, counter) -- Call getFormattedEntry() to get a correctly formatted entry.
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 = {} -- Variable to save the array.
local fullString = {} -- Variable to save the array.
local counter = 1 -- Variable to save the array counter.
local counter = 1 -- Variable to save the array counter.
if (appearanceMinor ~= nil) then -- Check if a minor appearance was entered.
if (appearanceMinor ~= nil) then -- Check if a minor appearance was entered.
fullString[counter] = appearanceMinor -- A minor appearance was entered; Add it to the array.
fullString[counter] = appearanceMinor -- A minor appearance was entered; Add it to the array.
counter = counter + 1 -- Increment counter by one.
counter = counter + 1 -- Increment counter by one.
end
end
if (appearanceMajor ~= nil) then -- Check if a major appearance was entered.
if (appearanceMajor ~= nil) then -- Check if a major appearance was entered.
fullString[counter] = appearanceMajor -- A major appearance was entered; Add it to the array.
fullString[counter] = appearanceMajor -- A major appearance was entered; Add it to the array.
counter = counter + 1 -- Increment counter by one.
counter = counter + 1 -- Increment counter by one.
end
end
if (appearanceDate ~= nil) then -- Check if a release date was entered.
if (appearanceDate ~= nil) then -- Check if a release date was entered.
fullString[counter] = appearanceDate -- A release date was entered; Add it to the array.
fullString[counter] = appearanceDate -- A release date was entered; Add it to the array.
counter = counter + 1 -- Increment counter by one.
counter = counter + 1 -- Increment counter by one.
end
end


return getFormattedEntry(fullString, counter) -- Call getFormattedEntry() to get a correctly formatted entry.
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 -- Check if the issue is not nil.
if (issue ~= nil) then -- Check if the issue is not nil.
if (string.find(issue, "#")) then -- Check if the issue already has a hash symbol.
if (string.find(issue, "#")) then -- Check if the issue already has a hash symbol.
return issue -- Hash symbol already present; Return issue.
return issue -- Hash symbol already present; Return issue.
else
else
local formattedString = string.gsub(issue, "%d+", "#%1") -- Hash symbol not found; Add the symbol before the issue number.
local formattedString = string.gsub(issue, "%d+", "#%1") -- Hash symbol not found; Add the symbol before the issue number.
return formattedString -- Return issue.
return formattedString -- Return issue.
end
end
else
else
return nil -- issue is nil; 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 -- Check if the title is not nil.
if (title ~= nil) then -- Check if the title is not nil.
return "\"" .. title .. "\"" -- Title is not nil; Add quotes to the title.
return "\"" .. title .. "\"" -- Title is not nil; Add quotes to the title.
else
else
return nil -- Title is nil; 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 -- Check if the title is not nil.
if (title ~= nil) then -- Check if the title is not nil.
return "''" .. title .. "''" -- Title is not nil; Add italics to the title.
return "''" .. title .. "''" -- Title is not nil; Add italics to the title.
else
else
return nil -- Title is nil; 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['major_work'] -- Get the title of the major work.
local appearanceMajor = args.major_work -- Get the title of the major work.
local appearanceMinor = args['minor_work'] -- Get the title of the minor work.
local appearanceMinor = args.minor_work -- Get the title of the minor work.
local isComic = false -- Variable to save the status of wether the appearence is from a comic book.
local isComic = false -- Variable to save the status of wether the appearence is from a comic book.
if (args['issue'] ~= nil) then -- Check if the comic specific issue is not nil.
if (args.issue ~= nil) then -- Check if the comic specific issue is not nil.
appearanceMinor = args['issue'] -- Issue is not nil; Get the issue number.
appearanceMinor = args.issue -- Issue is not nil; Get the issue number.
isComic = true -- Set isComic to true.
isComic = true -- Set isComic to true.
end
end
local appearanceDate = args['date'] -- Get the release date of the minor work.
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('Module:Arguments').getArgs -- Use Module:Arguments to access module arguments.
local getArgs = require("Module:Arguments").getArgs -- Use Module:Arguments to access module arguments.
local args = getArgs(frame) -- Get the arguments sent via the template.
local args = getArgs(frame) -- Get the arguments sent via the template.


return _getFormattedAppearance(args) -- Call _getFormattedAppearance() to perform the actual process.
return _getFormattedAppearance(args) -- Call _getFormattedAppearance() to perform the actual process.
end
end


return p
return p