Skip to content

Instantly share code, notes, and snippets.

@scottmatthewman
Created December 13, 2011 10:58
Show Gist options
  • Save scottmatthewman/1471694 to your computer and use it in GitHub Desktop.
Save scottmatthewman/1471694 to your computer and use it in GitHub Desktop.
Add a helper to aid prototyping using Placehold.it images
<%= placeholder_image(728, 90, name: 'IAB Leaderboard ad', background_color: 'ccc') %>
module PrototypingHelper
def placeholder_image(width, height, options = {})
# `.with_indifferent_access` allows for people using Ruby 1.9's JSON-like
# `key: value`, syntax, which tends to create string-based, rather than
# symbol-based, keys
options.merge!({
:text => "",
:background_color => '999',
:color => 'fff'
}.with_indifferent_access)
logger.info options.inspect
url = "http://placehold.it/#{width}x#{height}/#{options[:background_color]}/#{options[:color]}/"
url += "&text=#{CGI::escape(options[:text])}" unless options[:text].blank?
image_tag(url, alt: options[:text])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment