md_emoji 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  module MdEmoji
2
2
  class Render < Redcarpet::Render::HTML
3
- def preprocess(text)
3
+ def normal_text(text)
4
4
  if include_emoji?(text)
5
- emoji(text)
5
+ replace_emoji(text)
6
6
  else
7
7
  text
8
8
  end
@@ -11,14 +11,14 @@ module MdEmoji
11
11
  # Replaces valid emoji characters, ie :smile:, with img tags
12
12
  #
13
13
  # Valid emoji charaters are listed in +MdEmoji::EMOJI+
14
- def emoji(text)
14
+ def replace_emoji(text)
15
15
  text.gsub(/:(\S+):/) do |emoji|
16
16
  if MdEmoji::EMOJI.include?($1)
17
17
  file_name = "#{$1.gsub('+', 'plus')}.png"
18
18
  default_size = %{height="20" width="20"}
19
19
 
20
20
  %{<img src="/assets/emojis/#{file_name}" class="emoji" } +
21
- %{title="#{emoji}" alt="#{emoji} #{default_size}">}
21
+ %{title="#{emoji}" alt="#{emoji}" #{default_size}>}
22
22
  else
23
23
  emoji
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module MdEmoji
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -11,8 +11,7 @@ class MdEmojiTest < ActiveSupport::TestCase
11
11
 
12
12
  parsed_text = @markdown.render(text)
13
13
 
14
- assert parsed_text.include? %{<img src="/assets/emojis/smile.png"}
15
-
14
+ assert_emoji 'smile', parsed_text
16
15
  end
17
16
 
18
17
  test "works with +1 emoji" do
@@ -20,8 +19,7 @@ class MdEmojiTest < ActiveSupport::TestCase
20
19
 
21
20
  parsed_text = @markdown.render(text)
22
21
 
23
- assert parsed_text.include? %{<img src="/assets/emojis/plus1.png"}
24
-
22
+ assert_emoji 'plus1', parsed_text
25
23
  end
26
24
 
27
25
  test "skips emoji which aren't supported" do
@@ -33,14 +31,31 @@ class MdEmojiTest < ActiveSupport::TestCase
33
31
  end
34
32
 
35
33
  test "works with autolink enabled" do
34
+ skip "autolink messes everything up :("
35
+
36
36
  @markdown = Redcarpet::Markdown.new(MdEmoji::Render, :autolink => true)
37
37
 
38
38
  text = ":wink2: http://www.jordanbyron.com"
39
39
  parsed_text = @markdown.render(text)
40
40
 
41
- assert parsed_text.include?(%{<img src="/assets/emojis/wink2.png"}),
42
- "Emoji not present in parsed text: #{parsed_text}"
41
+ assert_emoji 'wink2', parsed_text
43
42
  assert parsed_text.include?(%{<a href="http://www.jordanbyron.com"}),
44
43
  "Hyperlink not present in parsed text: #{parsed_text}"
45
44
  end
45
+
46
+ test "does not render emoji in codeblocks" do
47
+ text = %{Look at my codez
48
+ ```
49
+ def hello
50
+ :wink:
51
+ end
52
+ ```
53
+ Everything is ok :smile:}
54
+
55
+ parsed_text = @markdown.render(text)
56
+
57
+ assert_emoji 'smile', parsed_text
58
+ refute_emoji 'wink', parsed_text
59
+ end
60
+
46
61
  end
data/test/test_helper.rb CHANGED
@@ -10,3 +10,17 @@ Rails.backtrace_cleaner.remove_silencers!
10
10
 
11
11
  # Load support files
12
12
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
13
+
14
+ private
15
+
16
+ def assert_emoji(emoji, text)
17
+ assert include_emoji?(emoji, text), "Emoji not found!"
18
+ end
19
+
20
+ def refute_emoji(emoji, text)
21
+ refute include_emoji?(emoji, text), "Emoji found!"
22
+ end
23
+
24
+ def include_emoji?(emoji, text)
25
+ text.include?(%{<img src="/assets/emojis/#{emoji}.png"})
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md_emoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-20 00:00:00.000000000Z
12
+ date: 2012-01-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2164942240 !ruby/object:Gem::Requirement
16
+ requirement: &2169729360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2164942240
24
+ version_requirements: *2169729360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redcarpet
27
- requirement: &2164941620 !ruby/object:Gem::Requirement
27
+ requirement: &2169728760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.0.0b3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2164941620
35
+ version_requirements: *2169728760
36
36
  description: Rails gem which adds emoji parsing to markdown
37
37
  email:
38
38
  - jordan@ducksoupsoftware.com
@@ -587,7 +587,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
587
587
  version: '0'
588
588
  segments:
589
589
  - 0
590
- hash: 1364931473961737296
590
+ hash: 1133397691911705144
591
591
  required_rubygems_version: !ruby/object:Gem::Requirement
592
592
  none: false
593
593
  requirements:
@@ -596,7 +596,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
596
596
  version: '0'
597
597
  segments:
598
598
  - 0
599
- hash: 1364931473961737296
599
+ hash: 1133397691911705144
600
600
  requirements: []
601
601
  rubyforge_project:
602
602
  rubygems_version: 1.8.15