|
|
(9 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| -- Module:GetEcopedia (https://wiki.play.eco/en/Module:GetEcopedia)
| |
| local p = {} | | local p = {} |
|
| |
|
| -- Grabs args from the parent frame
| | function p.main(param) |
| -- Trims and parses the args into a table, then returns the table
| | local Utils = require('Module:Utils') |
| function norm() | | local args = Utils.normaliseArgs(param) |
| local origArgs = mw.getCurrentFrame():getParent().args
| | local String = "" |
| local args = {}
| | local EcopediaList = mw.loadData("Module:EcopediaData") |
|
| | local String = EcopediaList[args.num] |
| 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"
| |
|
| |
| -- loop through sections (i = array position, j= {sectionType, text} )
| |
| for i=1, #p.sections do
| |
| -- create a local of the current section
| |
| local sec = p.sections[i]
| |
|
| |
| if (sec[1] == bodySec) then
| |
| text = text .. sec[2] .. "\n"
| |
| end -- if bodySec
| |
|
| |
| if (sec[1] == headerSec) then
| |
| text = text .. "\'\'" .. sec[2] .. "\'\'\n"
| |
| end -- if headerSec
| |
|
| |
| end -- sections for loop
| |
|
| |
| end -- if exists in Ecopedia
| |
| end -- if page not nil
| |
| | | |
| return text | | return String |
| end | | end |
|
| |
|
| return p | | return p |
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:
local p = {}
function p.main(param)
local Utils = require('Module:Utils')
local args = Utils.normaliseArgs(param)
local String = ""
local EcopediaList = mw.loadData("Module:EcopediaData")
local String = EcopediaList[args.num]
return String
end
return p