Մոդուլ:Emoji
Documentation for this module may be created at Մոդուլ:Emoji/doc
-- Մեդուլ զանազան Модуփոխդասավորություններում էմոջիների ցուցւադրման համար
-- Էմոջի-կոդերի տվյալներ 8-)
local emoji = mw.loadData('Module:Emoji/data');
local p = {};
-- Տվյալների տադարկության փորձարկում :-O
local function isEmpty(s)
return s == nil or s == ''
end
-- Էմոջիների ցուցադրման համար անվանման արտացում :-3
local function fileName(code, theme)
-- Noto ոճը պահանջում է երկակի էմոջիների այլ ֆորմատավորում >:-(
if theme == 'noto' then
code = code:gsub('%-',' ')
end
-- Թեմաներ և դրանց կրճատում <3
local themes = {
['firefox'] = 'Fxemoji u' .. string.upper(code),
['noto'] = 'Emoji u' .. string.lower(code),
['one'] = 'Emojione ' .. string.upper(code),
['twitter'] = 'Twemoji ' .. string.lower(code),
}
themes['fx'] = themes['firefox'];
themes['tw'] = themes['twitter'];
return themes[theme]
end
-- Вывод HTML-кода соответствующих эмодзи D-:
local function toHTML(code)
local r = ''
if string.match(code,'-') then
local spl = mw.text.split(code,'-',true)
r = '&#x' .. spl[1] .. ';' .. '&#x' .. spl[2] .. ';'
else
r = '&#x' .. code .. ';'
end
return r
end
-- Բանալիների ստացում ըստ նշանակության {-:
local function getKey(t, value)
for k, v in pairs(t) do
if v == value then return k end
end
return nil
end
-- HTML-մնեմոնիկայի ստացում էմոջիների համար :=|
local function getCode(str)
local r = '';
for i = 1, mw.ustring.len(str) do
r = r .. string.format('%04x', mw.ustring.codepoint(str, i, (i+1))) .. '-';
end
return r:sub(1,-2)
end
-- Ֆայլի անվանում ;-1
function p.fileName(frame)
local f = frame.args
local name = f.name
local theme = f.theme
local code = emoji[name]
if isEmpty(code) then
if getKey(emoji,name) ~= nil then
code = name
else
code = getCode(name)
end
end
return fileName(code, theme)
end
-- Էմոջիով կաղապար ;-)
function p.render(frame)
local f = frame.args
local name = f.name
local size = f.size
local theme = f.theme
-- Ստանդարտ էմոջիի ընտրություն :-)
if isEmpty(name) then
name = 'slightly_smiling_face'
end
-- Ստանդարտ չափսի ընտրություն c-:
if isEmpty(size) then
size = '16'
end
-- Թեմայի ընտրություն ըստ լռելյայն :->
if isEmpty(theme) then
theme = 'one'
end
local code = emoji[name]
if isEmpty(code) then
if getKey(emoji,name) ~= nil then
code = name
else
code = getCode(name)
end
end
local span = mw.html.create():tag('span')
span:addClass('emoji')
span:cssText('font-size:' .. size .. 'px; font-family:"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol",sans-serif; line-height:' .. size .. 'px;')
-- Թեմայի ընտրություն :-D
local themes = {
['firefox'] = 'Firefox Emoji',
['noto'] = 'Noto Color Emoji',
['one'] = 'EmojiOne',
['twitter'] = 'Twitter Emoji',
}
themes['fx'] = themes['firefox'];
themes['tw'] = themes['twitter'];
-- Սիմվոլի, սիմվոլների կամ ֆայլի ընտրություն ըստ թեմայի :-*
if theme == 'none' then
span:attr('title',name)
span:wikitext(toHTML(code))
else
local file = fileName(code, theme)
if not isEmpty(file) then
file = string.format('Файл:%s.svg', file)
end
if not isEmpty(file) and mw.title.new(file).fileExists then
span:wikitext(string.format('[[%s|%spx|%s|alt=%s]]', file, size, name, toHTML(code)))
else
span:attr('title',string.format('Էմոջին %a չկա ցանկում %s',name,themes[theme]))
span:wikitext(toHTML(code))
end
end
return tostring(span:done())
end
return p