Commit 9f845b63c3d52344c60876e1c53aa6c87e122a0b
1 parent
1d5e39e0
Exists in
master
and in
1 other branch
updated blitz, semi formal
Showing
21 changed files
with
138 additions
and
65 deletions
Show diff stats
vendor/plugins/blitz/features/controller_generator.feature
... | ... | @@ -5,49 +5,49 @@ Feature: Rails controller generator |
5 | 5 | |
6 | 6 | Scenario: Controller generator for index action |
7 | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | |
8 | + And the blitz plugin is installed | |
9 | 9 | When I generate a "Posts" controller with "index" action |
10 | 10 | And an empty "index" controller action for "posts" should be generated |
11 | 11 | |
12 | 12 | Scenario: Controller generator for new action |
13 | 13 | Given a Rails app |
14 | - And the coulda plugin is installed | |
14 | + And the blitz plugin is installed | |
15 | 15 | When I generate a "Posts" controller with "new" action |
16 | 16 | And a "new" controller action for "posts" should be generated |
17 | 17 | |
18 | 18 | Scenario: Controller generator for create action |
19 | 19 | Given a Rails app |
20 | - And the coulda plugin is installed | |
20 | + And the blitz plugin is installed | |
21 | 21 | When I generate a "Posts" controller with "create" action |
22 | 22 | And a "create" controller action for "posts" should be generated |
23 | 23 | |
24 | 24 | Scenario: Controller generator for create action when Cucumber is installed |
25 | 25 | Given a Rails app with Cucumber |
26 | - And the coulda plugin is installed | |
26 | + And the blitz plugin is installed | |
27 | 27 | When I generate a "Posts" controller with "create" action |
28 | 28 | And a "create" controller action for "posts" should be generated |
29 | 29 | |
30 | 30 | Scenario: Controller generator for show action |
31 | 31 | Given a Rails app |
32 | - And the coulda plugin is installed | |
32 | + And the blitz plugin is installed | |
33 | 33 | When I generate a "Posts" controller with "show" action |
34 | 34 | And a "show" controller action for "posts" should be generated |
35 | 35 | |
36 | 36 | Scenario: Controller generator for edit action |
37 | 37 | Given a Rails app |
38 | - And the coulda plugin is installed | |
38 | + And the blitz plugin is installed | |
39 | 39 | When I generate a "Posts" controller with "edit" action |
40 | 40 | And a "edit" controller action for "posts" should be generated |
41 | 41 | |
42 | 42 | Scenario: Controller generator for update action |
43 | 43 | Given a Rails app |
44 | - And the coulda plugin is installed | |
44 | + And the blitz plugin is installed | |
45 | 45 | When I generate a "Posts" controller with "update" action |
46 | 46 | And a "update" controller action for "posts" should be generated |
47 | 47 | |
48 | 48 | Scenario: Controller generator for destroy action |
49 | 49 | Given a Rails app |
50 | - And the coulda plugin is installed | |
50 | + And the blitz plugin is installed | |
51 | 51 | When I generate a "Posts" controller with "destroy" action |
52 | 52 | And a "destroy" controller action for "posts" should be generated |
53 | 53 | ... | ... |
vendor/plugins/blitz/features/feature_generator.feature
... | ... | @@ -5,7 +5,7 @@ Feature: Rails controller generator |
5 | 5 | |
6 | 6 | Scenario: Feature generator for new action |
7 | 7 | Given a Rails app with Cucumber |
8 | - And the coulda plugin is installed | |
8 | + And the blitz plugin is installed | |
9 | 9 | When I generate a "new" feature for "Posts" |
10 | 10 | Then a "posts" feature for the "create" scenario should be generated |
11 | 11 | And a "create posts" step definition should be generated |
... | ... | @@ -13,7 +13,7 @@ Feature: Rails controller generator |
13 | 13 | |
14 | 14 | Scenario: Feature generator for create action same as new |
15 | 15 | Given a Rails app with Cucumber |
16 | - And the coulda plugin is installed | |
16 | + And the blitz plugin is installed | |
17 | 17 | When I generate a "create" feature for "Posts" |
18 | 18 | Then a "posts" feature for the "create" scenario should be generated |
19 | 19 | And a "create posts" step definition should be generated |
... | ... | @@ -21,7 +21,7 @@ Feature: Rails controller generator |
21 | 21 | |
22 | 22 | Scenario: Feature generator for edit action |
23 | 23 | Given a Rails app with Cucumber |
24 | - And the coulda plugin is installed | |
24 | + And the blitz plugin is installed | |
25 | 25 | When I generate a "edit" feature for "Posts" |
26 | 26 | Then a "posts" feature for the "edit" scenario should be generated |
27 | 27 | And a "update posts" step definition should be generated |
... | ... | @@ -29,7 +29,7 @@ Feature: Rails controller generator |
29 | 29 | |
30 | 30 | Scenario: Feature generator for update action same as edit |
31 | 31 | Given a Rails app with Cucumber |
32 | - And the coulda plugin is installed | |
32 | + And the blitz plugin is installed | |
33 | 33 | When I generate a "update" feature for "Posts" |
34 | 34 | Then a "posts" feature for the "update" scenario should be generated |
35 | 35 | And a "update posts" step definition should be generated | ... | ... |
vendor/plugins/blitz/features/functional_test_generator.feature
... | ... | @@ -5,49 +5,49 @@ Feature: Rails controller generator |
5 | 5 | |
6 | 6 | Scenario: Functional test generator for index action |
7 | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | |
8 | + And the blitz plugin is installed | |
9 | 9 | When I generate a "Posts" functional test with "index" action |
10 | 10 | Then a standard "index" functional test for "posts" should be generated |
11 | 11 | |
12 | 12 | Scenario: Functional test generator for new action |
13 | 13 | Given a Rails app |
14 | - And the coulda plugin is installed | |
14 | + And the blitz plugin is installed | |
15 | 15 | When I generate a "Posts" functional test with "new" action |
16 | 16 | Then a standard "new" functional test for "posts" should be generated |
17 | 17 | |
18 | 18 | Scenario: Functional test generator for create action |
19 | 19 | Given a Rails app |
20 | - And the coulda plugin is installed | |
20 | + And the blitz plugin is installed | |
21 | 21 | When I generate a "Posts" functional test with "create" action |
22 | 22 | Then a standard "create" functional test for "posts" should be generated |
23 | 23 | |
24 | 24 | Scenario: Functional test generator for create action when Cucumber is installed |
25 | 25 | Given a Rails app with Cucumber |
26 | - And the coulda plugin is installed | |
26 | + And the blitz plugin is installed | |
27 | 27 | When I generate a "Posts" functional test with "create" action |
28 | 28 | Then a standard "create" functional test for "posts" should be generated |
29 | 29 | |
30 | 30 | Scenario: Functional test generator for show action |
31 | 31 | Given a Rails app |
32 | - And the coulda plugin is installed | |
32 | + And the blitz plugin is installed | |
33 | 33 | When I generate a "Posts" functional test with "show" action |
34 | 34 | Then a standard "show" functional test for "posts" should be generated |
35 | 35 | |
36 | 36 | Scenario: Functional test generator for edit action |
37 | 37 | Given a Rails app |
38 | - And the coulda plugin is installed | |
38 | + And the blitz plugin is installed | |
39 | 39 | When I generate a "Posts" functional test with "edit" action |
40 | 40 | Then a standard "edit" functional test for "posts" should be generated |
41 | 41 | |
42 | 42 | Scenario: Functional test generator for update action |
43 | 43 | Given a Rails app |
44 | - And the coulda plugin is installed | |
44 | + And the blitz plugin is installed | |
45 | 45 | When I generate a "Posts" functional test with "update" action |
46 | 46 | Then a standard "update" functional test for "posts" should be generated |
47 | 47 | |
48 | 48 | Scenario: Functional test generator for destroy action |
49 | 49 | Given a Rails app |
50 | - And the coulda plugin is installed | |
50 | + And the blitz plugin is installed | |
51 | 51 | When I generate a "Posts" functional test with "destroy" action |
52 | 52 | Then a standard "destroy" functional test for "posts" should be generated |
53 | 53 | ... | ... |
vendor/plugins/blitz/features/helper_generator.feature
... | ... | @@ -5,7 +5,7 @@ Feature: Rails helper generator |
5 | 5 | |
6 | 6 | Scenario: Helper |
7 | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | |
8 | + And the blitz plugin is installed | |
9 | 9 | When I generate a helper named "Navigation" |
10 | 10 | Then a helper should be generated for "Navigation" |
11 | 11 | And a helper test should be generated for "Navigation" | ... | ... |
vendor/plugins/blitz/features/model_generator.feature
... | ... | @@ -5,21 +5,21 @@ Feature: Rails model generator |
5 | 5 | |
6 | 6 | Scenario: Model generator without attributes |
7 | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | |
8 | + And the blitz plugin is installed | |
9 | 9 | When I generate a model named "User" |
10 | 10 | Then a factory should be generated for "User" |
11 | 11 | And a unit test should be generated for "User" |
12 | 12 | |
13 | 13 | Scenario: Model generator with attributes |
14 | 14 | Given a Rails app |
15 | - And the coulda plugin is installed | |
15 | + And the blitz plugin is installed | |
16 | 16 | When I generate a model "User" with a string "email" |
17 | 17 | Then a factory for "User" should have an "email" string |
18 | 18 | And a unit test should be generated for "User" |
19 | 19 | |
20 | 20 | Scenario: Model generator with association |
21 | 21 | Given a Rails app |
22 | - And the coulda plugin is installed | |
22 | + And the blitz plugin is installed | |
23 | 23 | When I generate a model "Post" that belongs to a "User" |
24 | 24 | Then a factory for "Post" should have an association to "User" |
25 | 25 | And the "Post" unit test should have "should_belong_to :user" macro |
... | ... | @@ -29,7 +29,7 @@ Feature: Rails model generator |
29 | 29 | |
30 | 30 | Scenario: Model generator with Paperclip |
31 | 31 | Given a Rails app |
32 | - And the coulda plugin is installed | |
32 | + And the blitz plugin is installed | |
33 | 33 | When I generate a model "Design" with file "Image" |
34 | 34 | Then the "Design" model should have "has_attached_file :image" macro |
35 | 35 | And the "Design" unit test should have "should_have_attached_file :image" macro | ... | ... |
vendor/plugins/blitz/features/step_definitions/controller_steps.rb
... | ... | @@ -18,7 +18,7 @@ Then /^a "create" controller action for "posts" should be generated$/ do |
18 | 18 | " @post = Post.new(params[:post])\n" << |
19 | 19 | " @post.save\n" << |
20 | 20 | " flash[:success] = 'Post created.'\n" << |
21 | - " redirect_to posts_path\n" << | |
21 | + " redirect_to root_path\n" << | |
22 | 22 | " end" |
23 | 23 | end |
24 | 24 | end |
... | ... | @@ -45,7 +45,7 @@ Then /^a "update" controller action for "posts" should be generated$/ do |
45 | 45 | " @post = Post.find(params[:id])\n" << |
46 | 46 | " @post.update_attributes(params[:post])\n" << |
47 | 47 | " flash[:success] = 'Post updated.'\n" << |
48 | - " redirect_to posts_path\n" << | |
48 | + " redirect_to root_path\n" << | |
49 | 49 | " end" |
50 | 50 | end |
51 | 51 | end |
... | ... | @@ -56,7 +56,7 @@ Then /^a "destroy" controller action for "posts" should be generated$/ do |
56 | 56 | " @post = Post.find(params[:id])\n" << |
57 | 57 | " @post.destroy\n" << |
58 | 58 | " flash[:success] = 'Post deleted.'\n" << |
59 | - " redirect_to posts_path\n" << | |
59 | + " redirect_to root_path\n" << | |
60 | 60 | " end" |
61 | 61 | end |
62 | 62 | end | ... | ... |
vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb
... | ... | @@ -14,6 +14,7 @@ end |
14 | 14 | Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |action| |
15 | 15 | if %w(new create).include?(action) |
16 | 16 | assert_generated_file("features/posts.feature") do |
17 | + "Feature: Posts\n\n" << | |
17 | 18 | " Scenario: Create a new post\n" << |
18 | 19 | " Given I am on the new post page\n" << |
19 | 20 | " When I create a post named \"A new post\"\n" << |
... | ... | @@ -21,6 +22,7 @@ Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |a |
21 | 22 | end |
22 | 23 | elsif %w(edit update).include?(action) |
23 | 24 | assert_generated_file("features/posts.feature") do |
25 | + "Feature: Posts\n\n" << | |
24 | 26 | " Scenario: Update a post\n" << |
25 | 27 | " Given I am on the edit \"An existing post\" post page\n" << |
26 | 28 | " When I update the post\n" << |
... | ... | @@ -32,8 +34,8 @@ end |
32 | 34 | Then /^a "create posts" step definition should be generated$/ do |
33 | 35 | assert_generated_file("features/step_definitions/posts_steps.rb") do |
34 | 36 | "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" << |
35 | - " fills_in :name, :with => name\n" << | |
36 | - " click_button 'Create'\n" | |
37 | + " fill_in :name, :with => name\n" << | |
38 | + " click_button 'Create'\n" << | |
37 | 39 | "end" |
38 | 40 | end |
39 | 41 | end |
... | ... | @@ -48,8 +50,8 @@ end |
48 | 50 | Then /^a "update posts" step definition should be generated$/ do |
49 | 51 | assert_generated_file("features/step_definitions/posts_steps.rb") do |
50 | 52 | "When /^I update a post named \"([^\\\"]*)\"$/ do |name|\n" << |
51 | - " fills_in :name, :with => name\n" << | |
52 | - " click_button 'Update'\n" | |
53 | + " fill_in :name, :with => name\n" << | |
54 | + " click_button 'Update'\n" << | |
53 | 55 | "end" |
54 | 56 | end |
55 | 57 | end | ... | ... |
vendor/plugins/blitz/features/step_definitions/generator_steps.rb
... | ... | @@ -3,11 +3,11 @@ Given 'a Rails app' do |
3 | 3 | @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") |
4 | 4 | end |
5 | 5 | |
6 | -Given /^the coulda plugin is installed$/ do | |
6 | +Given /^the blitz plugin is installed$/ do | |
7 | 7 | plugin_dir = File.join(@rails_root, "vendor", "plugins") |
8 | 8 | target = File.join(File.dirname(__FILE__), "..", "..", "generators") |
9 | - FileUtils.mkdir_p "#{plugin_dir}/coulda" | |
10 | - system "cp -r #{target} #{plugin_dir}/coulda" | |
9 | + FileUtils.mkdir_p "#{plugin_dir}/blitz" | |
10 | + system "cp -r #{target} #{plugin_dir}/blitz" | |
11 | 11 | end |
12 | 12 | |
13 | 13 | After do | ... | ... |
vendor/plugins/blitz/features/step_definitions/view_steps.rb
... | ... | @@ -4,6 +4,12 @@ When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource| |
4 | 4 | "cd .." |
5 | 5 | end |
6 | 6 | |
7 | +When /^I generate a "([^\"]*)" view for "([^\"]*)" with the empty option$/ do |view, resource| | |
8 | + system "cd #{@rails_root} && " << | |
9 | + "script/generate view #{resource} #{view} --empty && " << | |
10 | + "cd .." | |
11 | +end | |
12 | + | |
7 | 13 | When /^a SemiFormal "new" view for "posts" should be generated$/ do |
8 | 14 | assert_generated_file("app/views/posts/new.html.erb") do |
9 | 15 | "<h1>New post</h1>\n\n" << |
... | ... | @@ -24,8 +30,9 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do |
24 | 30 | "<% form_for(@post) do |form| %>\n" << |
25 | 31 | " <%= form.error_messages %>\n" << |
26 | 32 | " <fieldset class=\"inputs\">\n" << |
27 | - " <%= form.string :title %>\n" << | |
28 | - " <%= form.text :body %>\n" << | |
33 | + " <%= form.string :title %>\n" << | |
34 | + " <%= form.text :body %>\n" << | |
35 | + " <%= form.collection :user %>\n" << | |
29 | 36 | " </fieldset>\n" << |
30 | 37 | " <fieldset class=\"buttons\">\n" << |
31 | 38 | " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << |
... | ... | @@ -34,3 +41,7 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do |
34 | 41 | end |
35 | 42 | end |
36 | 43 | |
44 | +Then /^an empty "new" view for "posts" should be generated$/ do | |
45 | + assert_generated_empty_file("app/views/posts/new.html.erb") | |
46 | +end | |
47 | + | ... | ... |
vendor/plugins/blitz/features/support/env.rb
... | ... | @@ -14,6 +14,15 @@ module Test::Unit::Assertions |
14 | 14 | end |
15 | 15 | end |
16 | 16 | |
17 | + def assert_generated_empty_file(path) | |
18 | + assert_file_exists(path) | |
19 | + File.open(File.join(@rails_root, path)) do |file| | |
20 | + body = file.read | |
21 | + assert body.empty?, | |
22 | + "expected body to be empty but was #{body.inspect}" | |
23 | + end | |
24 | + end | |
25 | + | |
17 | 26 | def assert_file_exists(path) |
18 | 27 | file = File.join(@rails_root, path) |
19 | 28 | ... | ... |
vendor/plugins/blitz/features/view_generator.feature
... | ... | @@ -5,14 +5,21 @@ Feature: Rails view generator |
5 | 5 | |
6 | 6 | Scenario: View generator for new action |
7 | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | |
8 | + And the blitz plugin is installed | |
9 | 9 | When I generate a "new" view for "Posts" |
10 | 10 | Then a SemiFormal "new" view for "posts" should be generated |
11 | 11 | |
12 | 12 | Scenario: View generator for new action |
13 | 13 | Given a Rails app |
14 | - And the coulda plugin is installed | |
14 | + And the blitz plugin is installed | |
15 | 15 | When I generate a Post model with title, body, and User |
16 | 16 | And I generate a "new" view for "Posts" |
17 | 17 | Then a SemiFormal "new" view for "posts" should be generated with fields |
18 | 18 | |
19 | + Scenario: View generator for new action | |
20 | + Given a Rails app | |
21 | + And the blitz plugin is installed | |
22 | + When I generate a Post model with title, body, and User | |
23 | + When I generate a "new" view for "Posts" with the empty option | |
24 | + Then an empty "new" view for "posts" should be generated | |
25 | + | ... | ... |
vendor/plugins/blitz/generators/controller/templates/controller.rb
... | ... | @@ -15,7 +15,7 @@ class <%= class_name %>Controller < ApplicationController |
15 | 15 | @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>]) |
16 | 16 | @<%= resource %>.save |
17 | 17 | flash[:success] = '<%= resource_class %> created.' |
18 | - redirect_to <%= resources %>_path | |
18 | + redirect_to root_path | |
19 | 19 | end |
20 | 20 | |
21 | 21 | <% end -%> |
... | ... | @@ -36,7 +36,7 @@ class <%= class_name %>Controller < ApplicationController |
36 | 36 | @<%= resource %> = <%= resource_class %>.find(params[:id]) |
37 | 37 | @<%= resource %>.update_attributes(params[:<%= resource %>]) |
38 | 38 | flash[:success] = '<%= resource_class %> updated.' |
39 | - redirect_to <%= resources %>_path | |
39 | + redirect_to root_path | |
40 | 40 | end |
41 | 41 | |
42 | 42 | <% end -%> |
... | ... | @@ -45,7 +45,7 @@ class <%= class_name %>Controller < ApplicationController |
45 | 45 | @<%= resource %> = <%= resource_class %>.find(params[:id]) |
46 | 46 | @<%= resource %>.destroy |
47 | 47 | flash[:success] = '<%= resource_class %> deleted.' |
48 | - redirect_to <%= resources %>_path | |
48 | + redirect_to root_path | |
49 | 49 | end |
50 | 50 | |
51 | 51 | <% end -%> | ... | ... |
vendor/plugins/blitz/generators/feature/templates/feature.feature
vendor/plugins/blitz/generators/feature/templates/step_definition.rb
1 | 1 | <% if %w(new create).any? { |action| actions.include?(action) } -%> |
2 | 2 | When /^I create a <%= resource %> named "([^\"]*)"$/ do |name| |
3 | - fills_in :name, :with => name | |
3 | + fill_in :name, :with => name | |
4 | 4 | click_button 'Create' |
5 | 5 | end |
6 | 6 | <% elsif %w(edit update).any? { |action| actions.include?(action) } -%> |
7 | 7 | When /^I update a post named "([^\"]*)"$/ do |name| |
8 | - fills_in :name, :with => name | |
8 | + fill_in :name, :with => name | |
9 | 9 | click_button 'Update' |
10 | 10 | end |
11 | 11 | <% end -%> | ... | ... |
vendor/plugins/blitz/generators/support/generator_helper.rb
... | ... | @@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "insert_commands") |
2 | 2 | |
3 | 3 | module Blitz |
4 | 4 | module GeneratorHelper |
5 | - REMOVABLE_COLUMNS = ["created_at", "updated_at", "email_confirmed", | |
5 | + REMOVABLE_COLUMNS = ["id", "created_at", "updated_at", "email_confirmed", | |
6 | 6 | "encrypted_password", "salt", "token", "token_expires_at"] |
7 | 7 | |
8 | 8 | def resource |
... | ... | @@ -18,8 +18,8 @@ module Blitz |
18 | 18 | end |
19 | 19 | |
20 | 20 | def columns_for_form |
21 | - resource_class.constantize.content_columns. | |
22 | - collect { |column| [column.name, column.type] }. | |
21 | + resource_class.constantize.columns. | |
22 | + collect { |column| name_and_type(column) }. | |
23 | 23 | delete_if { |column| remove_column?(column.first) } |
24 | 24 | end |
25 | 25 | |
... | ... | @@ -30,9 +30,21 @@ module Blitz |
30 | 30 | models.include?(resource_class) |
31 | 31 | end |
32 | 32 | |
33 | + def belongs_to_column?(column_name) | |
34 | + !(column_name =~ /_id$/).nil? | |
35 | + end | |
36 | + | |
37 | + def name_and_type(column) | |
38 | + if belongs_to_column?(column.name) | |
39 | + [column.name.gsub("_id", ""), :collection] | |
40 | + else | |
41 | + [column.name, column.type] | |
42 | + end | |
43 | + end | |
44 | + | |
33 | 45 | def remove_column?(column) |
34 | 46 | REMOVABLE_COLUMNS.include?(column) || |
35 | - !(column =~ /_id$/).nil? | |
47 | + !(column =~ /_count$/).nil? | |
36 | 48 | end |
37 | 49 | end |
38 | 50 | end | ... | ... |
vendor/plugins/blitz/generators/view/templates/empty.html.erb
0 → 100644
vendor/plugins/blitz/generators/view/templates/new.html.erb
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +<h1>New <%= resource %></h1> | |
2 | + | |
3 | +<%% form_for(@<%= resource %>) do |form| %> | |
4 | + <%%= form.error_messages %> | |
5 | + <fieldset class="inputs"> | |
6 | +<% if active_record_defined? -%> | |
7 | +<% columns_for_form.each do |attribute_name, attribute_type| -%> | |
8 | + <%%= form.<%= attribute_type %> :<%= attribute_name %> %> | |
9 | +<% end -%> | |
10 | +<% end -%> | |
11 | + </fieldset> | |
12 | + <fieldset class="buttons"> | |
13 | + <%%= form.submit 'Create', :disable_with => 'Please wait...' %> | |
14 | + </fieldset> | |
15 | +<%% end %> | ... | ... |
vendor/plugins/blitz/generators/view/templates/view_new.html.erb
... | ... | @@ -1,15 +0,0 @@ |
1 | -<h1>New <%= resource %></h1> | |
2 | - | |
3 | -<%% form_for(@<%= resource %>) do |form| %> | |
4 | - <%%= form.error_messages %> | |
5 | - <fieldset class="inputs"> | |
6 | -<% if active_record_defined? -%> | |
7 | -<% columns_for_form.each do |attribute_name, attribute_type| -%> | |
8 | - <%%= form.<%= attribute_type %> :<%= attribute_name %> %> | |
9 | -<% end -%> | |
10 | -<% end -%> | |
11 | - </fieldset> | |
12 | - <fieldset class="buttons"> | |
13 | - <%%= form.submit 'Create', :disable_with => 'Please wait...' %> | |
14 | - </fieldset> | |
15 | -<%% end %> |
vendor/plugins/blitz/generators/view/view_generator.rb
1 | 1 | require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") |
2 | 2 | |
3 | 3 | class ViewGenerator < Rails::Generator::NamedBase |
4 | + default_options :empty => false | |
5 | + | |
4 | 6 | def manifest |
5 | 7 | record do |m| |
6 | 8 | m.directory File.join('app/views', class_path, file_name) |
7 | 9 | |
8 | 10 | if actions.include?("new") |
9 | 11 | path = File.join('app/views', class_path, file_name, "new.html.erb") |
10 | - m.template 'view_new.html.erb', path | |
12 | + if options[:empty] | |
13 | + m.file 'empty.html.erb', path | |
14 | + else | |
15 | + m.template 'new.html.erb', path | |
16 | + end | |
11 | 17 | end |
12 | 18 | end |
13 | 19 | end |
20 | + | |
21 | + def add_options!(opt) | |
22 | + opt.on('-e', '--empty') { options[:empty] = true } | |
23 | + end | |
14 | 24 | end | ... | ... |
vendor/plugins/semi_formal/README.markdown
1 | 1 | SemiFormal |
2 | 2 | ========== |
3 | 3 | |
4 | -A FormBuilder meant to play well with [Coulda](http://github.com/dancroak/coulda) and [Evergreen](http://github.com/dancroak/evergreen). | |
4 | +A FormBuilder meant to play well with [Blitz](http://github.com/dancroak/blitz) and [Evergreen](http://github.com/dancroak/evergreen). | |
5 | 5 | |
6 | 6 | Examples |
7 | 7 | -------- | ... | ... |
vendor/plugins/semi_formal/lib/semi_formal.rb
... | ... | @@ -41,6 +41,26 @@ class SemiFormal < ActionView::Helpers::FormBuilder |
41 | 41 | text_area(field, options[:text_area] || {}) + |
42 | 42 | "<div>" |
43 | 43 | end |
44 | + | |
45 | + def collection(field, *args) | |
46 | + options = args.extract_options! | |
47 | + | |
48 | + reflection = @object.class.reflect_on_association(field) | |
49 | + collection = reflection.class.all.collect {|each| [each.name, each.id] } | |
50 | + | |
51 | + html_options = {} | |
52 | + options[:include_blank] = true | |
53 | + | |
54 | + if [:has_many, :has_and_belongs_to_many].include?(reflection.macro) | |
55 | + html_options[:multiple] ||= true | |
56 | + html_options[:size] ||= 5 | |
57 | + end | |
58 | + | |
59 | + "<div class=\"collection\">" + | |
60 | + label(field, options[:label] || {}) + | |
61 | + select(field, collection, options, html_options) | |
62 | + "<div>" | |
63 | + end | |
44 | 64 | end |
45 | 65 | |
46 | 66 | ActionView::Base.default_form_builder = SemiFormal | ... | ... |