Module:Module wikitext/sandbox

This is an auxiliary module used to allow module pages to display wikitext. Use it by setting this module's text value to whatever content you want to display.

Module:Module wikitext/sandbox
--- This module provides functions related to adding wikitext to
-- module pages and transcluding wikitext.
-- @module module_wikitext
-- @alias p
-- @release stable

local p = {}

p.text = ''

--- Fetches the current module wikitext value
--
-- @return The current module wikitext
function p.main()
	return p.text
end

--- Adds module wikitext.
--
-- @param {string} text Module wikitext to add
-- @param preprocessFrame frame to use or false to skip preprocessing
-- @usage require("Module:Module wikitext")._addText(text)
function p._addText(text, preprocessFrame)
	if preprocessFrame ~= false then
		text = (preprocessFrame or mw.getCurrentFrame()):preprocess(text)
	end
	p.text = p.text .. text
	return p
end

function p:addText(text, preprocessFrame)
	if preprocessFrame ~= false then
		text = (preprocessFrame or mw.getCurrentFrame()):preprocess(text)
	end
	self.text = self.text .. text
	return self
end

--- Adds a new line
function p._newLine()
	p.text = p.text .. '\n\n'
	return p
end

function p:newLine()
	self.text = self.text .. '\n\n'
	return self
end

--- Package data for wrapping
--
-- @table p.packageData
-- @field package Package to use
-- @field prepend Text to prepend to string outputs
-- @field append Text to append to string outputs
p.packageData = {}

--- Wrapper function for packages using module wikitext
--
-- @param {table} package Module package
-- @param {string} prepend Text to prepend instead of p.text
-- @param {string} append Text to append
-- @return Metatable that invokes package wrapper and wraps metatable
function p.wrapper(package, prepend, append)
	p.packageData = {
		package = package,
		prepend = prepend or p.text or '',
		append = append or ''
	}
	return setmetatable({}, {
		__index = function( _, key )
			mw.logObject(p.packageData)
			if type(p.packageData.package[key]) == 'function' then
				-- This passthrough function adds the module wikitext
				-- to any string output, necessary for stuff like TfD
				return function(...)
					local output = p.packageData.package[key](...)
					if type(output) == 'string' then
						return p.packageData.prepend .. output .. p.packageData.append
					end
					return output
				end
			end
			return p.packageData.package[key]
		end
	})
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.