Sha256: 91bb35f1032e80d9d75c6dc7ac41be2f0ab116ab92f73ca7ab247dd82b4aa1ba

Contents?: true

Size: 906 Bytes

Versions: 5

Compression:

Stored size: 906 Bytes

Contents

module Iconoclast
  
  module IconHelper
    
    # Insert an image tag with an icon with name equal to "name" param and
    # extension .png, with alt attribute and options.
    # Example:
    #    <%= icon :information, "Information icon", :border => 0 %>
    # will generate:
    #    <img src="../icons/information.png" alt="Information icon" border="0" />
    def icon(name, alt = nil, opts = {})
      # Set up some defaults
      collection = 'famfamfam'
      family = 'silk'
      format = 'png'
      
      # Replace the defaults if specified
      ['collection', 'family', 'format'].each do |var|
        eval("#{var} = opts[:#{var}] unless opts[:#{var}].nil?")
        eval("opts.delete #{var}")
      end
      
      opts[:border] ||= 0
      opts[:align] ||= "bottom"
      opts[:alt] ||= alt

      image_tag "icons/#{collection}/#{family}/#{format}/#{name}.png", opts
    end
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
iconoclast-0.1.4 lib/iconoclast/icon_helper.rb
iconoclast-0.1.3 lib/iconoclast/icon_helper.rb
iconoclast-0.1.2 lib/iconoclast/icon_helper.rb
iconoclast-0.1.1 lib/iconoclast/icon_helper.rb
iconoclast-0.1.0 lib/iconoclast/icon_helper.rb