diff --git a/README.rdoc b/README.rdoc index 4b18a15..f9776c1 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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? diff --git a/app/controllers/mockups_controller.rb b/app/controllers/mockups_controller.rb index e41ca31..8e99588 100644 --- a/app/controllers/mockups_controller.rb +++ b/app/controllers/mockups_controller.rb @@ -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 diff --git a/generators/showoff/showoff_generator.rb b/generators/showoff/showoff_generator.rb index 87838da..27802e1 100644 --- a/generators/showoff/showoff_generator.rb +++ b/generators/showoff/showoff_generator.rb @@ -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 diff --git a/generators/showoff/templates/alternate_layout.html.erb b/generators/showoff/templates/alternate_layout.html.erb new file mode 100644 index 0000000..93c548a --- /dev/null +++ b/generators/showoff/templates/alternate_layout.html.erb @@ -0,0 +1,10 @@ +

Nesting & Alternate Layout Example

+ +

+ You can add subdirectories within app/views/mockups to organize your mockups (only one level deep). +

+ +

+ 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. +

diff --git a/generators/showoff/templates/alternate_layout.html.erb.alternate b/generators/showoff/templates/alternate_layout.html.erb.alternate deleted file mode 100644 index 6bf08bd..0000000 --- a/generators/showoff/templates/alternate_layout.html.erb.alternate +++ /dev/null @@ -1,7 +0,0 @@ -

Alternate Layout Example

- -

- If a template has an additinal file extension, such as alternate_layout.html.erb.alternate, - the first extension will be used as the layout. In this case, Rails is expecting a layout named - 'alternate' to be defined. -

diff --git a/generators/showoff/templates/sample_nested.html.erb b/generators/showoff/templates/sample_nested.html.erb deleted file mode 100644 index f9b7c1f..0000000 --- a/generators/showoff/templates/sample_nested.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

Sample Nested Mockup

- -

- You can add subdirectories within app/views/mockups to organize your mockups (only one level deep). -