mNo edit summary |
mNo edit summary |
||
(17 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
− | local |
+ | local w_frame = require( 'module:frame' ) |
− | local |
+ | local w_title = require( 'module:title' ) |
+ | -- DEPRECATED |
||
− | function p.pageName( f ) |
||
+ | p.pageName = w_title.main |
||
− | return mw.title.getCurrentTitle().text; |
||
+ | p.rootPageName = w_title.root |
||
− | end |
||
+ | p.subPageName = w_title.subpage |
||
− | |||
− | |||
− | function p.rootPageName( f ) |
||
− | return mw.title.getCurrentTitle().rootText; |
||
− | end |
||
− | |||
− | |||
− | function p.subPageName( f ) |
||
− | return mw.title.getCurrentTitle().subpageText; |
||
− | end |
||
− | |||
− | |||
− | function test( f ) |
||
− | return f |
||
− | end |
||
function p.toNumber( f ) |
function p.toNumber( f ) |
||
− | local args = |
+ | local args = w_frame.args( f ) |
return tonumber( args[1], args.base or 10 ) |
return tonumber( args[1], args.base or 10 ) |
||
end |
end |
||
+ | -- DEPRECATED : Use "template:font" instead |
||
− | function p.itemTest( f ) |
||
− | local args = rtable.trimAll( rtable.getArgs( f ) ) |
||
− | local exceptions = { |
||
− | ["Ace of Spades 2"] = "Ace of Spades (Card)", |
||
− | ["Cancer 2"] = "Cancer (Trinket)", |
||
− | ["Gemini"] = "Gemini (Item)", |
||
− | ["Little Horn"] = "Little Horn (Item)", |
||
− | ["Money Power"] = "Money = Power", |
||
− | ["Steven"] = "Steven (Item)" |
||
− | } |
||
− | for i, j in pairs( exceptions ) do |
||
− | if args[1] == i then |
||
− | return j |
||
− | end |
||
− | end |
||
− | return args[1] |
||
− | end |
||
− | function p.itemTest2( f ) |
||
− | local args = rtable.trimAll( rtable.getArgs( f ) ) |
||
− | local exceptions = { |
||
− | ["Ace of Spades 2"] = "Ace of Spades (Card)", |
||
− | ["Cancer 2"] = "Cancer (Trinket)", |
||
− | ["Gemini"] = "Gemini (Item)", |
||
− | ["Little Horn"] = "Little Horn (Item)", |
||
− | ["Money Power"] = "Money = Power", |
||
− | ["Steven"] = "Steven (Item)" |
||
− | } |
||
− | local name = args[1] |
||
− | for i, j in pairs( exceptions ) do |
||
− | if args[1] == i then |
||
− | name = j |
||
− | end |
||
− | end |
||
− | local mode = args[2] == 'a' and 'link-a' or args[2] == 'a+' and 'link-a+' or args[2] == 'n' and 'link-a+' or args[2] or 'link' |
||
− | return f:expandTemplate{ title = ':' .. name, args = { 'itemα' .. name .. 'β' .. mode } } |
||
− | end |
||
− | |||
− | p.specialCharacters = { |
||
− | ['"'] = "oquote", |
||
− | ["“"] = "oquote", |
||
− | ["”"] = "cquote", |
||
− | ["*"] = "star", |
||
− | ["+"] = "plus", |
||
− | ["±"] = "pm", |
||
− | ["="] = "equal", |
||
− | ["~"] = "tilde", |
||
− | [":"] = "colon", |
||
− | [";"] = "scolon", |
||
− | ["."] = "point", |
||
− | ["!"] = "emark", |
||
− | ["?"] = "qmark", |
||
− | ["/"] = "slash", |
||
− | ["|"] = "vbar", |
||
− | ["\\"] = "bslash", |
||
− | ["("] = "oparen", |
||
− | [")"] = "cparen", |
||
− | ["["] = "obrkt", |
||
− | ["]"] = "cbrkt", |
||
− | ["{"] = "obrace", |
||
− | ["}"] = "cbrace", |
||
− | ["<"] = "lthan", |
||
− | [">"] = "gthan", |
||
− | ["¶"] = "pilcrow", |
||
− | ["&"] = "and", |
||
− | ["§"] = "ss", |
||
− | ["%"] = "percent", |
||
− | ["†"] = "dagger", |
||
− | ["‡"] = "diesis", |
||
− | ["#"] = "hash", |
||
− | ["°"] = "degree", |
||
− | ["$"] = "dol", |
||
− | ["€"] = "euro", |
||
− | ["¢"] = "cent", |
||
− | ["£"] = "pound", |
||
− | ["@"] = "at", |
||
− | ["©"] = "copy", |
||
− | ["®"] = "regtm", |
||
− | ["¤"] = "curren", |
||
− | } |
||
− | |||
− | |||
− | -- Replace a text with div(s), with a special font on background |
||
− | -- Available: TeamMeat (https://bindingofisaacrebirth.gamepedia.com/File:Font_TeamMeat.png) |
||
− | -- TeamMeat-Bold (https://bindingofisaacrebirth.gamepedia.com/File:Font_TeamMeat_Bold.png) |
||
function p.font( f ) |
function p.font( f ) |
||
− | + | local args = w_frame.args( f ) |
|
+ | return '<span class="custom-font custom-font-' .. args[ 1 ] .. ( args.title and '" title="' .. args.title or '' ) .. '">' .. args[ 2 ] .. '</span>' |
||
− | local _t = '<span style="white-space:nowrap">' |
||
− | |||
− | -- Get custom characters |
||
− | local char = {} |
||
− | if args.var1 then |
||
− | local i = 1 |
||
− | repeat |
||
− | char[i] = mw.text.split( args['var'..i], '-' ) |
||
− | i = i + 1 |
||
− | until not args['var'..i] |
||
− | end |
||
− | |||
− | -- Split string |
||
− | local characters = {} |
||
− | args[2]:gsub( ".", function(c) table.insert( characters, c ) end ) |
||
− | local j = 1 |
||
− | while characters[j] do |
||
− | -- Is a space ? |
||
− | if characters[j] == ' ' then |
||
− | _t = _t .. '</span> <span style="white-space:nowrap">' |
||
− | else |
||
− | -- Replace custom character |
||
− | for k, l in pairs( char ) do |
||
− | if characters[j] == l[1] then |
||
− | characters[j] = l[2] |
||
− | break |
||
− | end |
||
− | end |
||
− | -- Is a special character ? |
||
− | characters[j] = p.specialCharacters[characters[j]] or characters[j] |
||
− | -- Replace character with a div |
||
− | _t = _t .. '<div ' .. ( args.title and 'title="' .. args.title .. '"' or '' ) .. ' class="font-' .. args[1] .. ' font-' .. args[1] .. '-' .. characters[j] .. '"></div>' |
||
− | end |
||
− | j = j + 1 |
||
− | end |
||
− | |||
− | return _t .. '</span>' |
||
end |
end |
||
− | |||
− | p.filesWidth = { |
||
− | ["("] = 9, |
||
− | ["“"] = 7, |
||
− | ["."] = 7, |
||
− | ["§"] = 11, |
||
− | ["'"] = 8, |
||
− | ["-"] = 12, |
||
− | ["&"] = 14, |
||
− | ["@"] = 17, |
||
− | ["¤"] = 11, |
||
− | ["©"] = 14, |
||
− | [")"] = 9, |
||
− | ["°"] = 10, |
||
− | ["$"] = 13, |
||
− | ["%"] = 22, |
||
− | ["£"] = 15, |
||
− | ["®"] = 14, |
||
− | ["~"] = 13, |
||
− | ["!"] = 7, |
||
− | ["¢"] = 11, |
||
− | ["="] = 11, |
||
− | ["¶"] = 11, |
||
− | ["±"] = 18, |
||
− | ["{"] = 13, |
||
− | ["1"] = 8, |
||
− | ["2"] = 12, |
||
− | ["4"] = 11, |
||
− | ["6"] = 13, |
||
− | ["7"] = 13, |
||
− | ["D"] = 13, |
||
− | ["G"] = 15, |
||
− | ["K"] = 15, |
||
− | ["M"] = 17, |
||
− | ["P"] = 14, |
||
− | ["Q"] = 19, |
||
− | ["S"] = 14, |
||
− | ["U"] = 14, |
||
− | ["b"] = 10, |
||
− | ["e"] = 11, |
||
− | ["f"] = 11, |
||
− | ["m"] = 12, |
||
− | ["o"] = 12, |
||
− | ["}"] = 10, |
||
− | ["0"] = 11, |
||
− | ["8"] = 13, |
||
− | ["9"] = 12, |
||
− | ["I"] = 11, |
||
− | ["J"] = 13, |
||
− | ["L"] = 14, |
||
− | ["O"] = 17, |
||
− | ["V"] = 13, |
||
− | ["Z"] = 15, |
||
− | ["a"] = 10, |
||
− | ["g"] = 12, |
||
− | ["h"] = 11, |
||
− | ["i"] = 5, |
||
− | ["k"] = 11, |
||
− | ["t"] = 12, |
||
− | ["w"] = 14, |
||
− | ["x"] = 10, |
||
− | ["z"] = 13, |
||
− | ["\\"] = 8, |
||
− | [">"] = 13, |
||
− | ["#"] = 17, |
||
− | ["["] = 9, |
||
− | [";"] = 7, |
||
− | ["A"] = 14, |
||
− | ["B"] = 14, |
||
− | ["C"] = 12, |
||
− | ["E"] = 12, |
||
− | ["F"] = 13, |
||
− | ["H"] = 14, |
||
− | ["N"] = 17, |
||
− | ["R"] = 15, |
||
− | ["T"] = 15, |
||
− | ["W"] = 19, |
||
− | ["X"] = 16, |
||
− | ["Y"] = 15, |
||
− | ["c"] = 11, |
||
− | ["d"] = 11, |
||
− | ["j"] = 10, |
||
− | ["l"] = 7, |
||
− | ["n"] = 10, |
||
− | ["p"] = 10, |
||
− | ["q"] = 12, |
||
− | ["r"] = 11, |
||
− | ["s"] = 11, |
||
− | ["u"] = 11, |
||
− | ["v"] = 12, |
||
− | ["y"] = 9, |
||
− | ["]"] = 10, |
||
− | [":"] = 5, |
||
− | ["?"] = 13, |
||
− | ["<"] = 13, |
||
− | ["+"] = 12, |
||
− | ["/"] = 10, |
||
− | ["*"] = 10, |
||
− | ["3"] = 13, |
||
− | ["5"] = 13, |
||
− | } |
||
function p.title( f ) |
function p.title( f ) |
||
− | + | local args = w_frame.args( f ) |
|
+ | local scale = tonumber( args[ 3 ] or 1 ) |
||
− | local _t = '<span style="white-space:nowrap">' |
||
+ | local space = '</span> ' .. ( scale > 1.5 and ' ' or '' ) .. ' <span style="white-space: nowrap">' |
||
− | |||
+ | local width = mw.loadData( 'module:text/' .. args[ 1 ] ) |
||
− | -- Get custom characters |
||
+ | local intro = '[[file:font_' .. args[ 1 ] .. '_' |
||
− | local char = {} |
||
+ | local outro = 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]' |
||
− | if args.var1 then |
||
+ | local text = '<span style="white-space:nowrap">' |
||
− | local i = 1 |
||
+ | local specialCharacters = mw.loadData( 'module:text/special' ) |
||
− | repeat |
||
− | + | for c in mw.text.gsplit( args[ 2 ], '' ) do |
|
+ | text = text .. ( c == ' ' and space or intro .. ( specialCharacters[ c ] or c ) .. '.png|alt=' .. c .. '|' .. math.floor( width[ c ] * scale ) .. outro ) |
||
− | i = i + 1 |
||
+ | end |
||
− | until not args['var'..i] |
||
+ | return text .. '</span>' |
||
− | end |
||
− | |||
− | -- Split string |
||
− | local characters = {} |
||
− | args[2]:gsub( ".", function(c) table.insert( characters, c ) end ) |
||
− | local j = 1 |
||
− | |||
− | while characters[j] do |
||
− | -- Is a space ? |
||
− | if characters[j] == ' ' then |
||
− | _t = _t .. '</span> ' .. ( tonumber( args[3] or 1 ) > 1.5 and ' ' or '' ) .. ' <span style="white-space:nowrap">' |
||
− | else |
||
− | -- Replace custom character |
||
− | for k, l in pairs( char ) do |
||
− | if characters[j] == l[1] then |
||
− | characters[j] = l[2] |
||
− | break |
||
− | end |
||
− | end |
||
− | -- Replace character with an image |
||
− | local fileName = 'Font_' .. args[1] .. '_' .. ( p.specialCharacters[characters[j]] or characters[j] ) .. '.png' |
||
− | local width = math.floor( p.filesWidth[characters[j]] * ( args[3] or 1 ) ) |
||
− | _t = _t .. '[[Image:' .. fileName .. '|' .. tostring( width ) .. 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]' |
||
− | end |
||
− | j = j + 1 |
||
− | end |
||
− | |||
− | return _t .. '</span>' |
||
end |
end |
||
+ | |||
return p |
return p |
Revision as of 22:48, 8 April 2021
The above documentation is transcluded from Module:Text/doc. (edit | history)
local p = {}
local w_frame = require( 'module:frame' )
local w_title = require( 'module:title' )
-- DEPRECATED
p.pageName = w_title.main
p.rootPageName = w_title.root
p.subPageName = w_title.subpage
function p.toNumber( f )
local args = w_frame.args( f )
return tonumber( args[1], args.base or 10 )
end
-- DEPRECATED : Use "template:font" instead
function p.font( f )
local args = w_frame.args( f )
return '<span class="custom-font custom-font-' .. args[ 1 ] .. ( args.title and '" title="' .. args.title or '' ) .. '">' .. args[ 2 ] .. '</span>'
end
function p.title( f )
local args = w_frame.args( f )
local scale = tonumber( args[ 3 ] or 1 )
local space = '</span> ' .. ( scale > 1.5 and ' ' or '' ) .. ' <span style="white-space: nowrap">'
local width = mw.loadData( 'module:text/' .. args[ 1 ] )
local intro = '[[file:font_' .. args[ 1 ] .. '_'
local outro = 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
local text = '<span style="white-space:nowrap">'
local specialCharacters = mw.loadData( 'module:text/special' )
for c in mw.text.gsplit( args[ 2 ], '' ) do
text = text .. ( c == ' ' and space or intro .. ( specialCharacters[ c ] or c ) .. '.png|alt=' .. c .. '|' .. math.floor( width[ c ] * scale ) .. outro )
end
return text .. '</span>'
end
return p