Skip to content

Commit

Permalink
Merge pull request #2748 from getnikola/emoji-sc
Browse files Browse the repository at this point in the history
Emoji shortcode
  • Loading branch information
ralsina committed May 9, 2017
2 parents bb6d8f6 + 20d6e92 commit c5b86a4
Show file tree
Hide file tree
Showing 15 changed files with 6,571 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -13,6 +13,8 @@ Math support changes
Features
--------


* New emoji shortcode
* Add ``SECTION_PATH`` support to move the section indexes to a
user-defined location (Issue #2738)
* Add a list of template variables to documentation (Issues #2328,
Expand Down
7 changes: 7 additions & 0 deletions docs/manual.txt
Expand Up @@ -1057,6 +1057,13 @@ chart
'Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4]
{{% /chart %}}{{% /raw %}}

emoji
Insert an emoji. For example::

{{% emoji crying_face %}}

This generates a ``span`` with ``emoji`` CSS class, so you can style it with a nice font if you want.

gist
Show GitHub gists. If you know the gist's ID, this will show it in your site:

Expand Down
6 changes: 6 additions & 0 deletions nikola/plugin_categories.py
Expand Up @@ -402,6 +402,12 @@ class ShortcodePlugin(BasePlugin):

name = "dummy_shortcode_plugin"

def set_site(self, site):
"""Set Nikola site."""
self.site = site
site.register_shortcode(self.name, self.handler)
return super(ShortcodePlugin, self).set_site(site)


class Importer(Command):
"""Basic structure for importing data into Nikola.
Expand Down
13 changes: 13 additions & 0 deletions nikola/plugins/shortcode/emoji.plugin
@@ -0,0 +1,13 @@
[Core]
name = emoji
module = emoji

[Nikola]
PluginCategory = Shortcode

[Documentation]
author = Roberto Alsina
version = 0.1
website = https://getnikola.com/
description = emoji shortcode

46 changes: 46 additions & 0 deletions nikola/plugins/shortcode/emoji/__init__.py
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# This file is public domain according to its author, Roberto Alsina

"""Emoji directive for reStructuredText."""

import glob
import json
import os

from nikola.plugin_categories import ShortcodePlugin
from nikola import utils

TABLE = {}

LOGGER = utils.get_logger('scan_posts', utils.STDERR_HANDLER)


def _populate():
for fname in glob.glob(os.path.join(os.path.dirname(__file__), 'data', '*.json')):
with open(fname) as inf:
data = json.load(inf)
data = data[list(data.keys())[0]]
data = data[list(data.keys())[0]]
for item in data:
if item['key'] in TABLE:
LOGGER.warning('Repeated emoji {}'.format(item['key']))
else:
TABLE[item['key']] = item['value']


class Plugin(ShortcodePlugin):
"""Plugin for gist directive."""

name = "emoji"

def handler(self, name, filename=None, site=None, data=None, lang=None, post=None):
"""Create HTML for emoji."""
if not TABLE:
self._populate()
try:
output = '''<span class="emoji">{}</span>'''.format(TABLE[name])
except KeyError:
LOGGER.warning('Unknown emoji {}'.format(name))
output = '''<span class="emoji error">{}</span>'''.format(name)

return output, []

0 comments on commit c5b86a4

Please sign in to comment.