Class: Mumukit::ContentType::Emoji::Render

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/mumukit/content_type/emoji.rb

Direct Known Subclasses

Markdown::HTML

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Render

Returns a new instance of Render.



107
108
109
110
# File 'lib/mumukit/content_type/emoji.rb', line 107

def initialize(options={})
  @options = options.merge(:no_intra_emphasis => true)
  super @options
end

Instance Method Details

#list_item(text, list_type) ⇒ Object



118
119
120
# File 'lib/mumukit/content_type/emoji.rb', line 118

def list_item(text, list_type)
  "<li>#{replace_emoji(text)}</li>"
end

#paragraph(text) ⇒ Object



112
113
114
115
116
# File 'lib/mumukit/content_type/emoji.rb', line 112

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



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/mumukit/content_type/emoji.rb', line 125

def replace_emoji(text)
  text.gsub(/:([^\s:])+:/) do |emoji|

    emoji_code = emoji #.gsub("|", "_")
    emoji      = emoji_code.gsub(":", "")

    if Mumukit::ContentType::Emoji::EMOJI.include?(emoji)
      file_name    = "#{emoji.gsub('+', 'plus')}.png"
      default_size = %{height="20" width="20"}

      %{<img src="/assets/emojis/#{file_name}" class="emoji" } +
        %{title="#{emoji_code}" alt="#{emoji_code}" #{default_size}>}
    else
      emoji_code
    end
  end
end