Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Look for templates in vendor/plugins/*/templates
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Oct 20, 2010
1 parent 49c3cfa commit 89691d0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/brochure/application.rb
@@ -1,13 +1,21 @@
module Brochure
class Application
attr_reader :app_root, :template_root, :asset_root
attr_reader :app_root, :template_root, :asset_root, :plugin_root

def initialize(root, options = {})
@app_root = File.expand_path(root)
@template_root = File.join(@app_root, "templates")
@asset_root = File.join(@app_root, "public")
@plugin_root = File.join(@app_root, "vendor", "plugins")

helpers.push(*options[:helpers]) if options[:helpers]
initialize_plugins
end

def initialize_plugins
plugins.each do |plugin_root|
template_trail.paths.push(File.join(plugin_root, "templates"))
end
end

def template_trail
Expand All @@ -29,6 +37,12 @@ def helpers
@helpers ||= []
end

def plugins
@plugins ||= Dir[File.join(plugin_root, "*")].select do |entry|
File.directory?(entry)
end
end

def call(env)
if forbidden?(env["PATH_INFO"])
forbidden
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/templates/help/index.html.erb
Expand Up @@ -4,5 +4,6 @@
<body>
<h1>Help</h1>
<%= link_to "Home", "/" %>
<%= render "shared/footer" %>
</body>
</html>
@@ -0,0 +1 @@
Common template
@@ -0,0 +1 @@
<div>Footer</div>
10 changes: 10 additions & 0 deletions test/test_brochure.rb
Expand Up @@ -79,4 +79,14 @@ def test_using_other_tilt_template_types
get "/hello?name=Sam"
assert last_response.body["<p>Hello Sam</p>"]
end

def test_templates_in_plugins
get "/common"
assert last_response.body["Common template"]
end

def test_rendering_partials_in_plugins
get "/help"
assert last_response.body["<div>Footer</div>"]
end
end

0 comments on commit 89691d0

Please sign in to comment.