# RequireResource v.1.4 by Duane Johnson # # Makes inclusion of javascript and stylesheet resources easier via automatic or explicit # calls. e.g. require_javascript 'popup' is an explicit call. # # The simplest way to make use of this functionality is to add # <%= resource_tags %> # to your layout (usually in the section). This will automatically add # bundle support to your application, as well as enable simple javascript and stylesheet # dependencies for your views. # # Note that this can easily be turned in to a helper on its own. module RequireResource mattr_accessor :path_prefix # Write out all javascripts & stylesheets, including default javascripts (unless :defaults => false) def resource_tags(options = {}) options = {:auto => true, :defaults => true}.update(options) require_defaults if options[:defaults] stylesheet_auto_link_tags(:auto => options[:auto]) + javascript_auto_include_tags(:auto => options[:auto]) end # Write out the tags themselves based on the array of stylesheets to be included def stylesheet_auto_link_tags(options = {}) options = {:auto => true}.update(options) ensure_resource_is_initialized(:stylesheet) autorequire(:stylesheet) if options[:auto] @stylesheets.uniq.inject("") do |buffer, css| buffer << stylesheet_link_tag(css) + "\n " end end # Write out the