Module:EcopediaString: Difference between revisions
From Eco - English Wiki
[unchecked revision] | [checked revision] |
No edit summary |
No edit summary |
||
Line 45: | Line 45: | ||
-- main heading | -- main heading | ||
text = text .. "\'\'\'" .. p.displayName .. "\'\'\'\n" | text = text .. "\'\'\'" .. p.displayName .. "\'\'\'\n\n" | ||
-- loop through sections (i = array position, j= {sectionType, text} ) | -- loop through sections (i = array position, j= {sectionType, text} ) | ||
Line 53: | Line 53: | ||
if (sec[1] == bodySec) then | if (sec[1] == bodySec) then | ||
text = text .. sec[2] .. "\n" | text = text .. sec[2] .. "\n\n" | ||
end -- if bodySec | end -- if bodySec | ||
if (sec[1] == headerSec) then | if (sec[1] == headerSec) then | ||
text = text .. "\'\'" .. sec[2] .. "\'\'\n" | text = text .. "\'\'\'" .. sec[2] .. "\'\'\'\n\n" | ||
end -- if headerSec | end -- if headerSec | ||
Revision as of 04:54, 4 February 2021
This module provides the back end functionality of the Template:EcopediaString.
If the template is passed information will be displayed using details from the following Modules:
-- Module:GetEcopedia (https://wiki.play.eco/en/Module:GetEcopedia)
local p = {}
-- Grabs args from the parent frame
-- Trims and parses the args into a table, then returns the table
function norm()
local origArgs = mw.getCurrentFrame():getParent().args
local args = {}
for k, v in pairs( origArgs ) do
v = mw.text.trim( tostring( v ) )
if v ~= '' then
args[k] = v
end
end
return args
end
-- Main entry point for the Module
function p.main()
-- get args from the Template
local args = norm()
-- assign variables for page
local page = args.page
-- load list of pages
local completeList = require( "Module:Ecopedia" )
local pageList = completeList.ecopedia
-- sectionTypes constants
local bodySec = "EcopediaSection"
local headerSec = "EcopediaHeader"
-- create text to be returned"
local text = ""
-- make sure page is not nil
if page ~= nil then
-- make sure page exists in ecopedia
local p = pageList[page]
if p ~= nil then
-- main heading
text = text .. "\'\'\'" .. p.displayName .. "\'\'\'\n\n"
-- loop through sections (i = array position, j= {sectionType, text} )
for i=1, #p.sectionsText do
-- create a local of the current section
local sec = p.sectionsText[i]
if (sec[1] == bodySec) then
text = text .. sec[2] .. "\n\n"
end -- if bodySec
if (sec[1] == headerSec) then
text = text .. "\'\'\'" .. sec[2] .. "\'\'\'\n\n"
end -- if headerSec
end -- sections for loop
end -- if exists in Ecopedia
else
text = "PAGE " .. page .. " NOT FOUND"
end -- if page not nil
return text
end
return p