require 'fileutils'
module ::ActionView
class Base
private
def full_template_path(template_path, extension)
# 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)
# 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.active.each 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' =>
#