very_nifty_generators 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/README +21 -1
  2. data/README.rdoc +20 -1
  3. data/TODO +1 -0
  4. data/bin/nifty_app +28 -0
  5. data/bin/nifty_auth +26 -0
  6. data/bin/nifty_config +26 -0
  7. data/bin/nifty_controller +28 -0
  8. data/bin/nifty_layout +26 -0
  9. data/bin/nifty_scaffold +28 -0
  10. data/lib/generators/nifty/app/USAGE +9 -0
  11. data/lib/generators/nifty/app/app_generator.rb +215 -0
  12. data/lib/generators/nifty/app/templates/Gemfile +28 -0
  13. data/lib/generators/nifty/app/templates/README +216 -0
  14. data/lib/generators/nifty/app/templates/Rakefile +10 -0
  15. data/lib/generators/nifty/app/templates/app/controllers/application_controller.rb +3 -0
  16. data/lib/generators/nifty/app/templates/app/helpers/application_helper.rb +2 -0
  17. data/lib/generators/nifty/app/templates/config/application.rb +37 -0
  18. data/lib/generators/nifty/app/templates/config/boot.rb +38 -0
  19. data/lib/generators/nifty/app/templates/config/environment.rb +5 -0
  20. data/lib/generators/nifty/app/templates/config/environments/development.rb.tt +19 -0
  21. data/lib/generators/nifty/app/templates/config/environments/production.rb.tt +33 -0
  22. data/lib/generators/nifty/app/templates/config/environments/test.rb.tt +29 -0
  23. data/lib/generators/nifty/app/templates/config/initializers/backtrace_silencers.rb +7 -0
  24. data/lib/generators/nifty/app/templates/config/initializers/cookie_verification_secret.rb.tt +7 -0
  25. data/lib/generators/nifty/app/templates/config/initializers/inflections.rb +10 -0
  26. data/lib/generators/nifty/app/templates/config/initializers/mime_types.rb +5 -0
  27. data/lib/generators/nifty/app/templates/config/initializers/session_store.rb.tt +15 -0
  28. data/lib/generators/nifty/app/templates/config/locales/en.yml +5 -0
  29. data/lib/generators/nifty/app/templates/config/routes.rb +58 -0
  30. data/lib/generators/nifty/app/templates/config.ru +4 -0
  31. data/lib/generators/nifty/app/templates/db/seeds.rb +7 -0
  32. data/lib/generators/nifty/app/templates/doc/README_FOR_APP +2 -0
  33. data/lib/generators/nifty/app/templates/gitignore +2 -0
  34. data/lib/generators/nifty/app/templates/public/404.html +26 -0
  35. data/lib/generators/nifty/app/templates/public/422.html +26 -0
  36. data/lib/generators/nifty/app/templates/public/500.html +26 -0
  37. data/lib/generators/nifty/app/templates/public/favicon.ico +0 -0
  38. data/lib/generators/nifty/app/templates/public/images/rails.png +0 -0
  39. data/lib/generators/nifty/app/templates/public/javascripts/application.js +2 -0
  40. data/lib/generators/nifty/app/templates/public/robots.txt +5 -0
  41. data/lib/generators/nifty/app/templates/script/about +3 -0
  42. data/lib/generators/nifty/app/templates/script/console.tt +5 -0
  43. data/lib/generators/nifty/app/templates/script/dbconsole.tt +5 -0
  44. data/lib/generators/nifty/app/templates/script/destroy +2 -0
  45. data/lib/generators/nifty/app/templates/script/generate +2 -0
  46. data/lib/generators/nifty/app/templates/script/performance/benchmarker +2 -0
  47. data/lib/generators/nifty/app/templates/script/performance/profiler +2 -0
  48. data/lib/generators/nifty/app/templates/script/plugin +2 -0
  49. data/lib/generators/nifty/app/templates/script/runner +3 -0
  50. data/lib/generators/nifty/app/templates/script/server.tt +5 -0
  51. data/lib/generators/nifty/app/templates/test/performance/browsing_test.rb +9 -0
  52. data/lib/generators/nifty/app/templates/test/test_helper.rb +13 -0
  53. data/lib/generators/nifty/authentication/USAGE +51 -0
  54. data/lib/generators/nifty/authentication/authentication_generator.rb +2 -1
  55. data/lib/generators/nifty/config/USAGE +24 -0
  56. data/lib/generators/nifty/config/config_generator.rb +2 -1
  57. data/lib/generators/nifty/controller/TODO +1 -0
  58. data/lib/generators/nifty/controller/USAGE +4 -0
  59. data/lib/generators/nifty/controller/controller_generator.rb +80 -0
  60. data/lib/generators/nifty/controller/templates/_controller.rb +4 -0
  61. data/lib/generators/nifty/controller/templates/actions/create.rb +4 -0
  62. data/lib/generators/nifty/controller/templates/actions/destroy.rb +4 -0
  63. data/lib/generators/nifty/controller/templates/actions/edit.rb +3 -0
  64. data/lib/generators/nifty/controller/templates/actions/index.rb +3 -0
  65. data/lib/generators/nifty/controller/templates/actions/new.rb +3 -0
  66. data/lib/generators/nifty/controller/templates/actions/show.rb +3 -0
  67. data/lib/generators/nifty/controller/templates/actions/update.rb +5 -0
  68. data/lib/generators/nifty/controller/templates/controller.rb +24 -0
  69. data/lib/generators/nifty/layout/USAGE +25 -0
  70. data/lib/generators/nifty/scaffold/USAGE +51 -0
  71. data/lib/generators/nifty/scaffold/scaffold_generator.rb +17 -5
  72. data/lib/generators/nifty/scaffold/templates/actions/new.rb +1 -1
  73. metadata +77 -5
