Module:Documentation: Difference between revisions

From Ato Wiki
starcitizen>Alistair3149
No edit summary
starcitizen>Alistair3149
No edit summary
Line 10: Line 10:
     local args = frame:getParent().args
     local args = frame:getParent().args
     local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
     local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
    local addDependencyList = yn( args.DependencyList or true )
    local addModuleToc = yn( args.ModuleToc or true )
    local isDataModule = yn( args.isData or false )
     local ret, cats, ret1, ret2, ret3
     local ret, cats, ret1, ret2, ret3
     local onModule = title.namespace == 828
     local onModule = title.namespace == 828
Line 32: Line 29:
         if title.namespace == 10 then -- Template namespace
         if title.namespace == 10 then -- Template namespace
             cats = '[[Category:Template documentation|' .. title.baseText .. ']]'
             cats = '[[Category:Template documentation|' .. title.baseText .. ']]'
             ret2 = addDependencyList and dependencyList._main() or ''
             ret2 = dependencyList._main()
         elseif title.namespace == 828 then -- Module namespace
         elseif title.namespace == 828 then -- Module namespace
             cats = '[[Category:Module documentation|' .. title.baseText .. ']]'
             cats = '[[Category:Module documentation|' .. title.baseText .. ']]'
             ret2 = addDependencyList and dependencyList._main() or ''
             ret2 = dependencyList._main()
             ret2 = ret2 .. (addModuleToc and require('Module:Module toc').main() or '')
             ret2 = ret2 .. require('Module:Module toc').main()
         else
         else
             cats = ''
             cats = ''
Line 93: Line 90:
    )
    )
    end
    end
   
    ret3 = ret3 .. '<div class="documentation-modulestats">'


     ret3 = ret3 .. (addModuleToc and require('Module:Module toc').main() or '')
     ret3 = ret3 .. require('Module:Module toc').main()
    
    
     -- Unit tests
     -- Unit tests
Line 102: Line 101:
     ret3 = ret3 .. frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' )
     ret3 = ret3 .. frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' )
     end
     end
   
    ret3 = ret3 .. '</div>'
   
    if title.subpageText == 'data' then
    ret3 = ret3 ..'<div class="seealso"><code>mw.loadData</code> compatible</div>[[Category:Data modules]]'
    end
     end
     end
   
    if isDataModule and title.namespace == 828 then
ret3 = ret3..'<div class="seealso"><code>mw.loadData</code> compatible</div>[[Category:Data modules]]'
end


if (preamble and preamble ~= "") then
if (preamble and preamble ~= "") then

Revision as of 23:25, 5 June 2023

Lua error at line 82: variable 'addDependencyList' is not declared. Module:Documentation implements Template:Documentation for templates and modules.


-- <nowiki>
local dependencyList = require( 'Module:DependencyList' )
local yn = require( 'Module:Yesno' )
local hatnote = require( 'Module:Hatnote' )._hatnote
local mbox = require( 'Module:Mbox' )._mbox
local p = {}

function p.doc( frame )
    local title = mw.title.getCurrentTitle()
    local args = frame:getParent().args
    local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
    local ret, cats, ret1, ret2, ret3
    local onModule = title.namespace == 828
    
    local opts = frame.args;
	local preamble = opts.preamble;
    
    -- subpage header
    if title.subpageText == 'doc' then
		ret = mbox(
			'This is a documentation subpage for ' .. page .. '.',
			string.format(
				'It contains usage information, categories, and other content that is not part of the [[' .. page .. '|original %s page]].',
				onModule and 'module' or 'template'
			),
			{ icon = 'WikimediaUI-Notice.svg' }
    	)

        if title.namespace == 10 then -- Template namespace
            cats = '[[Category:Template documentation|' .. title.baseText .. ']]'
            ret2 = dependencyList._main()
        elseif title.namespace == 828 then -- Module namespace
            cats = '[[Category:Module documentation|' .. title.baseText .. ']]'
            ret2 = dependencyList._main()
            ret2 = ret2 .. require('Module:Module toc').main()
        else
            cats = ''
            ret2 = ''
        end

		if isDataModule and title.namespace == 828 then
    		ret2 = ret2..'<div class="seealso"><code>mw.loadData</code> compatible</div>'
    	end

		if (preamble and preamble ~= "") then
			ret2 = preamble .. ret2
		end

        return tostring( ret ) .. ret2 .. cats
    end
    
    -- template header
    -- don't use mw.html as we aren't closing the main div tag
    ret1 = '<div class="documentation">'

    ret2 = mw.html.create( nil )
        :tag( 'div' )
            :addClass( 'documentation-header' )
            :tag( 'span' )
                :addClass( 'documentation-title' )
                :wikitext( string.format('%s documentation', onModule and 'Module' or 'Template') )
                :done()
            :tag( 'span' )
                :addClass( 'documentation-links plainlinks' )
                :wikitext(
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' view]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' ..
                    '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, {action='purge'} ) ) .. ' purge]</span>]'
                )
                :done()
            :done()
        :tag( 'div' )
            :addClass( 'documentation-subheader' )
            :tag( 'span' )
                :addClass( 'documentation-documentation' )
                :wikitext( 'This documentation is transcluded from [[' .. page .. '/doc]]. Changes can be proposed in the talk page.' )
                :done()
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Documentation/styles.css'} })
            :done()

    ret3 = addDependencyList and dependencyList._main(nil, args.category, args.isUsed) or ''
    
    if title.namespace == 828 then
    	-- Testcase page
    	if title.subpageText == 'testcases' then
	    	ret3 = ret3 .. hatnote(
	    		string.format( 'This is the test cases page for the module [[Module:%s]].', title.baseText ),
	    		{ icon='WikimediaUI-LabFlask.svg' }
	    	)
	    end
	    
	    ret3 = ret3 .. '<div class="documentation-modulestats">'

    	ret3 = ret3 .. require('Module:Module toc').main()
    	
    	-- Unit tests
    	local testcaseTitle = title.baseText .. '/testcases'
    	if mw.title.new( testcaseTitle, 'Module' ).exists then
    		-- There is probably a better way :P
    		ret3 = ret3 .. frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' )
    	end
    	
    	ret3 = ret3 .. '</div>'
    	
    	if title.subpageText == 'data' then
	    	ret3 = ret3 ..'<div class="seealso"><code>mw.loadData</code> compatible</div>[[Category:Data modules]]'
	    end
    end

	if (preamble and preamble ~= "") then
		ret3 = preamble .. ret3
	end
        
    return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. ret3
end

return p

-- </nowiki>