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
+1
View File
@@ -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. | | --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> | | --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> | | --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. | | --no-edit | none | Disable the feature of editing pages. |
| --live-preview | none | Enable the live preview feature in page editor. | | --live-preview | none | Enable the live preview feature in page editor. |
| --no-live-preview | none | Disable 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 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 wiki_options[:js] = true
end 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 opts.on("--no-edit", "Disable the feature of editing pages.") do
wiki_options[:allow_editing] = false wiki_options[:allow_editing] = false
end end
+2 -1
View File
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.name = 'gollum' s.name = 'gollum'
s.version = '4.0.1' s.version = '4.0.1'
s.date = '2015-09-20' s.date = '2016-05-19'
s.rubyforge_project = 'gollum' s.rubyforge_project = 'gollum'
s.license = 'MIT' s.license = 'MIT'
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
s.add_dependency 'sinatra', '~> 1.4', '>= 1.4.4' s.add_dependency 'sinatra', '~> 1.4', '>= 1.4.4'
s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0'] s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0']
s.add_dependency 'useragent', '~> 0.16.2' 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 'rack-test', '~> 0.6.2'
s.add_development_dependency 'shoulda', '~> 3.5.0' s.add_development_dependency 'shoulda', '~> 3.5.0'
+8
View File
@@ -130,6 +130,14 @@ module Precious
Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
end end
get '/emoji/:name' do
begin
[200, {'Content-Type' => 'image/png'}, emoji(params['name'])]
rescue ArgumentError
not_found
end
end
get '/data/*' do get '/data/*' do
if page = wiki_page(params[:splat].first).page if page = wiki_page(params[:splat].first).page
page.raw_data page.raw_data
+13
View File
@@ -1,6 +1,11 @@
# ~*~ encoding: utf-8 ~*~ # ~*~ encoding: utf-8 ~*~
require 'gemojione'
module Precious module Precious
module Helpers module Helpers
EMOJI_PATHNAME = Pathname.new(Gemojione.index.images_path).freeze
# Extract the path string that Gollum::Wiki expects # Extract the path string that Gollum::Wiki expects
def extract_path(file_path) def extract_path(file_path)
return nil if file_path.nil? return nil if file_path.nil?
@@ -51,5 +56,13 @@ module Precious
return mustache :error return mustache :error
end 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
end end
+6
View File
@@ -849,3 +849,9 @@ ul.actions {
.clearfloats { .clearfloats {
clear: both; clear: both;
} }
.emoji {
width: 20px;
height: 20px;
vertical-align: -18%;
}
@@ -211,6 +211,11 @@ var MarkDownHelp = [
{ {
menuName: 'Escaping', 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.' 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 assert_match /not so big smelly creatures/, last_response.body
end 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 def app
Precious::App Precious::App
end end