diff --git a/README.md b/README.md index 7e41ad54..9bbc8de2 100644 --- a/README.md +++ b/README.md @@ -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.3,5 | | --js | none | Tell Gollum to inject custom JS into each page. Uses `custom.js` from repository root.3,5 | +| --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. | diff --git a/bin/gollum b/bin/gollum index 2513536a..b47875ef 100755 --- a/bin/gollum +++ b/bin/gollum @@ -99,6 +99,9 @@ MSG opts.on("--js", "Inject custom JavaScript into each page. The '/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