data/README CHANGED
@@ -1,2 +1,22 @@
1
1
  Rails 3 nifty generators based on efforts by ryanb and dvyjones.
2
- The goal is to use the very DRY rails 3 conventions.
2
+ The generators use the very DRY rails 3 conventions as described by ryanb
3
+
4
+ http://ryandaigle.com/articles/2009/8/10/what-s-new-in-edge-rails-default-restful-rendering
5
+ http://ryandaigle.com/articles/2009/8/6/what-s-new-in-edge-rails-cleaner-restful-controllers-w-respond_with
6
+
7
+ The gem comes with executables that can be found in the /bin folder
8
+ nifty_auth
9
+ nifty_config
10
+ nifty_layout
11
+ nifty_scaffold [model:string] [attributes:hash]
12
+
13
+ Example
14
+ $ nifty_scaffold Person name:string birthdate:date
15
+
16
+ The executables are installed when the gem is installed on your system
17
+ $ sudo gem install very_nifty_generators
18
+
19
+ Note: More nifty generators for rails 3 are in the pipeline… feel free to come with suggestions.
20
+
21
+ Also check out my monog_model_r3 gem with generators for use with mongo DB ;)
22
+
data/README.rdoc CHANGED
@@ -1,7 +1,26 @@
1
1
  = very_nifty_generators
2
2
 
3
3
  Rails 3 nifty generators based on efforts by ryanb and dvyjones.
4
- The goal is to use the very DRY rails 3 conventions.
4
+ The generators use the very DRY rails 3 conventions as described by ryanb
5
+
6
+ http://ryandaigle.com/articles/2009/8/10/what-s-new-in-edge-rails-default-restful-rendering
7
+ http://ryandaigle.com/articles/2009/8/6/what-s-new-in-edge-rails-cleaner-restful-controllers-w-respond_with
8
+
9
+ The gem comes with executables that can be found in the /bin folder
10
+ nifty_auth
11
+ nifty_config
12
+ nifty_layout
13
+ nifty_scaffold [model:string] [attributes:hash]
14
+
15
+ Example
16
+ $ nifty_scaffold Person name:string birthdate:date
17
+
18
+ The executables are installed when the gem is installed on your system
19
+ $ sudo gem install very_nifty_generators
20
+
21
+ Note: More nifty generators for rails 3 are in the pipeline… feel free to come with suggestions.
22
+
23
+ Also check out my monog_model_r3 gem with generators for use with mongo DB ;)
5
24
 
6
25
  == Note on Patches/Pull Requests
7
26
 
data/TODO ADDED
@@ -0,0 +1 @@
1
+ nifty_controller
data/bin/nifty_app ADDED
@@ -0,0 +1,28 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ ARGV << "--help" if ARGV.empty?
24
+
25
+ require 'rails/generators'
26
+ require 'generators/nifty/app/app_generator'
27
+
28
+ Nifty::Generators::AppGenerator.start
data/bin/nifty_auth ADDED
@@ -0,0 +1,26 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ require 'rails/generators'
24
+ require 'generators/nifty/authentication/authentication_generator'
25
+
26
+ Nifty::Generators::AuthenticationGenerator.start
data/bin/nifty_config ADDED
@@ -0,0 +1,26 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ require 'rails/generators'
24
+ require 'generators/nifty/config/config_generator'
25
+
26
+ Nifty::Generators::ConfigGenerator.start
@@ -0,0 +1,28 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ ARGV << "--help" if ARGV.empty?
24
+
25
+ require 'rails/generators'
26
+ require 'generators/nifty/controller/controller_generator'
27
+
28
+ Nifty::Generators::ControllerGenerator.start
data/bin/nifty_layout ADDED
@@ -0,0 +1,26 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ require 'rails/generators'
24
+ require 'generators/nifty/layout/layout_generator'
25
+
26
+ Nifty::Generators::LayoutGenerator.start
@@ -0,0 +1,28 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ ARGV << "--help" if ARGV.empty?
24
+
25
+ require 'rails/generators'
26
+ require 'generators/nifty/scaffold/scaffold_generator'
27
+
28
+ Nifty::Generators::ScaffoldGenerator.start
@@ -0,0 +1,9 @@
1
+ Description:
2
+ The 'rails' command creates a new Rails application with a default
3
+ directory structure and configuration at the path you specify.
4
+
5
+ Example:
6
+ rails ~/Code/Ruby/weblog
7
+
8
+ This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
9
+ See the README in the newly created application to get going.
@@ -0,0 +1,215 @@
1
+ require 'digest/md5'
2
+ require 'active_support/secure_random'
3
+ require 'rails/version' unless defined?(Rails::VERSION)
4
+ require 'generators/nifty'
5
+
6
+ module Nifty
7
+ module Generators
8
+ # We need to store the RAILS_DEV_PATH in a constant, otherwise the path
9
+ # can change in Ruby 1.8.7 when we FileUtils.cd.
10
+ RAILS_DEV_PATH = File.expand_path("../../../../..", File.dirname(__FILE__))
11
+ class AppGenerator < Base
12
+ add_shebang_option!
13
+
14
+ argument :app_path, :type => :string
15
+
16
+ class_option :template, :type => :string, :aliases => "-m",
17
+ :desc => "Path to an application template (can be a filesystem path or URL)."
18
+
19
+ class_option :dev, :type => :boolean, :default => false,
20
+ :desc => "Setup the application with Gemfile pointing to your Rails checkout"
21
+
22
+ class_option :edge, :type => :boolean, :default => false,
23
+ :desc => "Setup the application with Gemfile pointing to Rails repository"
24
+
25
+ class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
26
+ :desc => "Skip Git ignores and keeps"
27
+
28
+ # Add bin/rails options
29
+ class_option :version, :type => :boolean, :aliases => "-v", :group => :rails,
30
+ :desc => "Show Rails version number and quit"
31
+
32
+ class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
33
+ :desc => "Show this help message and quit"
34
+
35
+ def self.source_root
36
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
37
+ end
38
+
39
+ def initialize(*args)
40
+ super
41
+ end
42
+
43
+ def create_root
44
+ self.destination_root = File.expand_path(app_path, destination_root)
45
+ valid_app_const?
46
+
47
+ empty_directory '.'
48
+ set_default_accessors!
49
+ FileUtils.cd(destination_root)
50
+ end
51
+
52
+ def create_root_files
53
+ # puts "Source path: #{self.source_root}"
54
+ copy_file "README"
55
+ copy_file "gitignore", ".gitignore" unless options[:skip_git]
56
+ template "Rakefile"
57
+ template "config.ru"
58
+ template "Gemfile"
59
+ end
60
+
61
+ def create_app_files
62
+ directory "app"
63
+ end
64
+
65
+ def create_config_files
66
+ empty_directory "config"
67
+
68
+ inside "config" do
69
+ template "routes.rb"
70
+ template "application.rb"
71
+ template "environment.rb"
72
+
73
+ directory "environments"
74
+ directory "initializers"
75
+ directory "locales"
76
+ end
77
+ end
78
+
79
+ def create_boot_file
80
+ template "config/boot.rb"
81
+ end
82
+
83
+ def create_db_files
84
+ directory "db"
85
+ end
86
+
87
+ def create_doc_files
88
+ directory "doc"
89
+ end
90
+
91
+ def create_lib_files
92
+ empty_directory "lib"
93
+ empty_directory_with_gitkeep "lib/tasks"
94
+ empty_directory_with_gitkeep "lib/generators"
95
+ end
96
+
97
+ def create_log_files
98
+ empty_directory "log"
99
+
100
+ inside "log" do
101
+ %w( server production development test ).each do |file|
102
+ create_file "#{file}.log"
103
+ chmod "#{file}.log", 0666, :verbose => false
104
+ end
105
+ end
106
+ end
107
+
108
+ def create_public_files
109
+ directory "public", "public", :recursive => false # Do small steps, so anyone can overwrite it.
110
+ end
111
+
112
+ def create_public_image_files
113
+ directory "public/images"
114
+ end
115
+
116
+ def create_public_stylesheets_files
117
+ empty_directory_with_gitkeep "public/stylesheets"
118
+ end
119
+
120
+ def create_javascript_files
121
+ directory "public/javascripts"
122
+ end
123
+
124
+ def create_script_files
125
+ directory "script" do |content|
126
+ "#{shebang}\n" + content
127
+ end
128
+ chmod "script", 0755, :verbose => false
129
+ end
130
+
131
+ def create_test_files
132
+ directory "test"
133
+ end
134
+
135
+ def create_tmp_files
136
+ empty_directory "tmp"
137
+
138
+ inside "tmp" do
139
+ %w(sessions sockets cache pids).each do |dir|
140
+ empty_directory(dir)
141
+ end
142
+ end
143
+ end
144
+
145
+ def create_vendor_files
146
+ empty_directory_with_gitkeep "vendor/plugins"
147
+ end
148
+
149
+ def apply_rails_template
150
+ apply rails_template if rails_template
151
+ rescue Thor::Error, LoadError, Errno::ENOENT => e
152
+ raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
153
+ end
154
+
155
+ def bundle_if_dev_or_edge
156
+ run "gem bundle" if dev_or_edge?
157
+ end
158
+
159
+ protected
160
+ attr_accessor :rails_template
161
+
162
+ def set_default_accessors!
163
+ self.rails_template = case options[:template]
164
+ when /^http:\/\//
165
+ options[:template]
166
+ when String
167
+ File.expand_path(options[:template], Dir.pwd)
168
+ else
169
+ options[:template]
170
+ end
171
+ end
172
+
173
+ # Define file as an alias to create_file for backwards compatibility.
174
+ def file(*args, &block)
175
+ create_file(*args, &block)
176
+ end
177
+
178
+ def app_name
179
+ @app_name ||= File.basename(destination_root)
180
+ end
181
+
182
+ def app_const_base
183
+ @app_const_base ||= app_name.gsub(/\W/, '_').squeeze('_').camelize
184
+ end
185
+
186
+ def app_const
187
+ @app_const ||= "#{app_const_base}::Application"
188
+ end
189
+
190
+ def valid_app_const?
191
+ case app_const
192
+ when /^\d/
193
+ raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
194
+ end
195
+ end
196
+
197
+ def app_secret
198
+ ActiveSupport::SecureRandom.hex(64)
199
+ end
200
+
201
+ def dev_or_edge?
202
+ options.dev? || options.edge?
203
+ end
204
+
205
+ def self.banner
206
+ "#{$0} #{self.arguments.map(&:usage).join(' ')} [options]"
207
+ end
208
+
209
+ def empty_directory_with_gitkeep(destination, config = {})
210
+ empty_directory(destination, config)
211
+ create_file("#{destination}/.gitkeep") unless options[:skip_git]
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,28 @@
1
+ # Edit this Gemfile to bundle your application's dependencies.
2
+ <% if !dev_or_edge? %>
3
+ gem "rails", "<%= Rails::VERSION::STRING %>"
4
+ <% end -%>
5
+
6
+ ## Bundle edge rails:
7
+ <%- if options.dev? -%>
8
+ directory "<%= Rails::Generators::RAILS_DEV_PATH %>", :glob => "{*/,}*.gemspec"
9
+ gem "rails", "<%= Rails::VERSION::STRING %>"
10
+ <%- else -%>
11
+ <%= "# " unless options.edge? %>gem "rails", :git => "git://github.com/rails/rails.git"
12
+ <%- end -%>
13
+
14
+ ## Bundle the gems you use:
15
+ # gem "aws-s3", :require_as => "aws/s3"
16
+
17
+ # mongo db
18
+ gem "mongo", "~> 0.18.2"
19
+ gem "mongo_ext", "~> 0.18.2"
20
+ # gem "mongo_mapper", "~> 0.6.10 "
21
+ # gem "mongoid"
22
+
23
+ ## Bundle gems used only in certain environments:
24
+ only :test do
25
+ gem "rspec"
26
+ gem "webrat"
27
+ gem "cucumber"
28
+ end