I'm attempting to build my first ruby gem that uses Middleman Frontmatter to display Gravatar images.
My goal is to use frontmatter like this as an input:
---
email: [email protected]
---
...and output the associated Gravatar image in a .erb file like this:
<%= gravatar_for(article.data.email) %>
Here is what I have come up with based on the instructions provided by Gravatar for displaying images via ruby:
require "gravatar/version"
require 'digest/md5'
module Gravatar
def gravatar_for(email)
hash = Digest::MD5.hexdigest(email.chomp.downcase)
"http://www.gravatar.com/avatar/#{hash}"
end
end
The error I receive when the code is run is
NoMethodError at/
undefined method `gravatar_for'...
The gem and repo can be found here: https://rubygems.org/gems/snagagrav
I assume you've successfully tried adding something like this to your config.rb:
Then in your template:
That works for me. Seems like you need to turn your gem into a MiddleMan extension and register it.