Skip to content

Commit

Permalink
Merge pull request #184 from dejan/emoji_unicode
Browse files Browse the repository at this point in the history
Use emoji unicode instead of images
  • Loading branch information
dejan authored Dec 4, 2021
2 parents 46efb51 + 2e6664d commit cbdb35d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 42 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
auto_html (2.0.2)
gemoji (~> 2.1)
gemoji (~> 4.0.0.rc2)
redcarpet (~> 3.5)
rinku (~> 2.0)

Expand All @@ -11,14 +11,14 @@ GEM
specs:
ast (2.4.2)
diff-lcs (1.4.4)
gemoji (2.1.0)
gemoji (4.0.0.rc3)
parallel (1.21.0)
parser (3.0.3.1)
ast (~> 2.4.1)
rainbow (3.0.0)
rake (13.0.6)
redcarpet (3.5.1)
regexp_parser (2.1.1)
regexp_parser (2.2.0)
rexml (3.2.5)
rinku (2.0.6)
rspec (3.10.0)
Expand All @@ -33,7 +33,7 @@ GEM
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rspec-support (3.10.3)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.23.0)
Expand All @@ -45,7 +45,7 @@ GEM
rubocop-ast (>= 1.12.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.13.0)
rubocop-ast (1.14.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
unicode-display_width (2.1.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ comment_format.call("Hello!\n\n Checkout out my blog: http://rors.org :point_lef

Bellow is the list of bundled filters along with their optional arguments on initialization and their default values.

* `AutoHtml::Emoji`, width: 20, height: 20, asset_root: '/images'
* `AutoHtml::Emoji`
* `AutoHtml::HtmlEscape`
* `AutoHtml::Image`, proxy: nil, alt: nil
* `AutoHtml::Link`, target: nil, rel: nil
Expand Down
2 changes: 1 addition & 1 deletion auto_html.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
gem.homepage = 'https://github.com/dejan/auto_html'
gem.license = 'MIT'

gem.add_dependency 'gemoji', '~> 2.1'
gem.add_dependency 'gemoji', '~> 4.0.0.rc2'
gem.add_dependency 'redcarpet', '~> 3.5'
gem.add_dependency 'rinku', '~> 2.0'

Expand Down
32 changes: 1 addition & 31 deletions lib/auto_html/emoji.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,10 @@
module AutoHtml
# Emoji filter
class Emoji
def initialize(asset_root: '/images', width: 20, height: 20)
@asset_root = asset_root
@width = width
@height = height
end

def call(text)
text.gsub(self.class.emoji_pattern) do
name = Regexp.last_match(1)
alt = ":#{name}:"
html_options = {
src: emoji_url(name),
class: 'emoji',
title: alt,
alt: alt,
height: @width,
witdh: @height,
align: 'absmiddle'
}
TagHelper.tag(:img, html_options)
::Emoji.find_by_alias(name).raw
end
end

Expand All @@ -36,19 +20,5 @@ def self.emoji_pattern
def self.emoji_names
::Emoji.all.map(&:aliases).flatten.sort
end

private

def emoji_url(name)
File.join(@asset_root, asset_path(name))
end

def asset_path(name)
File.join('emoji', emoji_filename(name))
end

def emoji_filename(name)
::Emoji.find_by_alias(name).image_filename
end
end
end
5 changes: 1 addition & 4 deletions spec/auto_html/emoji_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

RSpec.describe AutoHtml::Emoji do
it 'converts emoji to HTML' do
expect(subject.call(':joy:')).to eq(
'<img src="/images/emoji/unicode/1f602.png" class="emoji" title=":joy:" '\
'alt=":joy:" height="20" witdh="20" align="absmiddle" />'
)
expect(subject.call(':joy:')).to eq('😂')
end
end

0 comments on commit cbdb35d

Please sign in to comment.