Module: PlaceholdIt::Common

Included in:
ControllerExtensions, ViewExtensions
Defined in:
lib/placehold_it/common.rb

Instance Method Summary collapse

Instance Method Details

#placeholder_image_url(size = "200x150", *args) ⇒ Object

Source: gist.github.com/473254 Thanks very much to Zeke Sikelianos (github.com/zeke)



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/placehold_it/common.rb', line 7

def placeholder_image_url(size="200x150", *args)
  options = args.extract_options!
  # If fg is present, bg is required (and vice versa)
  options[:bg] = "FFF" if options[:fg].present? && options[:bg].blank?
  options[:fg] = "000" if options[:bg].present? && options[:fg].blank?
  parts = []
  parts << "http://placehold.it"
  parts << "/#{size}"
  parts << "/#{options[:bg]}" if options[:bg].present?
  parts << "/#{options[:fg]}" if options[:fg].present?
  parts << "&text=#{options[:text]}" if options[:text].present?
  parts.join ""
end