Module: UriHelper

Defined in:
app/helpers/uri_helper.rb

Instance Method Summary collapse

Instance Method Details

#favicon_icon(url) ⇒ Object


12
13
14
# File 'app/helpers/uri_helper.rb', line 12

def favicon_icon(url)
  image_tag favicon_url(url), width: 16, height: 16, alt: '', title: ''
end

#favicon_url(url) ⇒ Object


8
9
10
# File 'app/helpers/uri_helper.rb', line 8

def favicon_url(url)
  "//www.google.com/s2/favicons?domain=#{host_from_url(url)}"
end

#gravatar_url(email, args = {}) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'app/helpers/uri_helper.rb', line 16

def gravatar_url(email, args = {})
  # include MD5 gem, should be part of standard ruby install
  # require 'digest/md5'
  # create the md5 hash
  hash = Digest::MD5.hexdigest(email.downcase)

  # compile URL which can be used in <img src="RIGHT_HERE"...
  "//www.gravatar.com/avatar/#{hash}?s=#{args[:size] || 35}"
end

#host_from_url(url) ⇒ Object


2
3
4
5
6
# File 'app/helpers/uri_helper.rb', line 2

def host_from_url(url)
  URI(url).host
rescue
  nil
end