Commit 467daa7ae40a74675eb63d0195191c150ebb6c78
1 parent
177b3289
Exists in
master
and in
1 other branch
updating blitz
Showing
5 changed files
with
65 additions
and
26 deletions
Show diff stats
vendor/plugins/blitz/README.textile
@@ -8,6 +8,7 @@ h2. Generated code may contain | @@ -8,6 +8,7 @@ h2. Generated code may contain | ||
8 | * "Shoulda":http://github.com/thoughtbot/shoulda | 8 | * "Shoulda":http://github.com/thoughtbot/shoulda |
9 | * "Factory Girl":http://github.com/thoughtbot/factory_girl | 9 | * "Factory Girl":http://github.com/thoughtbot/factory_girl |
10 | * "Mocha":http://github.com/jferris/mocha | 10 | * "Mocha":http://github.com/jferris/mocha |
11 | +* "Formtastic":http://github.com/justinfrench/formtastic | ||
11 | 12 | ||
12 | h2. Installation | 13 | h2. Installation |
13 | 14 | ||
@@ -73,6 +74,34 @@ h2. View generator | @@ -73,6 +74,34 @@ h2. View generator | ||
73 | 74 | ||
74 | $ script/generate view Posts new | 75 | $ script/generate view Posts new |
75 | 76 | ||
77 | +generates a Formtastic view which reflects on your current schema... | ||
78 | + | ||
79 | +<pre><code><h1>New post</h1> | ||
80 | + | ||
81 | +<% semantic_form_for(@post) do |form| %> | ||
82 | + <% form.inputs do %> | ||
83 | + <%= form.input :title %> | ||
84 | + <%= form.input :body %> | ||
85 | + <%= form.input :user %> | ||
86 | + <% end %> | ||
87 | + <% form.buttons do %> | ||
88 | + <%= form.commit_button 'Create', | ||
89 | + :button_html => { :disable_with => 'Please wait...' } %> | ||
90 | + <% end %> | ||
91 | +<% end %></code></pre> | ||
92 | + | ||
93 | +If no ActiveRecord is defined named Post, it will generate... | ||
94 | + | ||
95 | +<pre><code><h1>New post</h1> | ||
96 | + | ||
97 | +<% semantic_form_for(@post) do |form| %> | ||
98 | + <% form.inputs %> | ||
99 | + <% form.buttons do %> | ||
100 | + <%= form.commit_button 'Create', | ||
101 | + :button_html => { :disable_with => 'Please wait...' } %> | ||
102 | + <% end %> | ||
103 | +<% end %></code></pre> | ||
104 | + | ||
76 | h2. Model generator: belongs_to | 105 | h2. Model generator: belongs_to |
77 | 106 | ||
78 | $ script/generate model post user:belongs_to | 107 | $ script/generate model post user:belongs_to |
vendor/plugins/blitz/features/step_definitions/view_steps.rb
@@ -13,13 +13,12 @@ end | @@ -13,13 +13,12 @@ end | ||
13 | When /^a SemiFormal "new" view for "posts" should be generated$/ do | 13 | When /^a SemiFormal "new" view for "posts" should be generated$/ do |
14 | assert_generated_file("app/views/posts/new.html.erb") do | 14 | assert_generated_file("app/views/posts/new.html.erb") do |
15 | "<h1>New post</h1>\n\n" << | 15 | "<h1>New post</h1>\n\n" << |
16 | - "<% form_for(@post) do |form| %>\n" << | ||
17 | - " <%= form.error_messages %>\n" << | ||
18 | - " <fieldset class=\"inputs\">\n" << | ||
19 | - " </fieldset>\n" << | ||
20 | - " <fieldset class=\"buttons\">\n" << | ||
21 | - " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << | ||
22 | - " </fieldset>\n" << | 16 | + "<% semantic_form_for(@post) do |form| %>\n" << |
17 | + " <%= form.inputs %>\n" << | ||
18 | + " <% form.buttons do %>\n" << | ||
19 | + " <%= form.commit_button 'Create',\n" << | ||
20 | + " :button_html => { :disable_with => 'Please wait...' } %>\n" << | ||
21 | + " <% end %>\n" << | ||
23 | "<% end %>" | 22 | "<% end %>" |
24 | end | 23 | end |
25 | end | 24 | end |
@@ -27,16 +26,16 @@ end | @@ -27,16 +26,16 @@ end | ||
27 | Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do | 26 | Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do |
28 | assert_generated_file("app/views/posts/new.html.erb") do | 27 | assert_generated_file("app/views/posts/new.html.erb") do |
29 | "<h1>New post</h1>\n\n" << | 28 | "<h1>New post</h1>\n\n" << |
30 | - "<% form_for(@post) do |form| %>\n" << | ||
31 | - " <%= form.error_messages %>\n" << | ||
32 | - " <fieldset class=\"inputs\">\n" << | ||
33 | - " <%= form.string :title %>\n" << | ||
34 | - " <%= form.text :body %>\n" << | ||
35 | - " <%= form.belongs_to :user %>\n" << | ||
36 | - " </fieldset>\n" << | ||
37 | - " <fieldset class=\"buttons\">\n" << | ||
38 | - " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << | ||
39 | - " </fieldset>\n" << | 29 | + "<% semantic_form_for(@post) do |form| %>\n" << |
30 | + " <% form.inputs do %>\n" << | ||
31 | + " <%= form.input :title %>\n" << | ||
32 | + " <%= form.input :body %>\n" << | ||
33 | + " <%= form.input :user %>\n" << | ||
34 | + " <% end %>\n" << | ||
35 | + " <% form.buttons do %>\n" << | ||
36 | + " <%= form.commit_button 'Create',\n" << | ||
37 | + " :button_html => { :disable_with => 'Please wait...' } %>\n" << | ||
38 | + " <% end %>\n" << | ||
40 | "<% end %>" | 39 | "<% end %>" |
41 | end | 40 | end |
42 | end | 41 | end |
vendor/plugins/blitz/features/support/env.rb
@@ -9,7 +9,7 @@ module Test::Unit::Assertions | @@ -9,7 +9,7 @@ module Test::Unit::Assertions | ||
9 | expected = yield | 9 | expected = yield |
10 | body = file.read | 10 | body = file.read |
11 | assert body.include?(expected), | 11 | assert body.include?(expected), |
12 | - "expected #{expected} but was #{body.inspect}" | 12 | + "expected #{expected} but was #{body}" |
13 | end | 13 | end |
14 | end | 14 | end |
15 | end | 15 | end |
vendor/plugins/blitz/generators/view/templates/new.html.erb
1 | <h1>New <%= resource %></h1> | 1 | <h1>New <%= resource %></h1> |
2 | 2 | ||
3 | -<%% form_for(@<%= resource %>) do |form| %> | ||
4 | - <%%= form.error_messages %> | ||
5 | - <fieldset class="inputs"> | 3 | +<%% semantic_form_for(@<%= resource %>) do |form| %> |
6 | <% if active_record_defined? -%> | 4 | <% if active_record_defined? -%> |
5 | + <%% form.inputs do %> | ||
7 | <% columns_for_form.each do |attribute_name, attribute_type| -%> | 6 | <% columns_for_form.each do |attribute_name, attribute_type| -%> |
8 | - <%%= form.<%= attribute_type %> :<%= attribute_name %> %> | 7 | + <%%= form.input :<%= attribute_name %> %> |
9 | <% end -%> | 8 | <% end -%> |
9 | + <%% end %> | ||
10 | +<% else -%> | ||
11 | + <%%= form.inputs %> | ||
10 | <% end -%> | 12 | <% end -%> |
11 | - </fieldset> | ||
12 | - <fieldset class="buttons"> | ||
13 | - <%%= form.submit 'Create', :disable_with => 'Please wait...' %> | ||
14 | - </fieldset> | 13 | + <%% form.buttons do %> |
14 | + <%%= form.commit_button 'Create', | ||
15 | + :button_html => { :disable_with => 'Please wait...' } %> | ||
16 | + <%% end %> | ||
15 | <%% end %> | 17 | <%% end %> |