nifty-generators 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +13 -0
- data/Gemfile.lock +1 -1
- data/README.rdoc +24 -26
- data/features/nifty_authentication.feature +7 -7
- data/features/nifty_scaffold.feature +4 -0
- data/features/step_definitions/common_steps.rb +4 -0
- data/lib/generators/nifty.rb +14 -1
- data/lib/generators/nifty/authentication/authentication_generator.rb +3 -3
- data/lib/generators/nifty/authentication/templates/controller_authentication.rb +1 -1
- data/lib/generators/nifty/authentication/templates/views/haml/_form.html.haml +1 -1
- data/lib/generators/nifty/authentication/templates/views/haml/login.html.haml +1 -1
- data/lib/generators/nifty/scaffold/USAGE +1 -1
- data/lib/generators/nifty/scaffold/scaffold_generator.rb +4 -2
- data/lib/generators/nifty/scaffold/templates/views/haml/_form.html.haml +1 -1
- data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +1 -1
- metadata +3 -3
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
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -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
|
-
==
|
7
|
-
|
8
|
-
gem install nifty-generators
|
6
|
+
== Setup
|
9
7
|
|
8
|
+
=== Rails 3
|
10
9
|
|
11
|
-
|
10
|
+
Add the gem to your Gemfile.
|
12
11
|
|
13
|
-
|
12
|
+
gem "nifty-generators", :group => :development
|
14
13
|
|
15
|
-
|
14
|
+
Then you can run any of the included generators.
|
16
15
|
|
17
|
-
|
16
|
+
rails g nifty:scaffold Recipe name:string index new
|
18
17
|
|
18
|
+
=== Rails 2
|
19
19
|
|
20
|
-
|
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
|
-
|
22
|
+
gem install nifty-generators
|
28
23
|
|
29
|
-
|
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
|
-
|
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
|
-
|
31
|
+
== Included Generators
|
37
32
|
|
38
|
-
|
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
|
-
|
38
|
+
To view the README for each generator, run it with the +help+ option.
|
41
39
|
|
42
|
-
|
40
|
+
rails g nifty:layout --help
|
43
41
|
|
44
42
|
|
45
43
|
== Troubleshooting and FAQs
|
46
44
|
|
47
|
-
<b>What is the difference between
|
45
|
+
<b>What is the difference between nifty:scaffold and built-in scaffold?</b>
|
48
46
|
|
49
|
-
One of the primary differences is that
|
47
|
+
One of the primary differences is that nifty:scaffold allows you to choose which controller actions to generate.
|
50
48
|
|
51
|
-
|
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
|
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
|
-
|
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 => :
|
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 => :
|
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
|
data/lib/generators/nifty.rb
CHANGED
@@ -8,7 +8,20 @@ module Nifty
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.banner
|
11
|
-
"
|
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
|
-
|
21
|
-
|
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 => :
|
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",
|
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
|
@@ -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, `
|
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
|
-
|
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("
|
152
|
+
end.join("\n").strip
|
151
153
|
end
|
152
154
|
|
153
155
|
def render_form
|
@@ -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("
|
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
|
-
-
|
9
|
-
version: 0.4.
|
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-
|
17
|
+
date: 2010-12-28 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|