md_emoji 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  Want to include [emoji](http://www.emoji-cheat-sheet.com/) in your rails app? Well now you can!
4
4
 
5
- :balloon: :smile: :balloon:
5
+ ![:balloon:](https://github.com/mendicant-university/md_emoji/raw/master/vendor/assets/images/emojis/balloon.png)
6
+ ![:smile:](https://github.com/mendicant-university/md_emoji/raw/master/vendor/assets/images/emojis/smile.png)
7
+ ![:balloon:](https://github.com/mendicant-university/md_emoji/raw/master/vendor/assets/images/emojis/balloon.png)
6
8
 
7
- This plugin requires `redcarpet` and `rails` >= 3.1 with the asset pipeline enabled.
9
+ Markdown Emoji was designed to work with the [Redcarpet](https://github.com/tanoku/redcarpet) markdown processor and [Rails 3.1](https://github.com/rails/rails) with the asset pipeline enabled.
10
+
11
+ **Warning** This gem is very new and under heavy development. Use at your own risk :)
8
12
 
9
13
  ## Installation
10
14
 
@@ -24,6 +28,12 @@ markdown = Redcarpet::Markdown.new(MdEmoji::Render)
24
28
  markdown.render("Hello :smile: world!")
25
29
  ```
26
30
 
31
+ Emoji assets will automatically be picked up by the asset pipeline and made available to your app at:
32
+
33
+ `/assets/emojis/<EMOJI_NAME>.png`
34
+
35
+ For a full list of supported emoji, just run `MdEmoji::EMOJI` in your console.
36
+
27
37
  ## Contributing
28
38
 
29
39
  Features and bugs are tracked through [Github Issues](https://github.com/mendicant-university/md_emoji/issues).
@@ -48,6 +58,10 @@ Contact Jordan through [GitHub (@jordanbyron)](https://github.com/jordanbyron) o
48
58
  9. Commit and push your changes.
49
59
  10. Submit a pull request.
50
60
 
61
+ ## Authorship
62
+
63
+ Emoji images are from [emoji-cheat-sheet.com](http://emoji-cheat-sheet.com)'s [github project](https://github.com/arvida/emoji-cheat-sheet.com). This project was inspired by [GitHub's emoji implementation](https://github.com/blog/816-emoji) and hacked together by [Jordan Byron](http://jordanbyron.com).
64
+
51
65
  ## License
52
66
 
53
67
  Copyright (c) 2011 Jordan Byron
@@ -1,8 +1,17 @@
1
1
  module MdEmoji
2
2
  class Render < Redcarpet::Render::HTML
3
- def normal_text(text)
4
- return if text.nil?
3
+ def preprocess(text)
4
+ if include_emoji?(text)
5
+ emoji(text)
6
+ else
7
+ text
8
+ end
9
+ end
5
10
 
11
+ # Replaces valid emoji characters, ie :smile:, with img tags
12
+ #
13
+ # Valid emoji charaters are listed in +MdEmoji::EMOJI+
14
+ def emoji(text)
6
15
  text.gsub(/:(\S+):/) do |emoji|
7
16
  if MdEmoji::EMOJI.include?($1)
8
17
  file_name = "#{$1.gsub('+', 'plus')}.png"
@@ -15,5 +24,12 @@ module MdEmoji
15
24
  end
16
25
  end
17
26
  end
27
+
28
+ private
29
+
30
+ # Returns +true+ if emoji are present in +text+, otherwise returns +false+
31
+ def include_emoji?(text)
32
+ text && text[/:\S+:/]
33
+ end
18
34
  end
19
35
  end
@@ -1,3 +1,3 @@
1
1
  module MdEmoji
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -31,4 +31,16 @@ class MdEmojiTest < ActiveSupport::TestCase
31
31
 
32
32
  assert_equal %{<p>Hello :jordan_byron: world!</p>\n}, parsed_text
33
33
  end
34
+
35
+ test "works with autolink enabled" do
36
+ @markdown = Redcarpet::Markdown.new(MdEmoji::Render, :autolink => true)
37
+
38
+ text = ":wink2: http://www.jordanbyron.com"
39
+ parsed_text = @markdown.render(text)
40
+
41
+ assert parsed_text.include?(%{<img src="/assets/emojis/wink2.png"}),
42
+ "Emoji not present in parsed text: #{parsed_text}"
43
+ assert parsed_text.include?(%{<a href="http://www.jordanbyron.com"}),
44
+ "Hyperlink not present in parsed text: #{parsed_text}"
45
+ end
34
46
  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.1
4
+ version: 0.0.2
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-19 00:00:00.000000000Z
12
+ date: 2012-01-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2157933900 !ruby/object:Gem::Requirement
16
+ requirement: &2164942240 !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: *2157933900
24
+ version_requirements: *2164942240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redcarpet
27
- requirement: &2157933040 !ruby/object:Gem::Requirement
27
+ requirement: &2164941620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,8 +32,8 @@ dependencies:
32
32
  version: 2.0.0b3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2157933040
36
- description: Rails plugin which adds emoji to markdown
35
+ version_requirements: *2164941620
36
+ description: Rails gem which adds emoji parsing to markdown
37
37
  email:
38
38
  - jordan@ducksoupsoftware.com
39
39
  executables: []
@@ -587,7 +587,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
587
587
  version: '0'
588
588
  segments:
589
589
  - 0
590
- hash: -1626333553585938101
590
+ hash: 1364931473961737296
591
591
  required_rubygems_version: !ruby/object:Gem::Requirement
592
592
  none: false
593
593
  requirements:
@@ -596,10 +596,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
596
596
  version: '0'
597
597
  segments:
598
598
  - 0
599
- hash: -1626333553585938101
599
+ hash: 1364931473961737296
600
600
  requirements: []
601
601
  rubyforge_project:
602
- rubygems_version: 1.8.6
602
+ rubygems_version: 1.8.15
603
603
  signing_key:
604
604
  specification_version: 3
605
605
  summary: Markdown emoji for Rails