-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1589 from UlrichB22/showsmiley
Add ShowSmileys macro
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |