ghart-nifty-generators 0.3.0.1

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.
Files changed (153) hide show
  1. data/CHANGELOG +105 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +107 -0
  4. data/Rakefile +15 -0
  5. data/TODO +7 -0
  6. data/lib/nifty_generators.rb +3 -0
  7. data/nifty-generators.gemspec +31 -0
  8. data/rails_generators/nifty_admin_scaffold/USAGE +51 -0
  9. data/rails_generators/nifty_admin_scaffold/lib/insert_commands.rb +31 -0
  10. data/rails_generators/nifty_admin_scaffold/nifty_admin_scaffold_generator.rb +238 -0
  11. data/rails_generators/nifty_admin_scaffold/templates/actions/create.rb +8 -0
  12. data/rails_generators/nifty_admin_scaffold/templates/actions/destroy.rb +5 -0
  13. data/rails_generators/nifty_admin_scaffold/templates/actions/edit.rb +3 -0
  14. data/rails_generators/nifty_admin_scaffold/templates/actions/index.rb +3 -0
  15. data/rails_generators/nifty_admin_scaffold/templates/actions/new.rb +3 -0
  16. data/rails_generators/nifty_admin_scaffold/templates/actions/show.rb +3 -0
  17. data/rails_generators/nifty_admin_scaffold/templates/actions/update.rb +8 -0
  18. data/rails_generators/nifty_admin_scaffold/templates/controller.rb +5 -0
  19. data/rails_generators/nifty_admin_scaffold/templates/fixtures.yml +9 -0
  20. data/rails_generators/nifty_admin_scaffold/templates/helper.rb +2 -0
  21. data/rails_generators/nifty_admin_scaffold/templates/migration.rb +16 -0
  22. data/rails_generators/nifty_admin_scaffold/templates/model.rb +3 -0
  23. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  24. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  25. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  26. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  27. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  28. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  29. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  30. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/controller.rb +8 -0
  31. data/rails_generators/nifty_admin_scaffold/templates/tests/rspec/model.rb +7 -0
  32. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  33. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  34. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  35. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  36. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  37. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  38. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  39. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/controller.rb +5 -0
  40. data/rails_generators/nifty_admin_scaffold/templates/tests/shoulda/model.rb +7 -0
  41. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  42. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  43. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  44. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  45. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  46. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  47. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  48. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/controller.rb +5 -0
  49. data/rails_generators/nifty_admin_scaffold/templates/tests/testunit/model.rb +7 -0
  50. data/rails_generators/nifty_admin_scaffold/templates/views/erb/_form.html.erb +10 -0
  51. data/rails_generators/nifty_admin_scaffold/templates/views/erb/edit.html.erb +3 -0
  52. data/rails_generators/nifty_admin_scaffold/templates/views/erb/index.html.erb +29 -0
  53. data/rails_generators/nifty_admin_scaffold/templates/views/erb/new.html.erb +3 -0
  54. data/rails_generators/nifty_admin_scaffold/templates/views/erb/show.html.erb +14 -0
  55. data/rails_generators/nifty_admin_scaffold/templates/views/haml/_form.html.haml +10 -0
  56. data/rails_generators/nifty_admin_scaffold/templates/views/haml/edit.html.haml +14 -0
  57. data/rails_generators/nifty_admin_scaffold/templates/views/haml/index.html.haml +26 -0
  58. data/rails_generators/nifty_admin_scaffold/templates/views/haml/new.html.haml +7 -0
  59. data/rails_generators/nifty_admin_scaffold/templates/views/haml/show.html.haml +12 -0
  60. data/rails_generators/nifty_authentication/USAGE +50 -0
  61. data/rails_generators/nifty_authentication/lib/insert_commands.rb +74 -0
  62. data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +128 -0
  63. data/rails_generators/nifty_authentication/templates/authentication.rb +61 -0
  64. data/rails_generators/nifty_authentication/templates/authlogic_session.rb +2 -0
  65. data/rails_generators/nifty_authentication/templates/fixtures.yml +24 -0
  66. data/rails_generators/nifty_authentication/templates/migration.rb +20 -0
  67. data/rails_generators/nifty_authentication/templates/sessions_controller.rb +45 -0
  68. data/rails_generators/nifty_authentication/templates/sessions_helper.rb +2 -0
  69. data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  70. data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +83 -0
  71. data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +26 -0
  72. data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  73. data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +85 -0
  74. data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +27 -0
  75. data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  76. data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +88 -0
  77. data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +23 -0
  78. data/rails_generators/nifty_authentication/templates/user.rb +42 -0
  79. data/rails_generators/nifty_authentication/templates/users_controller.rb +18 -0
  80. data/rails_generators/nifty_authentication/templates/users_helper.rb +2 -0
  81. data/rails_generators/nifty_authentication/templates/views/erb/login.html.erb +30 -0
  82. data/rails_generators/nifty_authentication/templates/views/erb/signup.html.erb +24 -0
  83. data/rails_generators/nifty_authentication/templates/views/haml/login.html.haml +30 -0
  84. data/rails_generators/nifty_authentication/templates/views/haml/signup.html.haml +24 -0
  85. data/rails_generators/nifty_config/USAGE +23 -0
  86. data/rails_generators/nifty_config/nifty_config_generator.rb +32 -0
  87. data/rails_generators/nifty_config/templates/config.yml +8 -0
  88. data/rails_generators/nifty_config/templates/load_config.rb +2 -0
  89. data/rails_generators/nifty_layout/USAGE +25 -0
  90. data/rails_generators/nifty_layout/lib/insert_commands.rb +43 -0
  91. data/rails_generators/nifty_layout/nifty_layout_generator.rb +55 -0
  92. data/rails_generators/nifty_layout/templates/helper.rb +22 -0
  93. data/rails_generators/nifty_layout/templates/layout.html.haml +26 -0
  94. data/rails_generators/nifty_layout/templates/stylesheet.sass +67 -0
  95. data/rails_generators/nifty_scaffold/USAGE +51 -0
  96. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +237 -0
  97. data/rails_generators/nifty_scaffold/templates/actions/create.rb +9 -0
  98. data/rails_generators/nifty_scaffold/templates/actions/destroy.rb +6 -0
  99. data/rails_generators/nifty_scaffold/templates/actions/edit.rb +3 -0
  100. data/rails_generators/nifty_scaffold/templates/actions/index.rb +3 -0
  101. data/rails_generators/nifty_scaffold/templates/actions/new.rb +3 -0
  102. data/rails_generators/nifty_scaffold/templates/actions/show.rb +3 -0
  103. data/rails_generators/nifty_scaffold/templates/actions/update.rb +9 -0
  104. data/rails_generators/nifty_scaffold/templates/controller.rb +3 -0
  105. data/rails_generators/nifty_scaffold/templates/fixtures.yml +9 -0
  106. data/rails_generators/nifty_scaffold/templates/helper.rb +2 -0
  107. data/rails_generators/nifty_scaffold/templates/migration.rb +16 -0
  108. data/rails_generators/nifty_scaffold/templates/model.rb +3 -0
  109. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  110. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  111. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  112. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  113. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  114. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  115. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  116. data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +8 -0
  117. data/rails_generators/nifty_scaffold/templates/tests/rspec/model.rb +7 -0
  118. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  119. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  120. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  121. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  122. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  123. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  124. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  125. data/rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb +5 -0
  126. data/rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb +7 -0
  127. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  128. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  129. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  130. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  131. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  132. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  133. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  134. data/rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb +5 -0
  135. data/rails_generators/nifty_scaffold/templates/tests/testunit/model.rb +7 -0
  136. data/rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb +10 -0
  137. data/rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb +14 -0
  138. data/rails_generators/nifty_scaffold/templates/views/erb/index.html.erb +29 -0
  139. data/rails_generators/nifty_scaffold/templates/views/erb/new.html.erb +7 -0
  140. data/rails_generators/nifty_scaffold/templates/views/erb/show.html.erb +20 -0
  141. data/rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml +10 -0
  142. data/rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml +14 -0
  143. data/rails_generators/nifty_scaffold/templates/views/haml/index.html.haml +25 -0
  144. data/rails_generators/nifty_scaffold/templates/views/haml/new.html.haml +7 -0
  145. data/rails_generators/nifty_scaffold/templates/views/haml/show.html.haml +20 -0
  146. data/tasks/deployment.rake +2 -0
  147. data/test/test_helper.rb +117 -0
  148. data/test/test_nifty_admin_scaffold_generator.rb +538 -0
  149. data/test/test_nifty_authentication_generator.rb +236 -0
  150. data/test/test_nifty_config_generator.rb +37 -0
  151. data/test/test_nifty_layout_generator.rb +47 -0
  152. data/test/test_nifty_scaffold_generator.rb +538 -0
  153. metadata +222 -0
