X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/a12d4f62752f546f57421244e370e79965706ffb..f7aee769411a893c1059c529a220c0d25c72974f:/vendor/plugins/engines/lib/engines/action_view_extensions.rb
diff --git a/vendor/plugins/engines/lib/engines/action_view_extensions.rb b/vendor/plugins/engines/lib/engines/action_view_extensions.rb
new file mode 100644
index 0000000..bdfa11a
--- /dev/null
+++ b/vendor/plugins/engines/lib/engines/action_view_extensions.rb
@@ -0,0 +1,141 @@
+require 'fileutils'
+
+module ::ActionView
+ class Base
+
+ private
+ def full_template_path(template_path, extension)
+
+ unless Engines.disable_app_views_loading
+ # If the template exists in the normal application directory,
+ # return that path
+ default_template = "#{@base_path}/#{template_path}.#{extension}"
+ return default_template if File.exist?(default_template)
+ end
+
+ # Otherwise, check in the engines to see if the template can be found there.
+ # Load this in order so that more recently started Engines will take priority.
+ Engines.each(:precidence_order) do |engine|
+ site_specific_path = File.join(engine.root, 'app', 'views',
+ template_path.to_s + '.' + extension.to_s)
+ return site_specific_path if File.exist?(site_specific_path)
+ end
+
+ # If it cannot be found anywhere, return the default path, where the
+ # user *should* have put it.
+ return "#{@base_path}/#{template_path}.#{extension}"
+ end
+ end
+
+
+ # add methods to handle including javascripts and stylesheets
+ module Helpers
+ module AssetTagHelper
+ # Returns a stylesheet link tag to the named stylesheet(s) for the given
+ # engine. A stylesheet with the same name as the engine is included automatically.
+ # If other names are supplied, those stylesheets from within the same engine
+ # will be linked too.
+ #
+ # engine_stylesheet "my_engine" =>
+ #
+ #
+ # engine_stylesheet "my_engine", "another_file", "one_more" =>
+ #
+ #
+ #
+ #
+ # Any options supplied as a Hash as the last argument will be processed as in
+ # stylesheet_link_tag.
+ #
+ def engine_stylesheet(engine_name, *sources)
+ stylesheet_link_tag(*convert_public_sources(engine_name, :stylesheet, sources))
+ end
+
+ # Returns a javascript link tag to the named stylesheet(s) for the given
+ # engine. A javascript file with the same name as the engine is included automatically.
+ # If other names are supplied, those javascript from within the same engine
+ # will be linked too.
+ #
+ # engine_javascript "my_engine" =>
+ #
+ #
+ # engine_javascript "my_engine", "another_file", "one_more" =>
+ #
+ #
+ #
+ #
+ # Any options supplied as a Hash as the last argument will be processed as in
+ # javascript_include_tag.
+ #
+ def engine_javascript(engine_name, *sources)
+ javascript_include_tag(*convert_public_sources(engine_name, :javascript, sources))
+ end
+
+ # Returns a image tag based on the parameters passed to it
+ # Required option is option[:engine] in order to correctly idenfity the correct engine location
+ #
+ # engine_image 'rails-engines.png', :engine => 'my_engine', :alt => 'My Engine' =>
+ #