7 def full_template_path(template_path, extension)
9 unless Engines.disable_app_views_loading
10 # If the template exists in the normal application directory,
12 default_template = "#{@base_path}/#{template_path}.#{extension}"
13 return default_template if File.exist?(default_template)
16 # Otherwise, check in the engines to see if the template can be found there.
17 # Load this in order so that more recently started Engines will take priority.
18 Engines.each(:precidence_order) do |engine|
19 site_specific_path = File.join(engine.root, 'app', 'views',
20 template_path.to_s + '.' + extension.to_s)
21 return site_specific_path if File.exist?(site_specific_path)
24 # If it cannot be found anywhere, return the default path, where the
25 # user *should* have put it.
26 return "#{@base_path}/#{template_path}.#{extension}"
31 # add methods to handle including javascripts and stylesheets
34 # Returns a stylesheet link tag to the named stylesheet(s) for the given
35 # engine. A stylesheet with the same name as the engine is included automatically.
36 # If other names are supplied, those stylesheets from within the same engine
39 # engine_stylesheet "my_engine" =>
40 # <link href="/engine_files/my_engine/stylesheets/my_engine.css" media="screen" rel="Stylesheet" type="text/css" />
42 # engine_stylesheet "my_engine", "another_file", "one_more" =>
43 # <link href="/engine_files/my_engine/stylesheets/my_engine.css" media="screen" rel="Stylesheet" type="text/css" />
44 # <link href="/engine_files/my_engine/stylesheets/another_file.css" media="screen" rel="Stylesheet" type="text/css" />
45 # <link href="/engine_files/my_engine/stylesheets/one_more.css" media="screen" rel="Stylesheet" type="text/css" />
47 # Any options supplied as a Hash as the last argument will be processed as in
48 # stylesheet_link_tag.
50 def engine_stylesheet(engine_name, *sources)
51 stylesheet_link_tag(*convert_public_sources(engine_name, :stylesheet, sources))
54 # Returns a javascript link tag to the named stylesheet(s) for the given
55 # engine. A javascript file with the same name as the engine is included automatically.
56 # If other names are supplied, those javascript from within the same engine
59 # engine_javascript "my_engine" =>
60 # <script type="text/javascript" src="/engine_files/my_engine/javascripts/my_engine.js"></script>
62 # engine_javascript "my_engine", "another_file", "one_more" =>
63 # <script type="text/javascript" src="/engine_files/my_engine/javascripts/my_engine.js"></script>
64 # <script type="text/javascript" src="/engine_files/my_engine/javascripts/another_file.js"></script>
65 # <script type="text/javascript" src="/engine_files/my_engine/javascripts/one_more.js"></script>
67 # Any options supplied as a Hash as the last argument will be processed as in
68 # javascript_include_tag.
70 def engine_javascript(engine_name, *sources)
71 javascript_include_tag(*convert_public_sources(engine_name, :javascript, sources))
74 # Returns a image tag based on the parameters passed to it
75 # Required option is option[:engine] in order to correctly idenfity the correct engine location
77 # engine_image 'rails-engines.png', :engine => 'my_engine', :alt => 'My Engine' =>
78 # <img src="/engine_files/my_engine/images/rails-engines.png" alt="My Engine />
80 # Any options supplied as a Hash as the last argument will be processed as in
83 def engine_image(src, options = {})
86 image_src = engine_image_src(src, options)
88 options.delete(:engine)
90 image_tag(image_src, options)
93 # Alias for engine_image
94 def engine_image_tag(src, options = {})
95 engine_image(src, options)
98 # Returns a path to the image stored within the engine_files
99 # Required option is option[:engine] in order to correctly idenfity the correct engine location
101 # engine_image_src 'rails-engines.png', :engine => 'my_engine' =>
102 # "/engine_files/my_engine/images/rails-engines.png"
104 def engine_image_src(src, options = {})
105 File.join(Engines.get(options[:engine].to_sym).public_dir, 'images', src)
109 # convert the engine public file sources into actual public paths
113 def convert_public_sources(engine_name, type, sources)
114 options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
119 type_dir = "javascripts"
122 type_dir = "stylesheets"
126 engine = Engines.get(engine_name)
128 default = "#{engine.public_dir}/#{type_dir}/#{engine_name}"
129 if defined?(RAILS_ROOT) && File.exists?(File.join(RAILS_ROOT, "public", "#{default}.#{ext}"))
130 new_sources << default
133 sources.each { |name|
134 new_sources << "#{engine.public_dir}/#{type_dir}/#{name}"
137 new_sources << options