Module:Type in location: Difference between revisions

m 1 revision imported: Template for journal
imported>Izno
fix per VPT
 
Line 1: Line 1:
local p = {}
local p = {}
local plaintext = require("Module:Plain text")._main
local plaintext = require("Module:Plain text")._main
local language = mw.language.getContentLanguage()


--Cleanup/format location for use in short descriptions
--Cleanup/format location for use in short descriptions
Line 29: Line 30:
function p._generalLoc (loc)
function p._generalLoc (loc)
loc = p._prepareLoc(loc)
loc = p._prepareLoc(loc)
split = {}
local split = {}
num = 0
local num = 0
loc = loc..',' --comma at the end for convenient splitting with gmatch
loc = loc..',' --comma at the end for convenient splitting with gmatch
for k in loc:gmatch('([^,]*),') do --split by commas
for k in loc:gmatch('([^,]*),') do --split by commas
Line 45: Line 46:
--validate type parameter
--validate type parameter
function p.validateTyp (typ, args)
function p.validateTyp (typ, args)
checkpatterns = args['check-patterns']
local checkpatterns = args['check-patterns']
invalidadd = args.invalidadd
local invalidadd = args.invalidadd
if checkpatterns then
if checkpatterns then
for k in (checkpatterns..';'):gmatch('([^;]*);') do --split checkpatterns by ;, check if one of the patterns is in type
for k in (checkpatterns..';'):gmatch('([^;]*);') do --split checkpatterns by ;, check if one of the patterns is in type
Line 61: Line 62:
--generates type in location
--generates type in location
function p.main(frame)
function p.main(frame)
args = require('Module:Arguments').getArgs (frame, {frameOnly = true})
local args = require('Module:Arguments').getArgs (frame, {frameOnly = true})
return p._main(args, frame)
return p._main(args, frame)
end
--Display short description using {{short description}}
function p.shortdesc(text, frame)
return frame:expandTemplate{title = 'Short description', args = {text, 'noreplace'}}
end
end


function p._main (args, frame)
function p._main (args, frame)
cleanupLoc = require('Module:Settlement short description').cleanupLoc
local cleanupLoc = require('Module:Settlement short description').cleanupLoc
typ = args[1]
local typ = args[1]
if typ then typ = plaintext(args[1]) end
if typ then typ = plaintext(args[1]) end
if not typ then return end --check after plaintexting if typ exists
if not typ then return end --check after plaintexting if typ exists
sep = ((args.sep == 'no') and '') or args.sep or ' in ' --if args.sep set to no, nothing between typ and loc, if it has other value put that
local sep = ((args.sep == 'no') and '') or args.sep or ' in ' --if args.sep set to no, nothing between typ and loc, if it has other value put that
local loc = args[2]
local loc = args[2]
local func
if args['full-loc'] then func = '_prepareLoc' else func =  '_generalLoc' end
if args['full-loc'] then func = '_prepareLoc' else func =  '_generalLoc' end
if loc then
if loc then
Line 81: Line 88:
end
end
typ = p.validateTyp (typ, args)
typ = p.validateTyp (typ, args)
if typ then return frame:expandTemplate {title = 'Short description', args = {typ..loc, 'noreplace'}} end
if typ then return p.shortdesc(language:ucfirst(typ..loc), frame) end
end
end


return p
return p