Permalink
Browse files

Codestyle

  • Loading branch information...
1 parent 4fa2612 commit 9873bffa926cb469392cc065f99f5e09411c8d26 @mscoutermarsh mscoutermarsh committed Dec 1, 2015
Showing with 12 additions and 4 deletions.
  1. +4 −1 .rubocop.yml
  2. +6 −2 app/emoji_helper.rb
  3. +2 −1 spec/emoji_helper_spec.rb
View
@@ -1,4 +1,7 @@
Documentation:
Enabled: false
Metrics/LineLength:
- Max: 120
+ Max: 140
+AllCops:
+ Exclude:
+ - 'bin/*'
View
@@ -1,10 +1,14 @@
module EmojiHelper
+ IMAGE_PARAMS = %(style="vertical-align:middle" width="20" height="20")
+
def self.emojify(content)
content = Rumoji.encode(content)
content.to_str.gsub(/:([\w+-]+):/) do |match|
- if emoji = Emoji.find_by_alias($1)
- %(<img alt="#$1" src="#{ShareMeow::App.base_url}/images/emoji/#{emoji.image_filename}" style="vertical-align:middle" width="20" height="20" />)
+ emoji = Emoji.find_by_alias(Regexp.last_match(1))
+
+ if emoji
+ %(<img alt="#{Regexp.last_match(1)}" src="#{ShareMeow::App.base_url}/images/emoji/#{emoji.image_filename}" #{IMAGE_PARAMS} />)
else
match
end
@@ -5,7 +5,8 @@
it 'turns unicode into emoji' do
content = described_class.emojify('My emoji content 😀')
- expect(content).to eq "My emoji content <img alt=\"grinning\" src=\"#{ShareMeow::App.base_url}/images/emoji/unicode/1f600.png\" " \
+ expect(content).to eq "My emoji content <img alt=\"grinning\" " \
+ "src=\"#{ShareMeow::App.base_url}/images/emoji/unicode/1f600.png\" " \
"style=\"vertical-align:middle\" width=\"20\" height=\"20\" />"
end

0 comments on commit 9873bff

Please sign in to comment.