X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/a12d4f62752f546f57421244e370e79965706ffb..f7aee769411a893c1059c529a220c0d25c72974f:/vendor/plugins/engines/lib/bundles/require_resource.rb diff --git a/vendor/plugins/engines/lib/bundles/require_resource.rb b/vendor/plugins/engines/lib/bundles/require_resource.rb new file mode 100644 index 0000000..3469c63 --- /dev/null +++ b/vendor/plugins/engines/lib/bundles/require_resource.rb @@ -0,0 +1,124 @@ +# 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