Last active
August 29, 2015 14:06
-
-
Save minimum2scp/1197d06dd8e5b63a98a9 to your computer and use it in GitHub Desktop.
tdiary-core の lib/tdiary/core_ext.rb の emojify メソッドをローカルで適当に変更してるやつ (SSL化+存在する絵文字のみに絞り込み)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 9d451e3335d5d841fb3e76f66361413876d8f0d5 Mon Sep 17 00:00:00 2001 | |
| From: YAMADA Tsuyoshi tyamada@minimum2scp.org> | |
| Date: Tue, 16 Sep 2014 16:55:40 +0900 | |
| Subject: [PATCH] lib/tdiary/core_ext.rb: emojify check if emoji exists, and | |
| use SSL site (experimental) | |
| --- | |
| lib/tdiary/core_ext.rb | 27 ++++++++++++++++++++++----- | |
| 1 file changed, 22 insertions(+), 5 deletions(-) | |
| diff --git a/lib/tdiary/core_ext.rb b/lib/tdiary/core_ext.rb | |
| index 466b935..655b2fb 100644 | |
| --- a/lib/tdiary/core_ext.rb | |
| +++ b/lib/tdiary/core_ext.rb | |
| @@ -34,12 +34,29 @@ class String | |
| end | |
| def emojify | |
| + ## NOTE: @emojis に入れているが、String のインスタンス変数なのでキャッシュできていないに等しい | |
| + unless @emojis | |
| + require 'uri' | |
| + require 'nokogiri' | |
| + ## NOTE: UA ちゃんと名乗ってないし SSL 使ってない | |
| + html = ->(uri){ Net::HTTP.start(uri.host,uri.port){ |http| http.get(uri.path) } }[URI.parse "http://www.emoji-cheat-sheet.com/"].body | |
| + doc = Nokogiri::HTML(html) | |
| + ## NOTE: github にある、ソース中の index.html と www.emoji-cheat-sheet.com の index.html は異なるので doc.css の取り方とか変える必要がある | |
| + @emojis = doc.css("#content span.emoji").map{|span| span["data-src"].sub('graphics/emojis/','').sub('.png', '')} | |
| + end | |
| self.gsub(/:([a-zA-Z0-9_+-]+):/) do |emoji| | |
| - emoji = ":plus1:" if emoji == ":+1:" | |
| - emoji.gsub!(":", "").downcase! | |
| - #"<img src='http://www.emoji-cheat-sheet.com/graphics/emojis/#{emoji}.png' width='20' height='20' title='#{emoji}' alt='#{emoji}' class='emoji' />" | |
| - #"<img src='https://raw.githubusercontent.com/arvida/emoji-cheat-sheet.com/master/public/graphics/emojis/#{emoji}.png' width='20' height='20' title='#{emoji}' alt='#{emoji}' class='emoji' />" | |
| - "<img src='https://d1ae2obkbc7sin.cloudfront.net/graphics/emojis/#{emoji}.png' width='20' height='20' title='#{emoji}' alt='#{emoji}' class='emoji' />" | |
| + ## NOTE: replace なんていう変数がだめすぎ | |
| + replace = (emoji == ":+1:") ? ":plus1:" : emoji.dup | |
| + replace = replace.gsub(":", "").downcase! | |
| + if @emojis.include?(replace) | |
| + emoji = replace | |
| + #"<img src='http://www.emoji-cheat-sheet.com/graphics/emojis/#{emoji}.png' width='20' height='20' title='#{emoji}' alt='#{emoji}' class='emoji' />" | |
| + ## NOTE: SSLサイト、公式ないっぽい | |
| + #"<img src='https://raw.githubusercontent.com/arvida/emoji-cheat-sheet.com/master/public/graphics/emojis/#{emoji}.png' width='20' height='20' title='#{emoji}' alt='#{emoji}' class='emoji' />" | |
| + "<img src='https://d1ae2obkbc7sin.cloudfront.net/graphics/emojis/#{emoji}.png' width='20' height='20' title='#{emoji}' alt='#{emoji}' class='emoji' />" | |
| + else | |
| + emoji | |
| + end | |
| end | |
| end | |
| end | |
| -- | |
| 2.1.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment