Модуль:Песочница/Abiyoyo/Test1
Документация
require( 'strict' )
local p = {}
local getArgs = require('Module:Arguments').getArgs
local DebugLog = require('Module:DebugLog')
local debLog = DebugLog:new()
--local config = mw.loadData('Module:Песочница/Abiyoyo/Autosorting/config')
local config
local CP = require('Module:Песочница/Abiyoyo/Autosorting/ConfigProcessor')
local cp = CP:new()
--------------------------------------------------------------------------------
-- Func maps
--------------------------------------------------------------------------------
-- filter funcs declarations
local isEmptyParam, isNotEmptyParam, isEqParam, isNotEqParam, isNamespace
local isNotNamespace
local maps = {}
maps.filters = {
['parameter-is-empty'] = isEmptyParam,
['parameter-not-empty'] = isNotEmptyParam,
['parameter-equals'] = isEqParam,
['parameter-not-equals'] = isNotEqParam,
['namespace-is'] = isNamespace,
['namespace-is-not'] = isNotNamespace,
default = function() return true end,
}
local task1, task2, task3, task4
maps.tasks = {
['task1'] = task1,
['task2'] = task2,
['task3'] = task3,
['task4'] = task4,
default = function() return '' end,
}
local optTransformOnDataSet, optTransformOnParamVal
maps.optTransformers = {
['dataset'] = optTransformOnDataSet,
['parameter-value'] = optTransformOnParamVal,
-- ['parameter-separated-values'] = transformOnParamSepVal, --?
}
maps.resTransformers = {}
maps.postProcs = {}
--- Call for debug and logs
function p.loggedCall(frame)
debLog.enabled = true
local frameArgs = getArgs(frame)
debLog:write('Invoked with args: '.. mw.dumpObject(frameArgs), 'loggedCall')
local functionName = frameArgs['function']
local success, result = pcall(p[functionName], frameArgs)
if not success then
debLog:write(result, 'loggedCall', 'error')
return debLog:getAll()
end
return debLog:getAll() .. mw.text.nowiki(tostring(result))
end
---Основная функция.
-- параметр presetName нужен для поддержки старых методов типа byImage и т.п.
-- Больше низачем не нужен, потом надо убрать
function p._main (frameArgs)
debLog:write('Invoked with args: '..mw.dumpObject(frameArgs), '_main')
local presetName = frameArgs['preset']
if not cp:getConfig('Module:Песочница/Abiyoyo/Autosorting/config') then
return nil, 'Config load failed'
end
cp:setGlobalOptions()
if not cp:processGlobalOptions(frameArgs) then
return nil, 'Global options interruption'
end
-- get preset enriched with defaults
if not cp:preparePreset(presetName) then
return nil, 'Preset is empty'
end
-- check page against preset filters
if not cp:initFuncMaps(maps) then
return nil, 'FilterMap init failed'
end
if not cp:processPresetFilters(frameArgs) then
return nil, 'Filtered out by preset filters'
end
-- get valid rules from preset and check vs. rules' definitions
if not cp:prepareRuleStack() then
return nil, 'Rule list is empty'
end
debLog:write(cp.log,'parent log')
-- process rules and concat result
local rulesResult = cp.processRuleList(ruleList, cp.config.rules, frameArgs, preset)
if rulesResult == nil then
return nil, 'Rules result is nil'
end
return true, rulesResult
end
return p