Created
December 13, 2011 10:58
-
-
Save scottmatthewman/1471694 to your computer and use it in GitHub Desktop.
Add a helper to aid prototyping using Placehold.it images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= placeholder_image(728, 90, name: 'IAB Leaderboard ad', background_color: 'ccc') %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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