Class: Middleman::Gemoji::Converter
- Inherits:
-
Object
- Object
- Middleman::Gemoji::Converter
- Defined in:
- lib/middleman-gemoji/converter.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #convert(content) ⇒ Object
- #emoji_file_exist? ⇒ Boolean
-
#initialize(app, options) ⇒ Converter
constructor
A new instance of Converter.
- #set_base_path ⇒ Object
- #size ⇒ Object
- #src(path) ⇒ Object
- #style ⇒ Object
Constructor Details
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/middleman-gemoji/converter.rb', line 6 def app @app end |
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
6 7 8 |
# File 'lib/middleman-gemoji/converter.rb', line 6 def base_path @base_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/middleman-gemoji/converter.rb', line 6 def @options end |
Instance Method Details
#convert(content) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/middleman-gemoji/converter.rb', line 18 def convert(content) return content if content.blank? content.to_str.gsub(/:([\w+-]+):/) do |match| emoji = Emoji.find_by_alias($1) if emoji image = [] image << %(alt="#{$1}") image << src(emoji.image_filename) image << size if size image << style if style %(<img class="gemoji" #{image.join(' ').strip} />) else match end end end |
#emoji_file_exist? ⇒ Boolean
49 50 51 52 53 |
# File 'lib/middleman-gemoji/converter.rb', line 49 def emoji_file_exist? Dir.exist?( File.join(@app.root, @app.config.source, @options[:emoji_dir], 'unicode') ) end |
#set_base_path ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/middleman-gemoji/converter.rb', line 55 def set_base_path @base_path = 'https://assets-cdn.github.com/images/icons/emoji/' if emoji_file_exist? if /^http/ =~ @app.config[:http_prefix] @base_path = File.join(app.config[:http_prefix], [:emoji_dir]) else @base_path = File.join('/', app.config[:http_prefix], [:emoji_dir]) end end end |
#size ⇒ Object
41 42 43 |
# File 'lib/middleman-gemoji/converter.rb', line 41 def size %(width="#{@options[:size]}" height="#{@options[:size]}") if @options[:size] end |
#src(path) ⇒ Object
37 38 39 |
# File 'lib/middleman-gemoji/converter.rb', line 37 def src(path) %(src="#{File.join(@base_path, path)}") end |
#style ⇒ Object
45 46 47 |
# File 'lib/middleman-gemoji/converter.rb', line 45 def style %(style="#{@options[:style]}") if @options[:style] end |