Merge pull request #1126 from svoop/emoji

Support for emoji
This commit is contained in:
Dawa Ometto
2016-06-09 16:43:52 +02:00
8 changed files with 52 additions and 3 deletions
+2 -1
View File
@@ -27,7 +27,7 @@ For a quick impression of gollum, see [this video](https://www.youtube.com/watch
## SYSTEM REQUIREMENTS
| Operating System | Ruby | Adapters | Supported |
| Operating System | Ruby | Adapters | Supported |
| ---------------- | -------------- | ------------------ | --------- |
| Unix/Linux-like | Ruby 1.9.3+ | all except [RJGit](https://github.com/repotag/rjgit) | yes |
| Unix/Linux-like | [JRuby](https://github.com/jruby/jruby) (1.9.3+ compatible) | [RJGit](https://github.com/repotag/rjgit) | yes |
@@ -143,6 +143,7 @@ Gollum comes with the following command line options:
| --page-file-dir | [PATH] | Specify the subdirectory for all pages. If set, Gollum will only serve pages from this directory and its subdirectories. Default: repository root. |
| --css | none | Tell Gollum to inject custom CSS into each page. Uses `custom.css` from repository root.<sup>3,5</sup> |
| --js | none | Tell Gollum to inject custom JS into each page. Uses `custom.js` from repository root.<sup>3,5</sup> |
| --emoji | none | Parse and interpret emoji tags (e.g. :heart:). |
| --no-edit | none | Disable the feature of editing pages. |
| --live-preview | none | Enable the live preview feature in page editor. |
| --no-live-preview | none | Disable the live preview feature in page editor. |
+3
View File
@@ -99,6 +99,9 @@ MSG
opts.on("--js", "Inject custom JavaScript into each page. The '<git-repo>/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
+2 -1
View File
@@ -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'
+9 -1
View File
@@ -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
+13
View File
@@ -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
+6
View File
@@ -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:).'
}
]
}
+12
View File
@@ -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