Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roberto Alsina
committed
May 8, 2017
1 parent
ef84f85
commit 22d981c
Showing
14 changed files
with
6,559 additions
and
6 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
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
# -*- coding: utf-8 -*- | |||
# This file is public domain according to its author, Brian Hsu | |||
|
|||
"""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) | |||
|
|||
|
|||
class Plugin(ShortcodePlugin): | |||
"""Plugin for gist directive.""" | |||
|
|||
name = "emoji" | |||
|
|||
def _populate(self): | |||
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'] | |||
|
|||
|
|||
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, [] |
Oops, something went wrong.