Permalink
Browse files

added themed generator features

  • Loading branch information...
1 parent 330bc05 commit 821f1ab9cc79c89943dbae0a711cdebd4d5a78c9 @pilu pilu committed Aug 27, 2009
View
@@ -2,5 +2,4 @@ require 'rubygems'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new
-
task :default => :cucumber
@@ -11,15 +11,15 @@
end
Given /^I generate a theme$/ do
- generate_layout(:theme)
+ generate_layout
end
Given /^I generate a theme with name "([^\"]*)"$/ do |name|
- generate_layout(:theme, name)
+ generate_layout(name)
end
Given /^I generate a theme choosing the "([^\"]*)" theme$/ do |theme_name|
- generate_layout(:theme, :theme => theme_name)
+ generate_layout(:theme => theme_name)
end
Then /^I should have a layout named "([^\"]*)"$/ do |filename|
@@ -31,23 +31,23 @@
end
Given /^I generate a theme without layout choosing the "([^\"]*)" theme$/ do |theme_name|
- generate_layout(:theme, :theme => theme_name, :no_layout => true )
+ generate_layout(:theme => theme_name, :no_layout => true )
end
Then /^I should not have any layouts$/ do
layouts_count.should == 0
end
Given /^I generate a theme with application name "([^\"]*)"$/ do |name|
- generate_layout(:theme, :app_name => name )
+ generate_layout(:app_name => name )
end
Then /^the layout "([^\"]*)" should have "([^\"]*)" as page title$/ do |layout, title|
layout_title(layout).should == title
end
Given /^I generate a theme for signin and signup$/ do
- generate_layout(:theme, :layout_type => :sign)
+ generate_layout(:layout_type => :sign)
end
Then /^I should have a layout named "([^\"]*)" with just a box$/ do |layout|
@@ -0,0 +1,15 @@
+Given /^a model "([^\"]*)"$/ do |model_name|
+ generate_model(model_name)
+end
+
+Given /^I generate views for controller "([^\"]*)"$/ do |controller_path|
+ generate_views(controller_path)
+end
+
+When /^I generate views for controller "([^\"]*)" and model "([^\"]*)"$/ do |controller_path, model_name|
+ generate_views(controller_path, model_name)
+end
+
+Then /^I should have a view named "([^\"]*)"$/ do |view_path|
+ view_exists?(view_path).should be_true
+end
View
@@ -24,12 +24,28 @@ def remove_stylesheets
FileUtils.rm_rf(File.join(@app_root, "public", "stylesheets"))
end
- def generate_layout(*args)
+ def generate(*args)
options = !args.empty? && args.last.is_a?(Hash) ? args.pop : {}
options.merge!({:destination => @app_root, :quiet => true})
Rails::Generator::Scripts::Generate.new.run(args, options)
end
+ def generate_layout(*args)
+ generate(:theme, *args)
+ end
+
+ def generate_views(*args)
+ generate(:themed, *args)
+ end
+
+ def generate_model(model_name)
+ Object.const_get(model_name)
+ rescue NameError
+ Object.const_set(model_name, Class.new)
+ klass = Object.const_get(model_name)
+ def klass.columns; []; end
+ end
+
def layouts_count
Dir[File.join(@app_root, "app", "views", "layouts", "**", "*.erb")].size
end
@@ -38,6 +54,10 @@ def layout_exists?(filename)
File.exists?(File.join(@app_root, "app", "views", "layouts", filename))
end
+ def view_exists?(view_path)
+ File.exists?(File.join(@app_root, "app", "views", view_path))
+ end
+
def stylesheet_exists?(relative_path)
File.exists?(File.join(@app_root, "public", "stylesheets", relative_path)).should be_true
end
@@ -0,0 +1,39 @@
+Feature: Theme generation
+ In order to create a great application
+ I should be able to creare theme after creating a layout
+
+ Scenario: Creating CRUD views with post path
+ Given I have a new rails app
+ And a model "Post"
+ When I generate views for controller "posts"
+ Then I should have a view named "posts/index.html.erb"
+ And I should have a view named "posts/new.html.erb"
+ And I should have a view named "posts/show.html.erb"
+ And I should have a view named "posts/edit.html.erb"
+
+ Scenario: Creating CRUD views with post path and model path
+ Given I have a new rails app
+ And a model "Post"
+ When I generate views for controller "items" and model "Post"
+ Then I should have a view named "items/index.html.erb"
+ And I should have a view named "items/new.html.erb"
+ And I should have a view named "items/show.html.erb"
+ And I should have a view named "items/edit.html.erb"
+
+ Scenario: Creating CRUD views with post path "admin/items" and model path
+ Given I have a new rails app
+ And a model "Post"
+ When I generate views for controller "admin/items" and model "Post"
+ Then I should have a view named "admin/items/index.html.erb"
+ And I should have a view named "admin/items/new.html.erb"
+ And I should have a view named "admin/items/show.html.erb"
+ And I should have a view named "admin/items/edit.html.erb"
+
+ Scenario: Creating CRUD views with post path "admin/gallery_pictures" and model path
+ Given I have a new rails app
+ And a model "GalleryPicture"
+ When I generate views for controller "admin/gallery_pictures"
+ Then I should have a view named "admin/gallery_pictures/index.html.erb"
+ And I should have a view named "admin/gallery_pictures/new.html.erb"
+ And I should have a view named "admin/gallery_pictures/show.html.erb"
+ And I should have a view named "admin/gallery_pictures/edit.html.erb"
@@ -12,7 +12,9 @@
<table class="table">
<tr>
<th class="first">ID</th>
- <th><%= columns.first.name.capitalize %></th>
+ <% unless columns.empty? -%>
+ <th><%= columns.first.name.capitalize %></th>
+ <% end -%>
<th>Created at</th>
<th class="last">&nbsp;</th>
</tr>
@@ -21,10 +23,12 @@
<td>
<%%= <%= resource_name %>.id %>
</td>
- <td>
- <%%= link_to <%= resource_name %>.<%= columns.first.name %>, <%= singular_controller_routing_path %>_path(<%= resource_name %>) %>
- </td>
- <td>
+ <% unless columns.empty? -%>
+ <td>
+ <%%= link_to <%= resource_name %>.<%= columns.first.name %>, <%= singular_controller_routing_path %>_path(<%= resource_name %>) %>
+ </td>
+ <% end -%>
+ <td>
<%%= <%= resource_name %>.created_at %>
</td>
<td class="last">

0 comments on commit 821f1ab

Please sign in to comment.