nifty-generators 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,16 @@
1
+ 0.4.3 (December 28, 2010)
2
+
3
+ * display usage documentation when given an invalid model name with nifty:scaffold - issue #76
4
+
5
+ * add newline when necessary to Gemfile before adding gem - issue #64
6
+
7
+ * remove extra whitespace between controller methods in nifty:scaffold - issue #62
8
+
9
+ * renaming edit_user route to edit_current_user - issue #59
10
+
11
+ * HAML template improvements (thanks IamNaN) - issue #71
12
+
13
+
1
14
  0.4.2 (October 15, 2010)
2
15
 
3
16
  * adding mocha to Gemfile automatically if it's not there already
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nifty-generators (0.4.1)
4
+ nifty-generators (0.4.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -3,52 +3,50 @@
3
3
  A collection of useful Rails generator scripts for scaffolding, layout files, authentication, and more.
4
4
 
5
5
 
6
- == Install
7
-
8
- gem install nifty-generators
6
+ == Setup
9
7
 
8
+ === Rails 3
10
9
 
11
- == Usage
10
+ Add the gem to your Gemfile.
12
11
 
13
- Once you install the gem, the generators will be available to all Rails applications on your system. If you run script/generate without any additional arguments you should see the available generators listed.
12
+ gem "nifty-generators", :group => :development
14
13
 
15
- To run the generator, go to your rails project directory and call it using the script/generate or script/destroy command.
14
+ Then you can run any of the included generators.
16
15
 
17
- script/generate nifty_scaffold Recipe name:string index new
16
+ rails g nifty:scaffold Recipe name:string index new
18
17
 
18
+ === Rails 2
19
19
 
20
- == Included Generators
21
-
22
- * nifty_layout: generates generic layout, stylesheet, and helper files.
23
- * nifty_scaffold: generates a controller and optional model/migration.
24
- * nifty_config: generates a config YAML file and loader.
25
- * nifty_authentication: generates user model with sign up and log in.
20
+ First install the gem.
26
21
 
27
- To view the README for each generator, run it with the +help+ option.
22
+ gem install nifty-generators
28
23
 
29
- script/generate nifty_layout --help
24
+ The generators will be available in all Rails applications. To run the generator, go to your rails project directory and call it using the script/generate or script/destroy command.
30
25
 
26
+ script/generate nifty_scaffold Recipe name:string index new
31
27
 
32
- == Rails 3
28
+ Note an underscore is used instead of a colon for the Rails 2 generators.
33
29
 
34
- To use Nifty Generators with Rails 3 you will need to include it in your Gemfile.
35
30
 
36
- gem "nifty-generators"
31
+ == Included Generators
37
32
 
38
- The generators use a colon as the separator instead of an underscore.
33
+ * nifty:layout: generates generic layout, stylesheet, and helper files.
34
+ * nifty:scaffold: generates a controller and optional model/migration.
35
+ * nifty:config: generates a config YAML file and loader.
36
+ * nifty:authentication: generates user model with sign up and log in.
39
37
 
40
- rails g nifty:layout
38
+ To view the README for each generator, run it with the +help+ option.
41
39
 
42
- The Rails 3 support is still in early development, please {report any issues}[http://github.com/ryanb/nifty-generators/issues] you find.
40
+ rails g nifty:layout --help
43
41
 
44
42
 
45
43
  == Troubleshooting and FAQs
46
44
 
47
- <b>What is the difference between nifty_scaffold and built-in scaffold?</b>
45
+ <b>What is the difference between nifty:scaffold and built-in scaffold?</b>
48
46
 
49
- One of the primary differences is that nifty_scaffold allows you to choose which controller actions to generate.
47
+ One of the primary differences is that nifty:scaffold allows you to choose which controller actions to generate.
50
48
 
51
- script/generate nifty_scaffold post name:string index new edit
49
+ rails g nifty:scaffold post name:string index new edit
52
50
 
53
51
  There are a few changes to the generated code as well, such as no XML format by default.
54
52
 
@@ -57,7 +55,7 @@ It also offers support for HAML, Shoulda, and RSpec.
57
55
 
58
56
  <b>I get "undefined method 'title'" error.</b>
59
57
 
60
- Try running nifty_layout, that will generate this helper method. Or you can just change the templates to whatever approach you prefer for setting the title.
58
+ Try running nifty:layout, that will generate this helper method. Or you can just change the templates to whatever approach you prefer for setting the title.
61
59
 
62
60
 
63
61
  <b>I can't set new attributes in my model.</b>
@@ -69,7 +67,7 @@ Add the attribute to the attr_accessible line in the model.
69
67
 
70
68
  Some generators default redirecting to the root_url. Set this in your routes.rb file like this (substituting your controller name).
71
69
 
72
- map.root :controller => 'foo'
70
+ root :to => "home#index"
73
71
 
74
72
 
75
73
  <b>I get a missing database error.</b>
@@ -22,12 +22,12 @@ Feature: Nifty Authentication Generator
22
22
  | test/functional/sessions_controller_test.rb |
23
23
  | db/migrate |
24
24
  And I should see the following in file "config/routes.rb"
25
- | resources :sessions |
26
- | resources :users |
27
- | match 'login' => 'sessions#new', :as => :login |
28
- | match 'logout' => 'sessions#destroy', :as => :logout |
29
- | match 'signup' => 'users#new', :as => :signup |
30
- | match 'user/edit' => 'users#edit', :as => :edit_user |
25
+ | resources :sessions |
26
+ | resources :users |
27
+ | match 'login' => 'sessions#new', :as => :login |
28
+ | match 'logout' => 'sessions#destroy', :as => :logout |
29
+ | match 'signup' => 'users#new', :as => :signup |
30
+ | match 'user/edit' => 'users#edit', :as => :edit_current_user |
31
31
  And I should see "include ControllerAuthentication" in file "app/controllers/application_controller.rb"
32
32
  And I should see "gem "mocha", :group => :test" in file "Gemfile"
33
33
  And I should see "gem "bcrypt-ruby", :require => "bcrypt"" in file "Gemfile"
@@ -57,7 +57,7 @@ Feature: Nifty Authentication Generator
57
57
  | match 'login' => 'current_sessions#new', :as => :login |
58
58
  | match 'logout' => 'current_sessions#destroy', :as => :logout |
59
59
  | match 'signup' => 'accounts#new', :as => :signup |
60
- | match 'account/edit' => 'accounts#edit', :as => :edit_account |
60
+ | match 'account/edit' => 'accounts#edit', :as => :edit_current_account |
61
61
  When I run "rails g nifty:layout -f"
62
62
  And I run "rake db:migrate"
63
63
  Then I should successfully run "rake test"
@@ -38,3 +38,7 @@ Feature: Nifty Scaffold Generator
38
38
  And I run "rails g rspec:install"
39
39
  And I replace "mock_with :rspec" with "mock_with :mocha" in file "spec/spec_helper.rb"
40
40
  Then I should successfully run "rake spec"
41
+
42
+ Scenario: Report error when invalid model name
43
+ Given a new Rails app
44
+ Then I should see "Usage:" when running "rails g nifty:scaffold name:string parent_id:integer"
@@ -42,3 +42,7 @@ end
42
42
  Then /^I should successfully run "([^\"]*)"$/ do |command|
43
43
  system("cd #{@current_directory} && #{command}").should be_true
44
44
  end
45
+
46
+ Then /^I should see "([^\"]*)" when running "([^\"]*)"$/ do |expected_response, command|
47
+ `cd #{@current_directory} && #{command}`.should include(expected_response)
48
+ end
@@ -8,7 +8,20 @@ module Nifty
8
8
  end
9
9
 
10
10
  def self.banner
11
- "#{$0} nifty:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
11
+ "rails generate nifty:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
+ end
13
+
14
+ private
15
+
16
+ def add_gem(name, options = {})
17
+ gemfile_content = File.read(destination_path("Gemfile"))
18
+ File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
19
+ gem name, options unless gemfile_content.include? name
20
+ end
21
+
22
+ def print_usage
23
+ self.class.help(Thor::Base.shell.new)
24
+ exit
12
25
  end
13
26
  end
14
27
  end
@@ -17,8 +17,8 @@ module Nifty
17
17
  class_option :authlogic, :desc => 'Use Authlogic for authentication.', :type => :boolean
18
18
 
19
19
  def add_gems
20
- gem "bcrypt-ruby", :require => "bcrypt" unless File.read(destination_path("Gemfile")).include? "bcrypt"
21
- gem "mocha", :group => :test unless File.read(destination_path("Gemfile")).include? "mocha"
20
+ add_gem "bcrypt-ruby", :require => "bcrypt"
21
+ add_gem "mocha", :group => :test
22
22
  end
23
23
 
24
24
  def create_model_files
@@ -53,7 +53,7 @@ module Nifty
53
53
  route "match 'login' => '#{session_plural_name}#new', :as => :login"
54
54
  route "match 'logout' => '#{session_plural_name}#destroy', :as => :logout"
55
55
  route "match 'signup' => '#{user_plural_name}#new', :as => :signup"
56
- route "match '#{user_singular_name}/edit' => '#{user_plural_name}#edit', :as => :edit_#{user_singular_name}"
56
+ route "match '#{user_singular_name}/edit' => '#{user_plural_name}#edit', :as => :edit_current_#{user_singular_name}"
57
57
  end
58
58
 
59
59
  def create_migration
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # <%% if logged_in? %>
6
6
  # Welcome <%%= current_<%= user_singular_name %>.username %>.
7
- # <%%= link_to "Edit profile", edit_<%= user_singular_name %>_path %> or
7
+ # <%%= link_to "Edit profile", edit_current_<%= user_singular_name %>_path %> or
8
8
  # <%%= link_to "Log out", logout_path %>
9
9
  # <%% else %>
10
10
  # <%%= link_to "Sign up", signup_path %> or
@@ -1,4 +1,4 @@
1
- - form_for @<%= user_singular_name %> do |f|
1
+ = form_for @<%= user_singular_name %> do |f|
2
2
  = f.error_messages
3
3
  %p
4
4
  = f.label :username
@@ -3,7 +3,7 @@
3
3
  %p== Don't have an account? #{link_to "Sign up!", signup_path}
4
4
 
5
5
  <%- if options[:authlogic] -%>
6
- - form_for @<%= session_singular_name %> do |f|
6
+ = form_for @<%= session_singular_name %> do |f|
7
7
  = f.error_messages
8
8
  %p
9
9
  = f.label :username
@@ -21,7 +21,7 @@ Usage:
21
21
  model's attributes. Timestamps are added by default, so you don't have to
22
22
  specify them by hand as 'created_at:datetime updated_at:datetime'.
23
23
 
24
- For example, `nifty_scaffold post name:string content:text hidden:boolean`
24
+ For example, `nifty:scaffold post name:string content:text hidden:boolean`
25
25
  gives you a model with those three attributes, a controller that handles
26
26
  the create/show/update/destroy, forms to create and edit your posts, and
27
27
  an index that lists them all, as well as a map.resources :posts
@@ -25,6 +25,8 @@ module Nifty
25
25
  def initialize(*args, &block)
26
26
  super
27
27
 
28
+ print_usage unless model_name =~ /^[a-zA-Z_]+$/
29
+
28
30
  @controller_actions = []
29
31
  @model_attributes = []
30
32
  @skip_model = options.skip_model?
@@ -62,7 +64,7 @@ module Nifty
62
64
  end
63
65
 
64
66
  def add_gems
65
- gem "mocha", :group => :test unless File.read(destination_path("Gemfile")).include? "mocha"
67
+ add_gem "mocha", :group => :test
66
68
  end
67
69
 
68
70
  def create_model
@@ -147,7 +149,7 @@ module Nifty
147
149
  def controller_methods(dir_name)
148
150
  controller_actions.map do |action|
149
151
  read_template("#{dir_name}/#{action}.rb")
150
- end.join(" \n").strip
152
+ end.join("\n").strip
151
153
  end
152
154
 
153
155
  def render_form
@@ -1,4 +1,4 @@
1
- - form_for @<%= singular_name %> do |f|
1
+ = form_for @<%= singular_name %> do |f|
2
2
  = f.error_messages
3
3
  <%- for attribute in model_attributes -%>
4
4
  %p
@@ -128,7 +128,7 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
128
128
  def controller_methods(dir_name)
129
129
  controller_actions.map do |action|
130
130
  read_template("#{dir_name}/#{action}.rb")
131
- end.join(" \n").strip
131
+ end.join("\n").strip
132
132
  end
133
133
 
134
134
  def render_form
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 2
9
- version: 0.4.2
8
+ - 3
9
+ version: 0.4.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Bates
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-15 00:00:00 -07:00
17
+ date: 2010-12-28 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency