Module:Data to Table: Difference between revisions
ReisuDesign (talk | contribs) No edit summary |
ReisuDesign (talk | contribs) No edit summary |
||
| Line 60: | Line 60: | ||
local sortkey = frame.args.sortkey or 'page' | local sortkey = frame.args.sortkey or 'page' | ||
local subtable = frame.args.subtable | local subtable = frame.args.subtable | ||
-- Constant value mode | |||
-- If |value=day is supplied, every page gets that value. | |||
local constantValue = frame.args.value | |||
local valueUnquoted = false | |||
if constantValue ~= nil then | |||
for _, rawKey in ipairs(rawKeys) do | |||
if rawKey == 'value' then | |||
valueUnquoted = true | |||
break | |||
end | |||
end | |||
end | |||
| Line 93: | Line 107: | ||
entry.page = clean(entry.page) | entry.page = clean(entry.page) | ||
-- | -- Constant value mode: | ||
if #dataKeys == 0 then | -- |value=day produces ['Page'] = 'day' | ||
if constantValue ~= nil and #dataKeys == 0 then | |||
local value | |||
if valueUnquoted then | |||
value = clean(constantValue) | |||
else | |||
value = '\'' .. clean(constantValue) .. '\'' | |||
end | |||
result:wikitext( | |||
'\t[\'', | |||
entry.page, | |||
'\'] = ', | |||
value, | |||
',\n' | |||
) | |||
-- No data keys: output page as a simple string | |||
elseif #dataKeys == 0 then | |||
result:wikitext( | |||
'\t\'', | |||
entry.page, | |||
'\',\n' | |||
) | |||
else | else | ||
| Line 193: | Line 210: | ||
-- Wrap output in syntaxhighlight | -- Wrap output in syntaxhighlight | ||
local luaText = tostring(result) | local luaText = tostring(result) | ||
-- Decode HTML entities introduced by mw.html | -- Decode HTML entities introduced by mw.html | ||
luaText = mw.text.decode(luaText) | luaText = mw.text.decode(luaText) | ||
local output = frame:extensionTag( | local output = frame:extensionTag( | ||
'syntaxhighlight', | 'syntaxhighlight', | ||
| Line 204: | Line 221: | ||
copy = '' | copy = '' | ||
} | } | ||
) | ) | ||
| Line 248: | Line 265: | ||
value = '{ \'' .. | value = '{ \'' .. | ||
table.concat(value, '\', \'') .. | table.concat(value, '\', \'') .. | ||
' }' | ' }' | ||
| Line 303: | Line 320: | ||
' = ', | ' = ', | ||
value, | value, | ||
',' | ',' | ||
) | ) | ||