| 1 |
# -*- coding: iso-8859-1 -*- |
|---|
| 2 |
# |
|---|
| 3 |
# Copyright (C) 2006 Christian Boos <cboos@neuf.fr> |
|---|
| 4 |
# All rights reserved. |
|---|
| 5 |
# |
|---|
| 6 |
# This software is licensed as described in the file COPYING, which |
|---|
| 7 |
# you should have received as part of this distribution. The terms |
|---|
| 8 |
# are also available at http://trac.edgewall.com/license.html. |
|---|
| 9 |
# |
|---|
| 10 |
# Author: Christian Boos <cboos@neuf.fr> |
|---|
| 11 |
|
|---|
| 12 |
# See also http://moinmoin.wikiwikiweb.de/HelpOnSmileys |
|---|
| 13 |
|
|---|
| 14 |
import re |
|---|
| 15 |
|
|---|
| 16 |
from trac.core import implements, Component |
|---|
| 17 |
from trac.web.chrome import ITemplateProvider |
|---|
| 18 |
from trac.wiki import IWikiSyntaxProvider, IWikiMacroProvider |
|---|
| 19 |
|
|---|
| 20 |
from goodies.util import * |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
SMILEYS = { |
|---|
| 24 |
":)": "smile.png", |
|---|
| 25 |
":-)": "smile.png", |
|---|
| 26 |
"B-)": "smile2.png", |
|---|
| 27 |
"B)": "smile2.png", |
|---|
| 28 |
":))": "smile3.png", |
|---|
| 29 |
":-))": "smile3.png", |
|---|
| 30 |
";-)": "smile4.png", |
|---|
| 31 |
":D": "biggrin.png", |
|---|
| 32 |
";)": "smile4.png", |
|---|
| 33 |
":(": "sad.png", |
|---|
| 34 |
":-(": "sad.png", |
|---|
| 35 |
":-?": "tongue.png", |
|---|
| 36 |
":o": "redface.png", |
|---|
| 37 |
"<:(": "frown.png", |
|---|
| 38 |
"|)": "tired.png", |
|---|
| 39 |
':-\\': "ohwell.png", |
|---|
| 40 |
">:>": "devil.png", |
|---|
| 41 |
"X-(": "angry.png", |
|---|
| 42 |
"|-)": "tired.png", |
|---|
| 43 |
|
|---|
| 44 |
"(./)": "checkmark.png", |
|---|
| 45 |
"(!)": "idea.png", |
|---|
| 46 |
"<!>": "attention.png", |
|---|
| 47 |
'/!\\': "alert.png", |
|---|
| 48 |
"{#1}": "prio1.png", |
|---|
| 49 |
"{#2}": "prio2.png", |
|---|
| 50 |
"{#3}": "prio3.png", |
|---|
| 51 |
"{o}": "star_off.png", |
|---|
| 52 |
"{*}": "star_on.png", |
|---|
| 53 |
"{OK}": "thumbs-up.png", |
|---|
| 54 |
"{X}": "icon-error.png", |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
class Smileys(Component): |
|---|
| 59 |
|
|---|
| 60 |
implements(IWikiSyntaxProvider, IWikiMacroProvider, ITemplateProvider) |
|---|
| 61 |
|
|---|
| 62 |
# ITemplateProvider methods |
|---|
| 63 |
|
|---|
| 64 |
def get_htdocs_dirs(self): |
|---|
| 65 |
from pkg_resources import resource_filename |
|---|
| 66 |
return [('smileys', resource_filename(__name__, 'htdocs/modern'))] |
|---|
| 67 |
|
|---|
| 68 |
def get_templates_dirs(self): |
|---|
| 69 |
return [] |
|---|
| 70 |
|
|---|
| 71 |
# IWikiSyntaxProvider methods |
|---|
| 72 |
|
|---|
| 73 |
def get_wiki_syntax(self): |
|---|
| 74 |
yield (prepare_regexp(SMILEYS), lambda x, y, z: self._format_smiley(y)) |
|---|
| 75 |
|
|---|
| 76 |
def get_link_resolvers(self): |
|---|
| 77 |
return [] |
|---|
| 78 |
|
|---|
| 79 |
def _format_smiley(self, s): |
|---|
| 80 |
return '<img src="%s" alt="%s" style="vertical-align: bottom" />' % \ |
|---|
| 81 |
(self.env.href.chrome('smileys/img', SMILEYS[s]), s) |
|---|
| 82 |
|
|---|
| 83 |
# IWikiMacroProvider methods |
|---|
| 84 |
|
|---|
| 85 |
def get_macros(self): |
|---|
| 86 |
yield 'ShowSmileys' |
|---|
| 87 |
|
|---|
| 88 |
def get_macro_description(self, name): |
|---|
| 89 |
return ("Renders in a table the list of available smileys. " |
|---|
| 90 |
"Optional argument is the number of columns in the table " |
|---|
| 91 |
"(defaults 3).") |
|---|
| 92 |
|
|---|
| 93 |
def render_macro(self, req, name, content): |
|---|
| 94 |
return render_table(SMILEYS.keys(), content, self._format_smiley) |
|---|