data/CHANGELOG ADDED
@@ -0,0 +1,105 @@
1
+ 0.3.0 (August 15th, 2009)
2
+
3
+ * adding attr_accessible to models in nifty_scaffold
4
+
5
+ * adding authlogic support with --authlogic option in nifty_authentication
6
+
7
+ * pluralize second argument for controller in nifty_authentication
8
+
9
+ * don't convert javascript/stylesheet arguments to strings in nifty_layout
10
+
11
+ * store request location and redirect to it when logging in under nifty_authentication
12
+
13
+
14
+ 0.2.4 (May 5th, 2009)
15
+
16
+ * using root_url when no index action in nifty_scaffold
17
+
18
+ * making password editable in user model in nifty_authentication
19
+
20
+ * adding filter_parameter_logging :password in nifty_authentication
21
+
22
+
23
+ 0.2.3 (February 20th, 2009)
24
+
25
+ * fixing nifty_authentication to work with Rails 2.3 application_controller.rb
26
+
27
+ * fixing password field in HAML signup page in nifty_authentication
28
+
29
+
30
+ 0.2.2 (November 11th, 2008)
31
+
32
+ * fixing sessions_path reference in nifty_authentication
33
+
34
+ * adding more validations to user model in nifty_authentication
35
+
36
+ * cleaning up nifty_layout stylesheet
37
+
38
+
39
+ 0.2.1 (November 10th, 2008)
40
+
41
+ * adding missing nifty_authentication files
42
+
43
+
44
+ 0.2.0 (November 4th, 2008)
45
+
46
+ * adding nifty_authentication
47
+
48
+
49
+ 0.1.8 (October 3rd, 2008)
50
+
51
+ * compatibility with RubyGems 1.3
52
+
53
+ * using f.error_messages instead of error_messages_for (thanks Zach Langley)
54
+
55
+
56
+ 0.1.7 (August 15th, 2008)
57
+
58
+ * fixing shoulda tests
59
+
60
+
61
+ 0.1.6 (August 7th, 2008)
62
+
63
+ * adding option to specify Shoulda as testing framework in nifty_scaffold generator
64
+
65
+ * adding options to manually specify rspec or testunit framework in nifty_scaffold generator
66
+
67
+
68
+ 0.1.5 (August 7th, 2008)
69
+
70
+ * adding option to nifty layout to generate HAML views and SASS stylesheets
71
+
72
+ * adding option to nifty scaffold to generate HAML views
73
+
74
+
75
+ 0.1.4 (July 21st, 2008)
76
+
77
+ * using same logic as model spec in model test for scaffold
78
+
79
+ * simplifying model spec generated by scaffold
80
+
81
+ * adding error_messages_for to form partial
82
+
83
+
84
+ 0.1.3 (June 20th, 2008)
85
+
86
+ * using _url in controllers instead of _path
87
+
88
+ * improving the nifty_config default example YAML file
89
+
90
+
91
+ 0.1.2 (May 16th, 2008)
92
+
93
+ * mentioning nifty_layout in nifty_scaffold generator
94
+
95
+ * adding nifty_config generator
96
+
97
+
98
+ 0.1.1 (May 9th, 2008)
99
+
100
+ * adding tests and specs to scaffold generator
101
+
102
+
103
+ 0.1.0 (May 8th, 2008)
104
+
105
+ * initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Ryan Bates
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,107 @@
1
+ = Nifty Generators
2
+
3
+ A collection of useful Rails generator scripts.
4
+
5
+
6
+ == Install
7
+
8
+ gem install nifty-generators
9
+
10
+ You may need to uninstall the older version if it's installed.
11
+
12
+ gem uninstall ryanb-nifty-generators
13
+
14
+
15
+ == Usage
16
+
17
+ Once you install the gem, the generators will be available to all Rails
18
+ applications on your system. If you run script/generate without any
19
+ additional arguments you should see the available generators listed.
20
+
21
+ To run the generator, go to your rails project directory and call it
22
+ using the script/generate or script/destroy command.
23
+
24
+ script/generate nifty_scaffold Recipe name:string index new
25
+
26
+
27
+ == Included Generators
28
+
29
+ * nifty_layout: generates generic layout, stylesheet, and helper files.
30
+ * nifty_scaffold: generates a controller and optional model/migration.
31
+ * nifty_config: generates a config YAML file and loader.
32
+ * nifty_authentication: generates user model with sign up and log in.
33
+ * nifty_admin_scaffold: generates an admin controller and optional model/migration.
34
+
35
+ To view the README for each generator, run it with the +--help+ option.
36
+
37
+ script/generate nifty_layout --help
38
+
39
+
40
+ == Troubleshooting and FAQs
41
+
42
+ <b>What is the difference between nifty_scaffold and built-in scaffold?</b>
43
+
44
+ One of the primary differences is that nifty_scaffold allows you to choose which
45
+ controller actions to generate.
46
+
47
+ script/generate nifty_scaffold post name:string index new edit
48
+
49
+ There are a few changes to the generated code as well, such as no XML format by default.
50
+
51
+ It also offers support for HAML, Shoulda, and RSpec.
52
+
53
+
54
+ <b>I get "undefined method 'title'" error.</b>
55
+
56
+ Try running nifty_layout, that will generate this helper method. Or
57
+ you can just change the templates to whatever approach you prefer for
58
+ setting the title.
59
+
60
+
61
+ <b>I can't set new attributes in my model.</b>
62
+
63
+ Add the attribute to the attr_accessible line in the model.
64
+
65
+
66
+ <b>I get "undefined method 'root_url'" error.</b>
67
+
68
+ Some generators default redirecting to the root_url. Set this in your
69
+ routes.rb file like this (substituting your controller name).
70
+
71
+ map.root :controller => 'foo'
72
+
73
+
74
+ <b>I get a missing database error.</b>
75
+
76
+ Run <tt>rake db:migrate</tt>.
77
+
78
+
79
+ <b>I get a routing error when I try to submit a form.</b>
80
+
81
+ Try restarting your development server. Sometimes it doesn't detect the
82
+ change in the routing.
83
+
84
+
85
+ <b>The tests/specs don't work.</b>
86
+
87
+ Make sure you have mocha installed and require it in your spec/test helper.
88
+
89
+ gem install mocha
90
+
91
+ # in spec_helper.rb
92
+ config.mock_with :mocha
93
+
94
+ # in test_helper.rb
95
+ require 'mocha'
96
+
97
+ Also, make sure you're using Rails 2.1 or greater.
98
+
99
+
100
+ == Development
101
+
102
+ This project can be found on github at the following URL.
103
+
104
+ http://github.com/ryanb/nifty-generators/
105
+
106
+ If you wish the generators behaved differently, please consider
107
+ forking the project and modifying to your heart's content.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('nifty-generators', '0.3.0') do |p|
6
+ p.project = "niftygenerators"
7
+ p.description = "A collection of useful generator scripts for Rails."
8
+ p.url = "http://github.com/ghart/nifty-generators"
9
+ p.author = 'Greg Hart'
10
+ p.email = "ghart (at) cs1 (dot) com"
11
+ p.ignore_pattern = ["script/*"]
12
+ p.development_dependencies = []
13
+ end
14
+
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/TODO ADDED
@@ -0,0 +1,7 @@
1
+
2
+ Nifty Scaffold
3
+ - add some validation for attributes/action names
4
+ - refactor out long methods in scaffold generator
5
+
6
+ Nifty Config
7
+ - make it easier to specify non environment specific configs
@@ -0,0 +1,3 @@
1
+ module NiftyGenerators
2
+ # nothing to see here, the real action is under rails_generators
3
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{ghart-nifty-generators}
5
+ s.version = "0.3.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ryan Bates", "Greg Hart"]
9
+ s.date = %q{2009-09-28}
10
+ s.description = %q{A collection of useful generator scripts for Rails.}
11
+ s.email = %q{ryan (at) railscasts (dot) com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "TODO", "lib/nifty_generators.rb", "tasks/deployment.rake"]
13
+ s.files = ["CHANGELOG", "LICENSE", "README.rdoc", "Rakefile", "TODO", "lib/nifty_generators.rb", "rails_generators/nifty_authentication/USAGE", "rails_generators/nifty_authentication/lib/insert_commands.rb", "rails_generators/nifty_authentication/nifty_authentication_generator.rb", "rails_generators/nifty_authentication/templates/authentication.rb", "rails_generators/nifty_authentication/templates/authlogic_session.rb", "rails_generators/nifty_authentication/templates/fixtures.yml", "rails_generators/nifty_authentication/templates/migration.rb", "rails_generators/nifty_authentication/templates/sessions_controller.rb", "rails_generators/nifty_authentication/templates/sessions_helper.rb", "rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb", "rails_generators/nifty_authentication/templates/tests/rspec/user.rb", "rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb", "rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb", "rails_generators/nifty_authentication/templates/tests/shoulda/user.rb", "rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb", "rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb", "rails_generators/nifty_authentication/templates/tests/testunit/user.rb", "rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb", "rails_generators/nifty_authentication/templates/user.rb", "rails_generators/nifty_authentication/templates/users_controller.rb", "rails_generators/nifty_authentication/templates/users_helper.rb", "rails_generators/nifty_authentication/templates/views/erb/login.html.erb", "rails_generators/nifty_authentication/templates/views/erb/signup.html.erb", "rails_generators/nifty_authentication/templates/views/haml/login.html.haml", "rails_generators/nifty_authentication/templates/views/haml/signup.html.haml", "rails_generators/nifty_config/USAGE", "rails_generators/nifty_config/nifty_config_generator.rb", "rails_generators/nifty_config/templates/config.yml", "rails_generators/nifty_config/templates/load_config.rb", "rails_generators/nifty_layout/USAGE", "rails_generators/nifty_layout/nifty_layout_generator.rb", "rails_generators/nifty_layout/lib/insert_commands.rb","rails_generators/nifty_layout/templates/helper.rb", "rails_generators/nifty_layout/templates/layout.html.haml", "rails_generators/nifty_layout/templates/stylesheet.sass", "rails_generators/nifty_scaffold/USAGE", "rails_generators/nifty_scaffold/nifty_scaffold_generator.rb", "rails_generators/nifty_scaffold/templates/actions/create.rb", "rails_generators/nifty_scaffold/templates/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/actions/edit.rb", "rails_generators/nifty_scaffold/templates/actions/index.rb", "rails_generators/nifty_scaffold/templates/actions/new.rb", "rails_generators/nifty_scaffold/templates/actions/show.rb", "rails_generators/nifty_scaffold/templates/actions/update.rb", "rails_generators/nifty_scaffold/templates/controller.rb", "rails_generators/nifty_scaffold/templates/fixtures.yml", "rails_generators/nifty_scaffold/templates/helper.rb", "rails_generators/nifty_scaffold/templates/migration.rb", "rails_generators/nifty_scaffold/templates/model.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb", "rails_generators/nifty_scaffold/templates/tests/rspec/model.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb", "rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb", "rails_generators/nifty_scaffold/templates/tests/testunit/model.rb", "rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb", "rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb", "rails_generators/nifty_scaffold/templates/views/erb/index.html.erb", "rails_generators/nifty_scaffold/templates/views/erb/new.html.erb", "rails_generators/nifty_scaffold/templates/views/erb/show.html.erb", "rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml", "rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml", "rails_generators/nifty_scaffold/templates/views/haml/index.html.haml", "rails_generators/nifty_scaffold/templates/views/haml/new.html.haml", "rails_generators/nifty_scaffold/templates/views/haml/show.html.haml", "rails_generators/nifty_admin_scaffold/USAGE", "rails_generators/nifty_admin_scaffold/lib/insert_commands.rb", "rails_generators/nifty_admin_scaffold/nifty_admin_scaffold_generator.rb", "rails_generators/nifty_admin_scaffold/templates/actions/create.rb", "rails_generators/nifty_admin_scaffold/templates/actions/destroy.rb", "rails_generators/nifty_admin_scaffold/templates/actions/edit.rb", "rails_generators/nifty_admin_scaffold/templates/actions/index.rb", "rails_generators/nifty_admin_scaffold/templates/actions/new.rb", "rails_generators/nifty_admin_scaffold/templates/actions/show.rb", "rails_generators/nifty_admin_scaffold/templates/actions/update.rb", "rails_generators/nifty_admin_scaffold/templates/controller.rb", "rails_generators/nifty_admin_scaffold/templates/fixtures.yml", "rails_generators/nifty_admin_scaffold/templates/helper.rb", "rails_generators/nifty_admin_scaffold/templates/migration.rb", "rails_generators/nifty_admin_scaffold/templates/model.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/create.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/destroy.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/edit.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/index.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/new.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/show.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/actions/update.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/controller.rb", "rails_generators/nifty_admin_scaffold/templates/tests/rspec/model.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/create.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/destroy.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/edit.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/index.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/new.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/show.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/actions/update.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/controller.rb", "rails_generators/nifty_admin_scaffold/templates/tests/shoulda/model.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/create.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/destroy.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/edit.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/index.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/new.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/show.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/actions/update.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/controller.rb", "rails_generators/nifty_admin_scaffold/templates/tests/testunit/model.rb", "rails_generators/nifty_admin_scaffold/templates/views/erb/_form.html.erb", "rails_generators/nifty_admin_scaffold/templates/views/erb/edit.html.erb", "rails_generators/nifty_admin_scaffold/templates/views/erb/index.html.erb", "rails_generators/nifty_admin_scaffold/templates/views/erb/new.html.erb", "rails_generators/nifty_admin_scaffold/templates/views/erb/show.html.erb", "rails_generators/nifty_admin_scaffold/templates/views/haml/_form.html.haml", "rails_generators/nifty_admin_scaffold/templates/views/haml/edit.html.haml", "rails_generators/nifty_admin_scaffold/templates/views/haml/index.html.haml", "rails_generators/nifty_admin_scaffold/templates/views/haml/new.html.haml", "rails_generators/nifty_admin_scaffold/templates/views/haml/show.html.haml", "tasks/deployment.rake", "test/test_helper.rb", "test/test_nifty_authentication_generator.rb", "test/test_nifty_config_generator.rb", "test/test_nifty_layout_generator.rb", "test/test_nifty_scaffold_generator.rb", "test/test_nifty_admin_scaffold_generator.rb", "nifty-generators.gemspec"]
14
+ s.homepage = %q{http://github.com/ghart/nifty-generators}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nifty-generators", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{niftygenerators}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{A collection of useful generator scripts for Rails.}
20
+ s.test_files = ["test/test_helper.rb", "test/test_nifty_authentication_generator.rb", "test/test_nifty_config_generator.rb", "test/test_nifty_layout_generator.rb", "test/test_nifty_scaffold_generator.rb", "test/test_nifty_admin_scaffold_generator.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,51 @@
1
+ Description:
2
+ Scaffolds an entire admin resource, from model and migration to controller and
3
+ views. The resource is ready to use as a starting point for your restful,
4
+ resource-oriented application. Tests or specs are also generated depending
5
+ on if you have a "spec" directory or not.
6
+
7
+ IMPORTANT: This generator uses the "title" helper method which is generated
8
+ by the nifty_layout generator. You may want to run that generator first.
9
+
10
+ Usage:
11
+ Pass the name of the model, either CamelCased or under_scored, as the first
12
+ argument, and an optional list of attribute pairs and controller actions.
13
+
14
+ If no controller actions are specified, they will default to index, show,
15
+ new, create, edit, update, and destroy.
16
+
17
+ IMPORTANT: If no attribute pairs are specified, no model will be generated.
18
+ It will try to determine the attributes from an existing model.
19
+
20
+ Attribute pairs are column_name:sql_type arguments specifying the
21
+ model's attributes. Timestamps are added by default, so you don't have to
22
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
23
+
24
+ For example, `nifty_admin_scaffold post name:string content:text hidden:boolean`
25
+ gives you a model with those three attributes, a controller that handles
26
+ the create/show/update/destroy, forms to create and edit your posts, and
27
+ an index that lists them all, as well as a map.resources :posts
28
+ declaration in config/routes.rb.
29
+
30
+ Adding an "!" in the mix of arguments will invert the passed controller
31
+ actions. This will include all 7 controller actitons except the ones
32
+ mentioned. This option doesn't effect model attributes.
33
+
34
+ Examples:
35
+ script/generate nifty_admin_scaffold post
36
+
37
+ Will create a controller called "posts" it will contain all seven
38
+ CRUD actions along with the views. A model will NOT be created,
39
+ instead it will look for an existing model and use those attributes.
40
+
41
+ script/generate nifty_admin_scaffold post name:string content:text index new edit
42
+
43
+ Will create a Post model and migration file with the name and content
44
+ attributes. It will also create a controller with index, new, create,
45
+ edit, and update actions. Notice the create and update actions are
46
+ added automatically with new and edit.
47
+
48
+ script/generate nifty_admin_scaffold post ! show new
49
+
50
+ Creates a posts controller (no model) with index, edit, update, and
51
+ destroy actions.
@@ -0,0 +1,31 @@
1
+ Rails::Generator::Commands::Create.class_eval do
2
+ def route_namespaced_resources(namespace, *resources)
3
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
4
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
5
+
6
+ logger.route "#{namespace}.resources #{resource_list}"
7
+ unless options[:pretend]
8
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
9
+ "#{match}\n map.namespace(:#{namespace}) do |#{namespace}|\n #{namespace}.resources #{resource_list}\n end\n"
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Rails::Generator::Commands::Destroy.class_eval do
16
+ def route_namespaced_resources(namespace, *resources)
17
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
18
+ look_for = "\n #{namespace}.resources #{resource_list}\n"
19
+ logger.route "#{namespace}.resources #{resource_list}"
20
+ unless options[:pretend]
21
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
22
+ end
23
+ end
24
+ end
25
+
26
+ Rails::Generator::Commands::List.class_eval do
27
+ def route_namespaced_resources(namespace, *resources)
28
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
29
+ logger.route "#{namespace}.resources #{resource_list}"
30
+ end
31
+ end
@@ -0,0 +1,238 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+ class NiftyAdminScaffoldGenerator < Rails::Generator::Base
3
+ attr_accessor :name, :attributes, :controller_actions
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ usage if @args.empty?
8
+
9
+ @name = @args.first
10
+ @controller_actions = []
11
+ @attributes = []
12
+
13
+ @args[1..-1].each do |arg|
14
+ if arg == '!'
15
+ options[:invert] = true
16
+ elsif arg.include? ':'
17
+ @attributes << Rails::Generator::GeneratedAttribute.new(*arg.split(":"))
18
+ else
19
+ @controller_actions << arg
20
+ @controller_actions << 'create' if arg == 'new'
21
+ @controller_actions << 'update' if arg == 'edit'
22
+ end
23
+ end
24
+
25
+ @controller_actions.uniq!
26
+ @attributes.uniq!
27
+
28
+ if options[:invert] || @controller_actions.empty?
29
+ @controller_actions = all_actions - @controller_actions
30
+ end
31
+
32
+ if @attributes.empty?
33
+ options[:skip_model] = true # default to skipping model if no attributes passed
34
+ if model_exists?
35
+ model_columns_for_attributes.each do |column|
36
+ @attributes << Rails::Generator::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
37
+ end
38
+ else
39
+ @attributes << Rails::Generator::GeneratedAttribute.new('name', 'string')
40
+ end
41
+ end
42
+ end
43
+
44
+ def manifest
45
+ record do |m|
46
+ unless options[:skip_model]
47
+ m.directory "app/models"
48
+ m.template "model.rb", "app/models/#{singular_name}.rb"
49
+ unless options[:skip_migration]
50
+ m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
51
+ end
52
+
53
+ if rspec?
54
+ m.directory "spec/models"
55
+ m.template "tests/#{test_framework}/model.rb", "spec/models/#{singular_name}_spec.rb"
56
+ if options[:make_fixture]
57
+ m.directory "spec/fixtures"
58
+ m.template "fixtures.yml", "spec/fixtures/#{plural_name}.yml"
59
+ end
60
+ else
61
+ m.directory "test/unit"
62
+ m.template "tests/#{test_framework}/model.rb", "test/unit/#{singular_name}_test.rb"
63
+ if options[:make_fixture]
64
+ m.directory "test/fixtures"
65
+ m.template "fixtures.yml", "test/fixtures/#{plural_name}.yml"
66
+ end
67
+ end
68
+ end
69
+
70
+ unless options[:skip_controller]
71
+ m.directory "app/controllers/admin"
72
+ m.template "controller.rb", "app/controllers/admin/#{plural_name}_controller.rb"
73
+
74
+ m.directory "app/helpers/admin"
75
+ m.template "helper.rb", "app/helpers/admin/#{plural_name}_helper.rb"
76
+
77
+ m.directory "app/views/admin/#{plural_name}"
78
+ controller_actions.each do |action|
79
+ if File.exist? source_path("views/#{view_language}/#{action}.html.#{view_language}")
80
+ m.template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/admin/#{plural_name}/#{action}.html.#{view_language}"
81
+ end
82
+ end
83
+
84
+ if form_partial?
85
+ m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/admin/#{plural_name}/_form.html.#{view_language}"
86
+ end
87
+
88
+ m.route_namespaced_resources :admin, plural_name
89
+
90
+ if rspec?
91
+ m.directory "spec/controllers/admin"
92
+ m.template "tests/#{test_framework}/controller.rb", "spec/controllers/admin/#{plural_name}_controller_spec.rb"
93
+ else
94
+ m.directory "test/functional/admin"
95
+ m.template "tests/#{test_framework}/controller.rb", "test/functional/admin/#{plural_name}_controller_test.rb"
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ def form_partial?
102
+ actions? :new, :edit
103
+ end
104
+
105
+ def all_actions
106
+ %w[index show new create edit update destroy]
107
+ end
108
+
109
+ def action?(name)
110
+ controller_actions.include? name.to_s
111
+ end
112
+
113
+ def actions?(*names)
114
+ names.all? { |n| action? n.to_s }
115
+ end
116
+
117
+ def singular_name
118
+ name.underscore
119
+ end
120
+
121
+ def plural_name
122
+ name.underscore.pluralize
123
+ end
124
+
125
+ def class_name
126
+ name.camelize
127
+ end
128
+
129
+ def plural_class_name
130
+ plural_name.camelize
131
+ end
132
+
133
+ def controller_methods(dir_name)
134
+ controller_actions.map do |action|
135
+ read_template("#{dir_name}/#{action}.rb")
136
+ end.join(" \n").strip
137
+ end
138
+
139
+ def render_form
140
+ if form_partial?
141
+ if options[:haml]
142
+ "= render :partial => 'form'"
143
+ else
144
+ "<%= render :partial => 'form' %>"
145
+ end
146
+ else
147
+ read_template("views/#{view_language}/_form.html.#{view_language}")
148
+ end
149
+ end
150
+
151
+ def items_path(suffix = 'path')
152
+ if action? :index
153
+ "admin_#{plural_name}_#{suffix}"
154
+ else
155
+ "root_#{suffix}"
156
+ end
157
+ end
158
+
159
+ def item_path(suffix = 'path')
160
+ if action? :show
161
+ "@#{singular_name}"
162
+ else
163
+ items_path(suffix)
164
+ end
165
+ end
166
+
167
+ def item_path_for_spec(suffix = 'path')
168
+ if action? :show
169
+ "#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
170
+ else
171
+ items_path(suffix)
172
+ end
173
+ end
174
+
175
+ def item_path_for_test(suffix = 'path')
176
+ if action? :show
177
+ "#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
178
+ else
179
+ items_path(suffix)
180
+ end
181
+ end
182
+
183
+ def model_columns_for_attributes
184
+ class_name.constantize.columns.reject do |column|
185
+ column.name.to_s =~ /^(id|created_at|updated_at)$/
186
+ end
187
+ end
188
+
189
+ def rspec?
190
+ test_framework == :rspec
191
+ end
192
+
193
+ protected
194
+
195
+ def view_language
196
+ options[:haml] ? 'haml' : 'erb'
197
+ end
198
+
199
+ def test_framework
200
+ options[:test_framework] ||= default_test_framework
201
+ end
202
+
203
+ def default_test_framework
204
+ File.exist?(destination_path("spec")) ? :rspec : :testunit
205
+ end
206
+
207
+ def add_options!(opt)
208
+ opt.separator ''
209
+ opt.separator 'Options:'
210
+ opt.on("--skip-model", "Don't generate a model or migration file.") { |v| options[:skip_model] = v }
211
+ opt.on("--skip-migration", "Don't generate migration file for model.") { |v| options[:skip_migration] = v }
212
+ opt.on("--skip-timestamps", "Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
213
+ opt.on("--skip-controller", "Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
214
+ opt.on("--make-fixture", "Only generate fixture file for model if requested.") { |v| options[:make_fixture] = v }
215
+ opt.on("--invert", "Generate all controller actions except these mentioned.") { |v| options[:invert] = v }
216
+ opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = v }
217
+ opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
218
+ opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
219
+ opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
220
+ end
221
+
222
+ # is there a better way to do this? Perhaps with const_defined?
223
+ def model_exists?
224
+ File.exist? destination_path("app/models/#{singular_name}.rb")
225
+ end
226
+
227
+ def read_template(relative_path)
228
+ ERB.new(File.read(source_path(relative_path)), nil, '-').result(binding)
229
+ end
230
+
231
+ def banner
232
+ <<-EOS
233
+ Creates a controller and optional model given the name, actions, and attributes.
234
+
235
+ USAGE: #{$0} #{spec.name} ModelName [controller_actions and model:attributes] [options]
236
+ EOS
237
+ end
238
+ end