Module:CRTModel: Difference between revisions

No edit summary
No edit summary
Line 229: Line 229:
ul:css('margin', '0'):css('padding-left', '1.5em')
ul:css('margin', '0'):css('padding-left', '1.5em')
-- Use #ask with array format to get raw values
-- Use #ask with array format - simpler separators
local docsQueryWikitext =
local docsQueryWikitext =
'{{#ask:\n' ..
'{{#ask:\n' ..
Line 237: Line 237:
' |?Has document URL\n' ..
' |?Has document URL\n' ..
' |format=array\n' ..
' |format=array\n' ..
' |propsep=@@\n' ..
' |propsep=§\n' ..
' |valuesep=##\n' ..
' |sep=\n' ..
' |sep=|||\n' ..
' |link=none\n' ..
' |link=none\n' ..
' |headers=hide\n' ..
'}}'
'}}'
local docsResult = frame:preprocess(docsQueryWikitext)
local docsResult = frame:preprocess(docsQueryWikitext)
-- Parse the array format: each document separated by |||, properties by @@
-- Parse the result - format should be: PageName§Type§URL¶PageName§Type§URL
if docsResult and trim(docsResult) then
if docsResult and trim(docsResult) then
for docData in docsResult:gmatch('[^|]+') do
-- Split by paragraph symbol (documents separator)
-- Split by @@ to get page name, type, and URL
for docLine in docsResult:gmatch('[^]+') do
local parts = {}
docLine = trim(docLine)
for part in (docData .. '@@'):gmatch('([^@]*)@@') do
if docLine and docLine ~= '' then
table.insert(parts, trim(part))
-- Split by section symbol (properties separator)
end
local parts = {}
for part in docLine:gmatch('[^§]+') do
-- parts[1] = page name, parts[2] = document type, parts[3] = URL
table.insert(parts, trim(part))
local docType = parts[2]
end
local docUrl = parts[3]
if docUrl and docUrl ~= '' then
local displayText = (docType and docType ~= '') and docType or 'Document'
-- Create list item with link
-- parts[1] = page name, parts[2] = type, parts[3] = URL
local li = ul:tag('li')
if #parts >= 3 then
li:wikitext('[' .. docUrl .. ' ' .. displayText .. ']')
local docType = parts[2]
local docUrl = parts[3]
if docUrl and docUrl ~= '' then
local displayText = (docType and docType ~= '') and docType or 'Document'
-- Create list item with link
local li = ul:tag('li')
li:wikitext('[' .. docUrl .. ' ' .. displayText .. ']')
end
end
end
end
end
end
MediaWiki Appliance - Powered by TurnKey Linux