Difference between revisions of "Module:Sandbox/Evad37/X1"
Jump to navigation
Jump to search
blackwiki>Evad37 (.) |
blackwiki>Evad37 (put coords into mapframe map) |
||
| Line 1: | Line 1: | ||
-- This module is a sandbox. It is also used for testing XFDcloser | -- This module is a sandbox. It is also used for testing XFDcloser | ||
| + | local getArgs = require('Module:Arguments').getArgs | ||
| + | local transclude = require("Module:Transclude") | ||
| + | local mapframe = require("Module:Mapframe") | ||
local p = {} | local p = {} | ||
| Line 10: | Line 13: | ||
p.getCoords = function(frame) | p.getCoords = function(frame) | ||
| − | local | + | local args = getArgs(frame, {parentFirst = true}) |
| − | local title = mw.title.getCurrentTitle() | + | local title = args.article and mw.title.new(args.article) or mw.title.getCurrentTitle() |
| − | local content = frame:preprocess(title:getContent()) | + | local content = frame:preprocess( |
| + | args.section and transclude.getSection(content, args.section) or title:getContent() | ||
| + | ) | ||
local coords = {} | local coords = {} | ||
| − | for | + | for geo in mw.ustring.gmatch(content, "<span class=\"geo%-default\">(.-)%)</span></span></span>%]</span>") do |
| − | + | local coord = mw.ustring.match(geo, "<span class=\"geo%-dec\">(.-)</span>") | |
| + | if coord then | ||
| + | coord = mw.ustring.gsub(coord, "[° ]", "_") | ||
| + | end | ||
| + | local name = mw.ustring.match(geo, "<span class=\"fn org\">(.-)</span>") | ||
| + | coords[coord] = name | ||
end | end | ||
| − | + | local mapframeArgs = { | |
| + | display = "inline", | ||
| + | frame = yes | ||
| + | } | ||
| + | local count = 1 | ||
| + | for coord, name in pairs(coords) do | ||
| + | mapframeArgs["type"..count] = coord | ||
| + | mapframeArgs["title"..count] = name | ||
| + | end | ||
| + | local map = mapframe._main(mapframeArgs) | ||
| + | return frame:preprocess(map) | ||
end | end | ||
return p | return p | ||
Revision as of 01:25, 25 June 2020
| 40x40px | This module is a sandbox for testing XFDcloser. It may occasionally have deletion or speedy deletion notices; please do not actually delete it. |
Tests
{{#invoke:Sandbox/Evad37/X1|main}} → Lua error in package.lua at line 80: module 'Module:Transclude' not found.
Lua error: callParserFunction: function "#coordinates" was not found.
Lua error: callParserFunction: function "#coordinates" was not found.
{{#invoke:Sandbox/Evad37/X1|getCoords}} →
Lua error in package.lua at line 80: module 'Module:Transclude' not found.
-- This module is a sandbox. It is also used for testing XFDcloser
local getArgs = require('Module:Arguments').getArgs
local transclude = require("Module:Transclude")
local mapframe = require("Module:Mapframe")
local p = {}
p.main = function(frame)
local childFrame = frame:newChild{ title = "Sandbox", args = {} }
local FULLPAGENAME = childFrame:preprocess( "{{FULLPAGENAME}}" )
return FULLPAGENAME
end
p.getCoords = function(frame)
local args = getArgs(frame, {parentFirst = true})
local title = args.article and mw.title.new(args.article) or mw.title.getCurrentTitle()
local content = frame:preprocess(
args.section and transclude.getSection(content, args.section) or title:getContent()
)
local coords = {}
for geo in mw.ustring.gmatch(content, "<span class=\"geo%-default\">(.-)%)</span></span></span>%]</span>") do
local coord = mw.ustring.match(geo, "<span class=\"geo%-dec\">(.-)</span>")
if coord then
coord = mw.ustring.gsub(coord, "[° ]", "_")
end
local name = mw.ustring.match(geo, "<span class=\"fn org\">(.-)</span>")
coords[coord] = name
end
local mapframeArgs = {
display = "inline",
frame = yes
}
local count = 1
for coord, name in pairs(coords) do
mapframeArgs["type"..count] = coord
mapframeArgs["title"..count] = name
end
local map = mapframe._main(mapframeArgs)
return frame:preprocess(map)
end
return p