Module:Documentation: Difference between revisions

From Ato Wiki
starcitizen>Alistair3149
(Use table instead of string concat for ret3)
starcitizen>Alistair3149
No edit summary
Line 11: Line 11:
     local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
     local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
     local ret, cats, ret1, ret2, ret3
     local ret, cats, ret1, ret2, ret3
     local onModule = title.namespace == 828
     local pageType = title.namespace == 828 and 'module' or 'template'
      
      
     local opts = frame.args;
     local opts = frame.args;
Line 21: Line 21:
string.format(
string.format(
'It contains usage information, categories, and other content that is not part of the [[' .. page .. '|original %s page]].',
'It contains usage information, categories, and other content that is not part of the [[' .. page .. '|original %s page]].',
onModule and 'module' or 'template'
pageType
),
),
{ icon = 'WikimediaUI-Notice.svg' }
{ icon = 'WikimediaUI-Notice.svg' }
Line 50: Line 50:
             :tag( 'span' )
             :tag( 'span' )
                 :addClass( 'documentation-title' )
                 :addClass( 'documentation-title' )
                 :wikitext( string.format('%s documentation', onModule and 'Module' or 'Template') )
                 :wikitext( string.format('%s documentation', pageType) )
                 :done()
                 :done()
             :tag( 'span' )
             :tag( 'span' )
Line 74: Line 74:
     table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) )
     table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) )
      
      
    if args.scwShared then
    table.insert( ret3,
    mbox(
    string.format(
'This %s is shared across the Star Citizen Wikis.',
pageType,
page,
page
),
string.format(
'This %s is shared across the Star Citizen Wikis. Any changes should also be relayed to the [%s GitHub repository].',
pageType,
'https://github.com/The-Star-Citizen-Wikis/SharedModules'
),
{ icon = 'WikimediaUI-Notice.svg' }
)
  )
    end
     if args.fromWikipedia then
     if args.fromWikipedia then
     table.insert( ret3,
     table.insert( ret3,
Line 79: Line 98:
    string.format(
    string.format(
'This %s is imported from [https://en.wikipedia.org/wiki/%s %s] on Wikipedia.',
'This %s is imported from [https://en.wikipedia.org/wiki/%s %s] on Wikipedia.',
onModule and 'module' or 'template',
pageType,
page,
page,
page
page
),
),
'This template is imported from the English Wikipedia. Although the visual appearance might be different, the functionality is identical. Please refer to the Wikipedia page for detailed documentation.',
string.format(
'This %s is imported from the English Wikipedia. Although the visual appearance might be different, the functionality is identical. Please refer to the Wikipedia page for detailed documentation.',
pageType
),
{ icon = 'WikimediaUI-Logo-Wikipedia.svg' }
{ icon = 'WikimediaUI-Logo-Wikipedia.svg' }
)
)

Revision as of 11:40, 7 June 2023

module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Documentation/doc. Changes can be proposed in the talk page.
Function list
L 8 — p.doc

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 pageType = title.namespace == 828 and 'module' or 'template'
    
    local opts = frame.args;
    
    -- 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]].',
				pageType
			),
			{ 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

        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', pageType) )
                :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 = {}
    table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) )
    
    if args.scwShared then
    	table.insert( ret3,
    		mbox(
	    		string.format(
					'This %s is shared across the Star Citizen Wikis.',
					pageType,
					page,
					page
				),
				string.format(
					'This %s is shared across the Star Citizen Wikis. Any changes should also be relayed to the [%s GitHub repository].',
					pageType,
					'https://github.com/The-Star-Citizen-Wikis/SharedModules'
				),
				{ icon = 'WikimediaUI-Notice.svg' }
			)
	   )
    end

    if args.fromWikipedia then
    	table.insert( ret3,
    		mbox(
	    		string.format(
					'This %s is imported from [https://en.wikipedia.org/wiki/%s %s] on Wikipedia.',
					pageType,
					page,
					page
				),
				string.format(
					'This %s is imported from the English Wikipedia. Although the visual appearance might be different, the functionality is identical. Please refer to the Wikipedia page for detailed documentation.',
					pageType
				),
				{ icon = 'WikimediaUI-Logo-Wikipedia.svg' }
			)
	   )
    end
    
    if title.namespace == 828 then
    	-- Testcase page
    	if title.subpageText == 'testcases' then
    		table.insert( ret3,
		    	hatnote(
		    		string.format( 'This is the test cases page for the module [[Module:%s]].', title.baseText ),
		    		{ icon='WikimediaUI-LabFlask.svg' }
		    	)
		    )
		end

		table.insert( ret3, '<div class="documentation-modulestats">' )

		-- Function list
		table.insert( 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
			table.insert( ret3, frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' ) )
    	end
	
    	table.insert( ret3, '</div>' )
    end
        
    return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 )
end

return p

-- </nowiki>