Add support for emojione
This commit is contained in:
+9
-1
@@ -49,7 +49,7 @@ module Precious
|
||||
class App < Sinatra::Base
|
||||
register Mustache::Sinatra
|
||||
include Precious::Helpers
|
||||
|
||||
|
||||
dir = File.dirname(File.expand_path(__FILE__))
|
||||
|
||||
# Detect unsupported browsers.
|
||||
@@ -130,6 +130,14 @@ module Precious
|
||||
Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||
end
|
||||
|
||||
get '/emoji/:name' do
|
||||
begin
|
||||
[200, {'Content-Type' => 'image/png'}, emoji(params['name'])]
|
||||
rescue ArgumentError
|
||||
not_found
|
||||
end
|
||||
end
|
||||
|
||||
get '/data/*' do
|
||||
if page = wiki_page(params[:splat].first).page
|
||||
page.raw_data
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require 'gemojione'
|
||||
|
||||
module Precious
|
||||
module Helpers
|
||||
|
||||
EMOJI_PATHNAME = Pathname.new(Gemojione.index.images_path).freeze
|
||||
|
||||
# Extract the path string that Gollum::Wiki expects
|
||||
def extract_path(file_path)
|
||||
return nil if file_path.nil?
|
||||
@@ -51,5 +56,13 @@ module Precious
|
||||
return mustache :error
|
||||
end
|
||||
|
||||
def emoji(name)
|
||||
if emoji = Gemojione.index.find_by_name(name)
|
||||
IO.read(EMOJI_PATHNAME.join("#{emoji['unicode']}.png"))
|
||||
else
|
||||
fail ArgumentError, "emoji `#{name}' not found"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -849,3 +849,9 @@ ul.actions {
|
||||
.clearfloats {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.emoji {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
vertical-align: -18%;
|
||||
}
|
||||
|
||||
@@ -211,6 +211,11 @@ var MarkDownHelp = [
|
||||
{
|
||||
menuName: 'Escaping',
|
||||
data: '<p>If you want to use a special Markdown character in your document (such as displaying literal asterisks), you can escape the character with the backslash (<code>\\</code>). Markdown will ignore the character directly after a backslash.'
|
||||
},
|
||||
|
||||
{
|
||||
menuName: 'Emoji',
|
||||
data: '<p>See the <a href="http://emojione.com/demo/" target="_blank">EmojiOne demo</a> for all available emoji. To include one, wrap the emoji name in colons and use underscores instead of spaces (e.g. :heart: or :point_up:).'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user