Module:Sandbox/Fred Gandt/sgd

local getArgs = require('Module:Arguments').getArgs local p = {}

-- Return a formatted description if we have one or nothing local function formattedDesc(desc) if desc then return ' (' .. mw.text.trim(desc) .. ') ' -- Not ideal if substituted end return '' end

-- Fetch the description list and return specified desc for genre local function getDescription(genre) -- local lc_genre = mw.ustring.lower(genre) -- possible case insensitive search? -- Fetch the description list and store it to dl	local dl = mw.title.new('User:Fred_Gandt/sandbox/Sgd/list'):getContent -- Look for a description in the list local desc = mw.ustring.match(dl, ';%s*' ..		string.gsub(genre, '[%^%$%(%)%.%[%]%*%+%-%?%%]', '%%%1') ..		'%s*:%s*([^;]+)') if desc then -- If found: format and return it		return formattedDesc(desc) end -- Or return an empty string return '' end

-- Main function function p._getOutput(cleanargs) -- Create local genre from clean args local genre = cleanargs.genre -- If a genre is suplied if genre then -- Create other local vars from clean args local nopipe = cleanargs.nopipe local description = cleanargs.description -- Start building genre_link local genre_link =  ..				string.gsub(string.gsub(string.gsub(genre,				' genre', ), ' music', ), ' %([%a%s]+%)', )		end		-- Finish the genre_link markup		genre_link = genre_link .. '' -- Return the formatted genre link with its description if there is one if description then -- If a description was provided in the invocation: use that return genre_link .. formattedDesc(description) end -- Or try to find and use one from the description list return genre_link .. getDescription(genre) end return ' ERROR: No genre specified ' end

-- Invoked function function p.get(frame) -- Pass clean args to _getOutput and return the results local args = getArgs(frame) return p._getOutput(args) end

return p