Module: Fluxbit::Gravatar
- Defined in:
- lib/fluxbit/gravatar.rb
Overview
Standalone Gravatar URL generator.
Can be used independently of the component:
Fluxbit::Gravatar.url(email: "user@example.com")
Fluxbit::Gravatar.url(email: "user@example.com", size: :lg, rating: :g)
Or via the helper in views:
fx_gravatar_url(email: "user@example.com")
From: github.com/chrislloyd/gravtastic/blob/master/lib/gravtastic.rb chrislloyd.github.io/gravtastic/
Constant Summary collapse
- ABBREVIATIONS =
{ size: "s", default: "d", rating: "r", forcedefault: "f" }.freeze
Class Method Summary collapse
-
.gravatar_id(email) ⇒ String
Returns the MD5 hash of the email, which Gravatar uses as identifier.
-
.url(email:, rating: nil, secure: true, filetype: nil, default: nil, size: nil, name: nil, initials: nil) ⇒ String
Generates a Gravatar URL for the given email.
Class Method Details
.gravatar_id(email) ⇒ String
Returns the MD5 hash of the email, which Gravatar uses as identifier.
59 60 61 |
# File 'lib/fluxbit/gravatar.rb', line 59 def gravatar_id(email) Digest::MD5.hexdigest(email.to_s.downcase) end |
.url(email:, rating: nil, secure: true, filetype: nil, default: nil, size: nil, name: nil, initials: nil) ⇒ String
Generates a Gravatar URL for the given email.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fluxbit/gravatar.rb', line 40 def url(email:, rating: nil, secure: true, filetype: nil, default: nil, size: nil, name: nil, initials: nil) styles = config.gravatar_styles = resolve_option(, collection: styles[:rating], fallback: config.) filetype = resolve_option(filetype, collection: styles[:filetype], fallback: config.filetype) default = resolve_option(default, collection: styles[:default], fallback: config.default) size_px = resolve_size(size, styles[:size]) params = { rating: , default: default, size: size_px } params[:name] = name if name.present? params[:initials] = initials if initials.present? hostname(secure) + filename(email, filetype) + "?" + to_query((params)) end |