Permalink
Browse files

fix how alternate layouts are handled

  • Loading branch information...
1 parent fb6c234 commit 4bd247d0784fbc78a3e702102579723e8f5184b5 @adamlogic committed Feb 25, 2010
View
@@ -18,7 +18,7 @@ you embed a "mini app" inside of your main app.
Just throw your mockups into app/views/mockups, then navigate to /mockups in your app. Just like any other
Rails view, you can use partials, helpers, etc. If you want to use a layout other than your application
-default, tack it on as an additional file extension (example.html.erb.alternate).
+default, nest your mockup in a subdirectory with the same name as the layout (see examples).
== Can I see an example?
@@ -1,4 +1,7 @@
class MockupsController < ApplicationController
+ LAYOUTS = Dir.glob(File.join(Rails.root, 'app', 'views', 'layouts', '*.html.*')).map do |file|
+ File.basename(file).split('.').first
+ end
def frameset
render :layout => false
@@ -26,24 +29,14 @@ def show
session[:template_name] = params[:template_name]
session[:parent_dir] = params[:parent_dir]
template_path = File.join(['mockups', params[:parent_dir], params[:template_name]].compact)
- render :template => template_path, :layout => extract_layout(template_path)
+ render :template => template_path, :layout => determine_layout
end
private
- def extract_layout(template_path)
- full_path = File.join(Rails.root, 'app', 'views', template_path)
- located_files = Dir.glob("#{full_path}*")
-
- return true if located_files.empty?
-
- filename_components = File.basename(located_files[0]).split('.')
-
- if filename_components.length < 4
- true
- else
- filename_components.last
- end
+ def determine_layout
+ directory = params[:parent_dir].to_s.downcase
+ LAYOUTS.include?(directory) ? directory : true
end
end
@@ -1,10 +1,10 @@
class ShowoffGenerator < Rails::Generator::Base
def manifest
record do |m|
- m.directory 'app/views/mockups/sample_section'
+ m.directory 'app/views/mockups/basic'
+
m.file 'sample_mockup.html.erb', 'app/views/mockups/sample_mockup.html.erb'
- m.file 'alternate_layout.html.erb.alternate', 'app/views/mockups/alternate_layout.html.erb.alternate'
- m.file 'sample_nested.html.erb', 'app/views/mockups/sample_section/sample_nested.html.erb'
+ m.file 'alternate_layout.html.erb', 'app/views/mockups/basic/alternate_layout.html.erb'
m.file 'showoff.css', 'public/stylesheets/showoff.css'
end
end
@@ -0,0 +1,10 @@
+<h1>Nesting & Alternate Layout Example</h1>
+
+<p>
+ You can add subdirectories within app/views/mockups to organize your mockups (only one level deep).
+</p>
+
+<p>
+ If the subdirectory name matches a layout file, that layout would be used.
+ In this example, if you had a layout named "basic", it would be used instead of the default.
+</p>
@@ -1,7 +0,0 @@
-<h1>Alternate Layout Example</h1>
-
-<p>
- If a template has an additinal file extension, such as <code>alternate_layout.html.erb.alternate</code>,
- the first extension will be used as the layout. In this case, Rails is expecting a layout named
- 'alternate' to be defined.
-</p>
@@ -1,5 +0,0 @@
-<h1>Sample Nested Mockup</h1>
-
-<p>
- You can add subdirectories within app/views/mockups to organize your mockups (only one level deep).
-</p>

0 comments on commit 4bd247d

Please sign in to comment.