require 'cgi' require File.dirname(__FILE__) + '/url_helper' require File.dirname(__FILE__) + '/tag_helper' module ActionView module Helpers # Provides methods for linking a HTML page together with other assets, such as javascripts, stylesheets, and feeds. module AssetTagHelper # Returns a link tag that browsers and news readers can use to auto-detect a RSS or ATOM feed for this page. The +type+ can # either be :rss (default) or :atom and the +options+ follow the url_for style of declaring a link target. # # Examples: # auto_discovery_link_tag # => # # auto_discovery_link_tag(:atom) # => # # auto_discovery_link_tag(:rss, :action => "feed") # => # def auto_discovery_link_tag(type = :rss, options = {}) tag( "link", "rel" => "alternate", "type" => "application/#{type}+xml", "title" => type.to_s.upcase, "href" => url_for(options.merge(:only_path => false)) ) end # Returns a script include tag per source given as argument. Examples: # # javascript_include_tag "xmlhr" # => # # # javascript_include_tag "common.javascript", "/elsewhere/cools" # => # # def javascript_include_tag(*sources) sources.collect { |source| source = "/javascripts/#{source}" unless source.include?("/") source = "#{source}.js" unless source.include?(".") content_tag("script", "", "language" => "JavaScript", "type" => "text/javascript", "src" => source) }.join("\n") end # Returns a css link tag per source given as argument. Examples: # # stylesheet_link_tag "style" # => # # # stylesheet_link_tag "random.styles", "/css/stylish" # => # # def stylesheet_link_tag(*sources) sources.collect { |source| source = "/stylesheets/#{source}" unless source.include?("/") source = "#{source}.css" unless source.include?(".") tag("link", "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => source) }.join("\n") end end end end