Skip to content

Instantly share code, notes, and snippets.

@thephw
Last active October 13, 2015 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thephw/4237725 to your computer and use it in GitHub Desktop.
Save thephw/4237725 to your computer and use it in GitHub Desktop.
Kittenify-Rails lets you easily swap out your placeholder images in from placehold it with kittens via a view helper. Sexy hotness. And seriously cute.
export KITTENIFY=1
Kittenify-Rails lets you easily swap out your placeholder images in from placehold it with kittens via a view helper. Sexy hotness. And seriously cute.
module ApplicationHelper
def hold_it(width, height, text = "")
text = text.gsub(/\s/, '+')
if ENV["KITTENIFY"].to_i == 1
url = kitten_it(width, height, text)
else
url = placehold_it(width, height, text)
end
image_tag url, size: "#{width}x#{height}"
end
def placehold_it(width, height, text = "")
"http://placehold.it/#{width}x#{height}&text=#{text}+(#{width}x#{height})"
end
def kitten_it(width, height, text = "", grayscale = false)
"http://placekitten.com/#{grayscale ? "g/" : ""}#{width}/#{height}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment