Module:Type in location: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
new module
 
fix
Line 19: Line 19:
loc = p.Format(loc)
loc = p.Format(loc)
loc = loc..','
loc = loc..','
for k in loc:gmatch('([^,]-),') do --split by commmas
for k in loc:gmatch('([^,]*),') do --split by commmas
split.insert(k)
table.insert(split, k)
num = num + 1
num = num + 1
end
end
if num == 1 then --if only comma was the one at the end return the whole thing
if num == 1 then --if only comma was the one at the end return the whole thing
return loc[1]
return split[1]
else
else
return loc[num-1]..','..loc[num] --return last two entries seperated by commas
return split[num-1]..','..split[num] --return last two entries seperated by commas
end
end
end
end

Revision as of 12:57, 18 May 2018

local p = {}
local plaintext = require("Module:Plain text")._main

--Format location for use in short descriptions
function p.Format (text)
	text = text:gsub('<br/?>', ', ') --<br> or <br/> with commas
	text = plaintext(text) --plain textify to reduce strange stuff
	return text
end

--Gets general location from more specific one for short descriptions
--i.e if a location is specified to be "P. Sherman 42 Wallaby Way Sydney, Australia", return "Sydney, Australia"
--splits by commas and returns last two entries

function p.General (frame)
	loc = frame.args[1]
	split = {}
	num = 0
	loc = p.Format(loc)
	loc = loc..','
	for k in loc:gmatch('([^,]*),') do --split by commmas
		table.insert(split, k)
		num = num + 1
	end
	if num == 1 then --if only comma was the one at the end return the whole thing
		return split[1]
	else
		return split[num-1]..','..split[num] --return last two entries seperated by commas
	end
end

return p