Module:Mapframe: Difference between revisions
Jump to navigation
Jump to search
>Evad37 (start) |
>Evad37 (+) |
||
Line 20: | Line 20: | ||
local tag --todo | local tag --todo | ||
return tag | return tag | ||
end | |||
function makeContent(args) | |||
local content = {}; | |||
local contentIndex = ''; | |||
while Args['type'..contentIndex] do | |||
local contentArgs = {} | |||
contentArgs['type'] = Args['type'..contentIndex] | |||
--todo: Add other relevant args | |||
content[contentIndex or 1] = makeContentJson(contentArgs) | |||
contentIndex = (contentIndex or 1) + 1 | |||
end | |||
--Single item, no array needed | |||
if #content==1 then | |||
return content[0] | |||
end | |||
--Multiple items get placed in an array | |||
local contentArray = '[\n' + table.concat( content, ',\n') + '\n]' | |||
return contentArray | |||
end | end | ||
Line 34: | Line 57: | ||
return mw.text.jsonEncode(data) | return mw.text.jsonEncode(data) | ||
end | end | ||
local p = {} | local p = {} | ||
Line 41: | Line 65: | ||
Args = setCleanArgs(parent.args) | Args = setCleanArgs(parent.args) | ||
local | local tagContent = makeContent(Args) | ||
-- todo: make tag(s) | |||
-- todo | |||
local output = '' | local output = '' | ||
return output | return output | ||
end | end | ||
return p | return p | ||
Revision as of 21:30, 1 May 2018
Documentation for this module may be created at Module:Mapframe/doc
--Parameter for cleaned-up parent.args (whitespace trimmed, blanks removed) local Args = {} function setCleanArgs(argsTable) local cleanArgs = {} for key, val in pairs(argsTable) do if type(val) == 'string' then val = val:match('^%s*(.-)%s*$') if val ~= '' then cleanArgs[key] = val end else cleanArgs[key] = val end end return cleanArgs end function makeTag(name, attributes, content) local tag --todo return tag end function makeContent(args) local content = {}; local contentIndex = ''; while Args['type'..contentIndex] do local contentArgs = {} contentArgs['type'] = Args['type'..contentIndex] --todo: Add other relevant args content[contentIndex or 1] = makeContentJson(contentArgs) contentIndex = (contentIndex or 1) + 1 end --Single item, no array needed if #content==1 then return content[0] end --Multiple items get placed in an array local contentArray = '[\n' + table.concat( content, ',\n') + '\n]' return contentArray end function makeContentJson(contentArgs) local data = {} if contentArgs.type == 'point' then data.type = "Feature" else data.type = "ExternalData" end --todo: fill out rest of data return mw.text.jsonEncode(data) end local p = {} function p.main(frame) local parent = frame.getParent(frame) Args = setCleanArgs(parent.args) local tagContent = makeContent(Args) -- todo: make tag(s) -- todo local output = '' return output end return p