Diese Dokumentation wird von Modul:Transclude/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
Function list |
---|
L 5 — getLstSections L 25 — parseTitleAndSections L 39 — isIgnored L 78 — makeOptions L 79 — isSet L 136 — p.transclude |
Modulinfo
Das Modul:Transclude bindet Text aus anderen Seiten ein. Das Hauptmodul ist unter Modul:Transcluder zu finden.
Dieses Modul setzt die Vorlage:Transclude um. Anweisungen zur Verwendung findest du auf der Vorlagenseite.
local p = {}
local transcluder = require( 'Modul:Transcluder' )
local function getLstSections( title, options )
if options.sections == nil then
return ''
end
local separator = '\n\n'
if options.inlineSections == true then
separator = ' '
end
local out = {}
for _, section in ipairs( mw.text.split( options.sections, ', ', true ) ) do
table.insert( out, transcluder.get( string.format( "%s#%s", title, section ) ) )
end
return table.concat( out, separator )
end
local function parseTitleAndSections( title, args )
local sections = {}
local ignoreList = {
'loadSections', 'Sektionen',
'noFiles', 'Keine Dateien',
'filterFiles', 'Dateifilter',
'inlineSections', 'Kein Sektionsumbruch',
'noRefs', 'Keine Referenzen',
'onlyParagraphs', 'Nur Text',
'templates', 'Vorlagen',
'noCategories', 'Keine Kategorien'
}
local function isIgnored( key )
for k, v in pairs( ignoreList ) do
if v == key then
return true
end
end
return false
end
-- loop from 2 -> 10
for i = 2, 10, 1 do
if args[ i ] ~= nil and not isIgnored( args[ i ] ) then
table.insert( sections, args[ i ] )
end
end
if #sections == 1 then
if mw.ustring.find( title, '#', 0, true ) == nil then
title = title .. '#' .. sections[ 1 ]
end
end
return title, table.concat( sections, ', ' ) or {}
end
--- Creates the options table from passed args
--- Supports the following args:
--- * inlineSections = Don't add two '\n' after each section
--- Only works with loadSections
--- * loadSections = request each section separately
--- Allows to set a list of <section> elements to translcude
--- Required when specifying a list of sections in {{Transclude}}
--- * noFiles = Remove all files from the output
--- * filterFiles = Filter files, see Module:Transcluder
--- = e.g. '1,2' -> Exclude all files except the first and second
--- * noRefs = Remove all references from the output
--- @param args table
--- @return table
local function makeOptions( args )
local function isSet( a1, a2 )
return (args[ a1 ] ~= nil and args[ a1 ] ~= '') or
(args[ a2 ] ~= nil and args[ a2 ] ~= '')
end
local options = {
loadSections = false,
inlineSections = false,
categories = '0',
}
if isSet( 'loadSections', 'Sektionen' ) then
options[ 'loadSections' ] = true
end
if isSet( 'noFiles', 'Keine Dateien' ) then
options[ 'files' ] = 0
end
if isSet( 'filterFiles', 'Dateifilter' ) then
options[ 'files' ] = args[ 'fileFilter' ] or args[ 'Dateifilter' ]
end
if isSet( 'inlineSections', 'Kein Sektionsumbruch' ) then
options[ 'inlineSections' ] = true
end
if isSet( 'noRefs', 'Keine Referenzen' ) then
options[ 'references' ] = 0
options[ 'templates' ] = '-Quelle'
end
if isSet( 'onlyParagraphs', 'Nur Text' ) then
options[ 'only' ] = 'paragraphs'
end
if isSet( 'onlyFirstParagraph', 'Erster Satz' ) then
options[ 'only' ] = 'paragraphs'
options[ 'paragraphs' ] = 0
end
if isSet( 'templates', 'Vorlagen' ) then
options[ 'templates' ] = args[ 'templates' ] or args[ 'Vorlagen' ]
end
if isSet( 'noCategories', 'Keine Kategorien' ) then
options[ 'categories' ] = 0
end
return options
end
--- Transclude part of a page
--- Removes all categories by default
---
--- @param frame table
--- @return string
function p.transclude( frame )
local options
local args = {}
local title
for key, value in pairs(frame:getParent().args) do args[key] = value end
for key, value in pairs(frame.args) do args[key] = value end
options = makeOptions( args )
title = args[ 'Titel' ] or args[ 1 ] or nil
if title == nil then
error( 'Kein Seitentitel angegeben' )
end
title, sections = parseTitleAndSections( title, args )
if #sections > 1 then
options[ 'sections' ] = sections
end
if options.loadSections == true then
return frame:preprocess( getLstSections( title, options ) )
end
return frame:preprocess( mw.ustring.gsub( transcluder.get( title, options ), '[\r\n\s]*</?translate>[\r\n\s]*', '' ) )
end
return p