Skip to content

Commit

Permalink
Merge pull request #1589 from UlrichB22/showsmiley
Browse files Browse the repository at this point in the history
Add ShowSmileys macro
  • Loading branch information
RogerHaase authored Feb 3, 2024
2 parents f59252f + 04d8de2 commit d78e547
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/moin/macros/ShowSmileys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Show all available smileys that may be included in wiki item content
"""

from flask import url_for

from moin.utils.tree import html
from moin.macros._base import MacroBlockBase
from moin.i18n import _
from moin.converters._table import TableMixin
from moin.converters.smiley import Converter


class Macro(MacroBlockBase):
def macro(self, content, arguments, page_url, alternative):
smileys = Converter.smileys
headings = (_('Markup'), _('Result'), _('Name'))
rows = []
for key in smileys.keys():
icon_name = smileys[key]
src = url_for('static', filename='img/icons/' + icon_name + ".png")
rows.append((key, html.img(attrib={html.src: src, html.alt: icon_name}), icon_name))
table = TableMixin()
ret = table.build_dom_table(rows, head=headings)
return ret
25 changes: 25 additions & 0 deletions src/moin/macros/_tests/test_ShowSmileys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Test for macros.ShowSmileys
"""

from moin.macros.ShowSmileys import Macro


def test_Macro():
""" test for Macro.macro """
expected_text = ['X-(', 'angry', ':D', 'biggrin', '<:(', 'frown', '{o}', 'star_off', ]
expected_tag = '{http://moinmo.in/namespaces/page}table-row'
macro_obj = Macro()
macro_out = macro_obj.macro('content', None, 'page_url', 'alternative')
result_text = []
result_tags = []
for node in macro_out.iter_elements_tree():
if getattr(node, 'text'):
result_text.append(getattr(node, 'text'))
if getattr(node, 'tag'):
result_tags.append(str(getattr(node, 'tag')))
assert set(expected_text).issubset(result_text)
assert expected_tag in result_tags

0 comments on commit d78e547

Please sign in to comment.