Class: Mumukit::ContentType::Emoji::Render
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- Mumukit::ContentType::Emoji::Render
- Defined in:
- lib/mumukit/content_type/emoji.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Render
constructor
A new instance of Render.
- #list_item(text, list_type) ⇒ Object
- #paragraph(text) ⇒ Object
-
#replace_emoji(text) ⇒ Object
Replaces valid emoji characters, ie :smile:, with img tags.
Constructor Details
#initialize(options = {}) ⇒ Render
Returns a new instance of Render.
5 6 7 8 |
# File 'lib/mumukit/content_type/emoji.rb', line 5 def initialize( = {}) @options = .merge(:no_intra_emphasis => true) super @options end |
Instance Method Details
#list_item(text, list_type) ⇒ Object
16 17 18 |
# File 'lib/mumukit/content_type/emoji.rb', line 16 def list_item(text, list_type) "<li>#{replace_emoji(text)}</li>" end |
#paragraph(text) ⇒ Object
10 11 12 13 14 |
# File 'lib/mumukit/content_type/emoji.rb', line 10 def paragraph(text) text.gsub!("\n", "<br>\n") if @options[:hard_wrap] "<p>#{replace_emoji(text)}</p>\n" end |
#replace_emoji(text) ⇒ Object
Replaces valid emoji characters, ie :smile:, with img tags
Valid emoji charaters are listed in Mumukit::ContentType::Emoji::EMOJI
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mumukit/content_type/emoji.rb', line 23 def replace_emoji(text) emojis = Mumuki::Emojis::EMOJIS text.gsub(/:([^\s:])+:/) do |short_name| short_code = short_name.gsub(':', '') emoji = emojis[short_code] if emoji %{<i class="mu-emoji #{emoji['ca']} _#{emoji['co']}" title="#{short_name}"></i>} else short_name end end end |