/custom.js' file is used (must be committed).") do
wiki_options[:js] = true
end
+ opts.on("--emoji", "Parse and interpret emoji tags (e.g. :heart:).") do
+ wiki_options[:emoji] = true
+ end
opts.on("--no-edit", "Disable the feature of editing pages.") do
wiki_options[:allow_editing] = false
end
diff --git a/gollum.gemspec b/gollum.gemspec
index 3be441f4..84be9fe6 100644
--- a/gollum.gemspec
+++ b/gollum.gemspec
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.name = 'gollum'
s.version = '4.0.1'
- s.date = '2015-09-20'
+ s.date = '2016-05-19'
s.rubyforge_project = 'gollum'
s.license = 'MIT'
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
s.add_dependency 'sinatra', '~> 1.4', '>= 1.4.4'
s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0']
s.add_dependency 'useragent', '~> 0.16.2'
+ s.add_dependency 'gemojione', '~> 2'
s.add_development_dependency 'rack-test', '~> 0.6.2'
s.add_development_dependency 'shoulda', '~> 3.5.0'
diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb
index d4498185..3843d18c 100644
--- a/lib/gollum/app.rb
+++ b/lib/gollum/app.rb
@@ -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
diff --git a/lib/gollum/helpers.rb b/lib/gollum/helpers.rb
index 3e057f3e..d140b932 100644
--- a/lib/gollum/helpers.rb
+++ b/lib/gollum/helpers.rb
@@ -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
diff --git a/lib/gollum/public/gollum/css/gollum.css b/lib/gollum/public/gollum/css/gollum.css
index cd577b78..de90e47d 100755
--- a/lib/gollum/public/gollum/css/gollum.css
+++ b/lib/gollum/public/gollum/css/gollum.css
@@ -849,3 +849,9 @@ ul.actions {
.clearfloats {
clear: both;
}
+
+.emoji {
+ width: 20px;
+ height: 20px;
+ vertical-align: -18%;
+}
diff --git a/lib/gollum/public/gollum/javascript/editor/langs/markdown.js b/lib/gollum/public/gollum/javascript/editor/langs/markdown.js
index 851b7381..b1f917eb 100644
--- a/lib/gollum/public/gollum/javascript/editor/langs/markdown.js
+++ b/lib/gollum/public/gollum/javascript/editor/langs/markdown.js
@@ -211,6 +211,11 @@ var MarkDownHelp = [
{
menuName: 'Escaping',
data: '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 (\\). Markdown will ignore the character directly after a backslash.'
+ },
+
+ {
+ menuName: 'Emoji',
+ data: '
See the EmojiOne demo 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:).'
}
]
}
diff --git a/test/test_app.rb b/test/test_app.rb
index 6f1b7294..32ba29ea 100644
--- a/test/test_app.rb
+++ b/test/test_app.rb
@@ -707,6 +707,18 @@ context "Frontend with lotr" do
assert_match /not so big smelly creatures/, last_response.body
end
+ test "existing emoji" do
+ get "/emoji/heart"
+ assert_equal 200, last_response.status
+ assert_equal 'image/png', last_response.headers['Content-Type']
+ assert_equal [137, 80, 78, 71, 13, 10, 26, 10], last_response.body.each_byte.to_a[0..7]
+ end
+
+ test "missing emoji" do
+ get "/emoji/oggy_was_here"
+ assert_equal 404, last_response.status
+ end
+
def app
Precious::App
end