railties 3.0.20 → 3.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/CHANGELOG +36 -49
  2. data/README.rdoc +2 -1
  3. data/guides/assets/stylesheets/fixes.css +16 -0
  4. data/guides/rails_guides.rb +2 -2
  5. data/guides/rails_guides/generator.rb +8 -3
  6. data/guides/rails_guides/textile_extensions.rb +4 -2
  7. data/guides/source/2_2_release_notes.textile +3 -3
  8. data/guides/source/2_3_release_notes.textile +2 -2
  9. data/guides/source/3_0_release_notes.textile +14 -14
  10. data/guides/source/action_controller_overview.textile +54 -79
  11. data/guides/source/action_mailer_basics.textile +39 -9
  12. data/guides/source/action_view_overview.textile +257 -211
  13. data/guides/source/active_record_basics.textile +1 -1
  14. data/guides/source/active_record_querying.textile +217 -27
  15. data/guides/source/active_record_validations_callbacks.textile +94 -25
  16. data/guides/source/active_support_core_extensions.textile +109 -77
  17. data/guides/source/ajax_on_rails.textile +15 -150
  18. data/guides/source/api_documentation_guidelines.textile +12 -12
  19. data/guides/source/association_basics.textile +74 -60
  20. data/guides/source/caching_with_rails.textile +59 -60
  21. data/guides/source/command_line.textile +46 -47
  22. data/guides/source/configuring.textile +55 -37
  23. data/guides/source/contribute.textile +7 -7
  24. data/guides/source/contributing_to_ruby_on_rails.textile +14 -23
  25. data/guides/source/credits.html.erb +3 -3
  26. data/guides/source/debugging_rails_applications.textile +59 -46
  27. data/guides/source/form_helpers.textile +76 -31
  28. data/guides/source/generators.textile +39 -40
  29. data/guides/source/getting_started.textile +73 -94
  30. data/guides/source/i18n.textile +64 -58
  31. data/guides/source/index.html.erb +3 -3
  32. data/guides/source/initialization.textile +634 -3284
  33. data/guides/source/layout.html.erb +6 -7
  34. data/guides/source/layouts_and_rendering.textile +59 -60
  35. data/guides/source/migrations.textile +63 -59
  36. data/guides/source/nested_model_forms.textile +2 -2
  37. data/guides/source/performance_testing.textile +16 -16
  38. data/guides/source/plugins.textile +236 -1280
  39. data/guides/source/rails_application_templates.textile +37 -29
  40. data/guides/source/rails_on_rack.textile +4 -9
  41. data/guides/source/routing.textile +96 -75
  42. data/guides/source/ruby_on_rails_guides_guidelines.textile +19 -12
  43. data/guides/source/security.textile +57 -30
  44. data/guides/source/testing.textile +26 -24
  45. data/guides/w3c_validator.rb +2 -2
  46. data/lib/rails.rb +1 -7
  47. data/lib/rails/application.rb +46 -76
  48. data/lib/rails/application/bootstrap.rb +6 -11
  49. data/lib/rails/application/configuration.rb +43 -40
  50. data/lib/rails/application/finisher.rb +16 -4
  51. data/lib/rails/application/railties.rb +6 -24
  52. data/lib/rails/application/routes_reloader.rb +45 -0
  53. data/lib/rails/backtrace_cleaner.rb +1 -1
  54. data/lib/rails/cli.rb +7 -5
  55. data/lib/rails/commands.rb +27 -2
  56. data/lib/rails/commands/application.rb +14 -1
  57. data/lib/rails/commands/benchmarker.rb +3 -1
  58. data/lib/rails/commands/dbconsole.rb +2 -2
  59. data/lib/rails/commands/destroy.rb +3 -1
  60. data/lib/rails/commands/generate.rb +3 -1
  61. data/lib/rails/commands/plugin.rb +2 -7
  62. data/lib/rails/commands/plugin_new.rb +10 -0
  63. data/lib/rails/commands/profiler.rb +3 -1
  64. data/lib/rails/commands/server.rb +4 -0
  65. data/lib/rails/configuration.rb +8 -81
  66. data/lib/rails/console/app.rb +2 -2
  67. data/lib/rails/engine.rb +460 -78
  68. data/lib/rails/engine/configuration.rb +46 -49
  69. data/lib/rails/engine/railties.rb +33 -0
  70. data/lib/rails/generators.rb +11 -5
  71. data/lib/rails/generators/actions.rb +2 -27
  72. data/lib/rails/generators/app_base.rb +216 -0
  73. data/lib/rails/generators/base.rb +3 -2
  74. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -1
  75. data/lib/rails/generators/generated_attribute.rb +2 -1
  76. data/lib/rails/generators/migration.rb +6 -2
  77. data/lib/rails/generators/named_base.rb +79 -3
  78. data/lib/rails/generators/rails/app/app_generator.rb +44 -209
  79. data/lib/rails/generators/rails/app/templates/Gemfile +15 -31
  80. data/lib/rails/generators/rails/app/templates/README +2 -2
  81. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  82. data/lib/rails/generators/rails/app/templates/{public → app/assets}/images/rails.png +0 -0
  83. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +8 -0
  84. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -0
  85. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  86. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  87. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  88. data/lib/rails/generators/rails/app/templates/config/application.rb +19 -3
  89. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +4 -4
  90. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +11 -6
  91. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -3
  92. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -2
  94. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -11
  95. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -1
  96. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
  97. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +12 -0
  98. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  99. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  100. data/lib/rails/generators/rails/app/templates/db/{seeds.rb → seeds.rb.tt} +2 -2
  101. data/lib/rails/generators/rails/app/templates/public/index.html +10 -8
  102. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  103. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  104. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  105. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  106. data/lib/rails/generators/rails/app/templates/test/{test_helper.rb.tt → test_helper.rb} +0 -0
  107. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  108. data/lib/rails/generators/rails/assets/USAGE +20 -0
  109. data/lib/rails/generators/rails/assets/assets_generator.rb +39 -0
  110. data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
  111. data/lib/rails/generators/rails/assets/templates/javascript.js.coffee +3 -0
  112. data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
  113. data/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +5 -0
  114. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
  115. data/lib/rails/generators/rails/controller/templates/controller.rb +2 -0
  116. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -2
  117. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  118. data/lib/rails/generators/rails/helper/templates/helper.rb +2 -0
  119. data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -0
  120. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -4
  121. data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
  122. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +303 -0
  123. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +9 -0
  124. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +11 -0
  125. data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
  126. data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
  127. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +21 -0
  128. data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
  129. data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
  130. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  131. data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
  132. data/lib/rails/generators/rails/plugin_new/templates/gitignore +6 -0
  133. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
  134. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
  135. data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
  136. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +16 -0
  137. data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
  138. data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
  139. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -0
  140. data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
  141. data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
  142. data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +10 -0
  143. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  144. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +20 -1
  145. data/lib/rails/generators/rails/{stylesheets → scaffold}/templates/scaffold.css +0 -0
  146. data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +58 -0
  147. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +21 -19
  148. data/lib/rails/generators/resource_helpers.rb +3 -3
  149. data/lib/rails/generators/test_case.rb +2 -20
  150. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +5 -4
  151. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +2 -0
  152. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +3 -4
  153. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +5 -4
  154. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +1 -1
  155. data/lib/rails/generators/test_unit/model/templates/unit_test.rb +5 -4
  156. data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +5 -4
  157. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +3 -4
  158. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +7 -5
  159. data/lib/rails/info.rb +0 -1
  160. data/lib/rails/paths.rb +119 -65
  161. data/lib/rails/plugin.rb +18 -19
  162. data/lib/rails/rack/log_tailer.rb +1 -1
  163. data/lib/rails/railtie.rb +50 -47
  164. data/lib/rails/railtie/configurable.rb +20 -10
  165. data/lib/rails/railtie/configuration.rb +20 -19
  166. data/lib/rails/source_annotation_extractor.rb +5 -5
  167. data/lib/rails/tasks.rb +1 -0
  168. data/lib/rails/tasks/assets.rake +10 -0
  169. data/lib/rails/tasks/documentation.rake +2 -8
  170. data/lib/rails/tasks/engine.rake +69 -0
  171. data/lib/rails/tasks/framework.rake +4 -21
  172. data/lib/rails/tasks/misc.rake +1 -1
  173. data/lib/rails/tasks/routes.rake +2 -1
  174. data/lib/rails/test_help.rb +17 -1
  175. data/lib/rails/test_unit/railtie.rb +1 -1
  176. data/lib/rails/test_unit/testing.rake +8 -3
  177. data/lib/rails/version.rb +3 -3
  178. metadata +128 -100
  179. checksums.yaml +0 -7
  180. data/lib/rails/application/configurable.rb +0 -19
  181. data/lib/rails/console/sandbox.rb +0 -6
  182. data/lib/rails/deprecation.rb +0 -41
  183. data/lib/rails/engine/configurable.rb +0 -25
  184. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +0 -62
  185. data/lib/rails/generators/rails/app/templates/public/javascripts/application.js +0 -2
  186. data/lib/rails/generators/rails/app/templates/public/javascripts/controls.js +0 -965
  187. data/lib/rails/generators/rails/app/templates/public/javascripts/dragdrop.js +0 -974
  188. data/lib/rails/generators/rails/app/templates/public/javascripts/effects.js +0 -1123
  189. data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +0 -6001
  190. data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +0 -202
  191. data/lib/rails/generators/rails/stylesheets/USAGE +0 -5
  192. data/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb +0 -9
  193. data/lib/rails/info_routes.rb +0 -3
@@ -0,0 +1,20 @@
1
+ Description:
2
+ Stubs out a new asset placeholders. Pass the asset name, either CamelCased
3
+ or under_scored.
4
+
5
+ To create assets within a folder, specify the assets name as a
6
+ path like 'parent/name'.
7
+
8
+ This generates a JavaScript stub in app/assets/javascripts and a stylesheet
9
+ stub in app/assets/stylesheets.
10
+
11
+ If CoffeeScript is available, JavaScripts will be generated with the .coffee extension.
12
+ If Sass 3 is available, stylesheets will be generated with the .scss extension.
13
+
14
+ Example:
15
+ `rails generate assets posts`
16
+
17
+ Posts assets.
18
+ Javascript: app/assets/javascripts/posts.js
19
+ Stylesheet: app/assets/stylesheets/posts.css
20
+
@@ -0,0 +1,39 @@
1
+ module Rails
2
+ module Generators
3
+ class AssetsGenerator < NamedBase
4
+ class_option :javascripts, :type => :boolean, :desc => "Generate javascripts"
5
+ class_option :stylesheets, :type => :boolean, :desc => "Generate stylesheets"
6
+
7
+ class_option :javascript_engine, :desc => "Engine for javascripts"
8
+ class_option :stylesheet_engine, :desc => "Engine for stylesheets"
9
+
10
+ def create_javascript_files
11
+ return unless options.javascripts?
12
+ copy_file "javascript.#{javascript_extension}",
13
+ File.join('app/assets/javascripts', class_path, "#{asset_name}.#{javascript_extension}")
14
+ end
15
+
16
+ def create_stylesheet_files
17
+ return unless options.stylesheets?
18
+ copy_file "stylesheet.#{stylesheet_extension}",
19
+ File.join('app/assets/stylesheets', class_path, "#{asset_name}.#{stylesheet_extension}")
20
+ end
21
+
22
+ protected
23
+
24
+ def asset_name
25
+ file_name
26
+ end
27
+
28
+ def javascript_extension
29
+ options.javascript_engine.present? ?
30
+ "js.#{options.javascript_engine}" : "js"
31
+ end
32
+
33
+ def stylesheet_extension
34
+ options.stylesheet_engine.present? ?
35
+ "css.#{options.stylesheet_engine}" : "css"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ You can use Sass (SCSS) here: http://sass-lang.com/
5
+ */
@@ -14,7 +14,7 @@ module Rails
14
14
  end
15
15
  end
16
16
 
17
- hook_for :template_engine, :test_framework, :helper
17
+ hook_for :template_engine, :test_framework, :helper, :assets
18
18
  end
19
19
  end
20
20
  end
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  class <%= class_name %>Controller < ApplicationController
2
3
  <% for action in actions -%>
3
4
  def <%= action %>
@@ -5,3 +6,4 @@ class <%= class_name %>Controller < ApplicationController
5
6
 
6
7
  <% end -%>
7
8
  end
9
+ <% end -%>
@@ -14,9 +14,9 @@ module Rails
14
14
 
15
15
  def generator_dir
16
16
  if options[:namespace]
17
- File.join("lib", "generators", file_name)
17
+ File.join("lib", "generators", regular_class_path, file_name)
18
18
  else
19
- File.join("lib", "generators")
19
+ File.join("lib", "generators", regular_class_path)
20
20
  end
21
21
  end
22
22
 
@@ -1,2 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module <%= class_name %>Helper
2
3
  end
4
+ <% end -%>
@@ -1,3 +1,4 @@
1
+
1
2
  require 'rails/generators/rails/generator/generator_generator'
2
3
 
3
4
  module Rails
@@ -5,6 +6,12 @@ module Rails
5
6
  class PluginGenerator < NamedBase
6
7
  class_option :tasks, :desc => "When supplied creates tasks base files."
7
8
 
9
+ def show_deprecation
10
+ return unless behavior == :invoke
11
+ message = "Plugin generator is deprecated, please use 'rails plugin new' command to generate plugin structure."
12
+ ActiveSupport::Deprecation.warn message
13
+ end
14
+
8
15
  check_class_collision
9
16
 
10
17
  def create_root_files
@@ -1,6 +1,6 @@
1
- require 'rake'
1
+ #!/usr/bin/env rake
2
2
  require 'rake/testtask'
3
- require 'rdoc/task'
3
+ require 'rake/rdoctask'
4
4
 
5
5
  desc 'Default: run unit tests.'
6
6
  task :default => :test
@@ -14,10 +14,10 @@ Rake::TestTask.new(:test) do |t|
14
14
  end
15
15
 
16
16
  desc 'Generate documentation for the <%= file_name %> plugin.'
17
- RDoc::Task.new(:rdoc) do |rdoc|
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
18
  rdoc.rdoc_dir = 'rdoc'
19
19
  rdoc.title = '<%= class_name %>'
20
20
  rdoc.options << '--line-numbers' << '--inline-source'
21
21
  rdoc.rdoc_files.include('README')
22
22
  rdoc.rdoc_files.include('lib/**/*.rb')
23
- end
23
+ end
@@ -0,0 +1,10 @@
1
+ Description:
2
+ The 'rails plugin new' command creates a skeleton for developing any
3
+ kind of Rails extension with ability to run tests using dummy Rails
4
+ application.
5
+
6
+ Example:
7
+ rails plugin new ~/Code/Ruby/blog
8
+
9
+ This generates a skeletal Rails plugin in ~/Code/Ruby/blog.
10
+ See the README in the newly created plugin to get going.
@@ -0,0 +1,303 @@
1
+ require 'active_support/core_ext/hash/slice'
2
+ require "rails/generators/rails/app/app_generator"
3
+ require 'date'
4
+
5
+ module Rails
6
+ class PluginBuilder
7
+ def rakefile
8
+ template "Rakefile"
9
+ end
10
+
11
+ def app
12
+ if mountable?
13
+ directory "app"
14
+ template "#{app_templates_dir}/app/views/layouts/application.html.erb.tt",
15
+ "app/views/layouts/#{name}/application.html.erb"
16
+ empty_directory_with_gitkeep "app/assets/images"
17
+ elsif full?
18
+ empty_directory_with_gitkeep "app/models"
19
+ empty_directory_with_gitkeep "app/controllers"
20
+ empty_directory_with_gitkeep "app/views"
21
+ empty_directory_with_gitkeep "app/helpers"
22
+ empty_directory_with_gitkeep "app/assets/images"
23
+ end
24
+ end
25
+
26
+ def readme
27
+ template "README.rdoc"
28
+ end
29
+
30
+ def gemfile
31
+ template "Gemfile"
32
+ end
33
+
34
+ def license
35
+ template "MIT-LICENSE"
36
+ end
37
+
38
+ def gemspec
39
+ template "%name%.gemspec"
40
+ end
41
+
42
+ def gitignore
43
+ copy_file "gitignore", ".gitignore"
44
+ end
45
+
46
+ def lib
47
+ template "lib/%name%.rb"
48
+ template "lib/tasks/%name%_tasks.rake"
49
+ if full?
50
+ template "lib/%name%/engine.rb"
51
+ end
52
+ end
53
+
54
+ def config
55
+ template "config/routes.rb" if full?
56
+ end
57
+
58
+ def test
59
+ template "test/test_helper.rb"
60
+ template "test/%name%_test.rb"
61
+ append_file "Rakefile", <<-EOF
62
+ #{rakefile_test_tasks}
63
+
64
+ task :default => :test
65
+ EOF
66
+ if full?
67
+ template "test/integration/navigation_test.rb"
68
+ end
69
+ end
70
+
71
+ PASSTHROUGH_OPTIONS = [
72
+ :skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
73
+ ]
74
+
75
+ def generate_test_dummy(force = false)
76
+ opts = (options || {}).slice(*PASSTHROUGH_OPTIONS)
77
+ opts[:force] = force
78
+
79
+ invoke Rails::Generators::AppGenerator,
80
+ [ File.expand_path(dummy_path, destination_root) ], opts
81
+ end
82
+
83
+ def test_dummy_config
84
+ template "rails/boot.rb", "#{dummy_path}/config/boot.rb", :force => true
85
+ template "rails/application.rb", "#{dummy_path}/config/application.rb", :force => true
86
+ if mountable?
87
+ template "rails/routes.rb", "#{dummy_path}/config/routes.rb", :force => true
88
+ end
89
+ end
90
+
91
+ def test_dummy_clean
92
+ inside dummy_path do
93
+ remove_file ".gitignore"
94
+ remove_file "db/seeds.rb"
95
+ remove_file "doc"
96
+ remove_file "Gemfile"
97
+ remove_file "lib/tasks"
98
+ remove_file "app/assets/images/rails.png"
99
+ remove_file "public/index.html"
100
+ remove_file "public/robots.txt"
101
+ remove_file "README"
102
+ remove_file "test"
103
+ remove_file "vendor"
104
+ end
105
+ end
106
+
107
+ def stylesheets
108
+ if mountable?
109
+ copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
110
+ "app/assets/stylesheets/application.css"
111
+ elsif full?
112
+ empty_directory_with_gitkeep "app/assets/stylesheets"
113
+ end
114
+ end
115
+
116
+ def javascripts
117
+ return if options.skip_javascript?
118
+
119
+ if mountable?
120
+ copy_file "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
121
+ "app/assets/javascripts/application.js"
122
+ elsif full?
123
+ empty_directory_with_gitkeep "app/assets/javascripts"
124
+ end
125
+ end
126
+
127
+ def script(force = false)
128
+ directory "script", :force => force do |content|
129
+ "#{shebang}\n" + content
130
+ end
131
+ chmod "script", 0755, :verbose => false
132
+ end
133
+ end
134
+
135
+ module Generators
136
+ class PluginNewGenerator < AppBase
137
+ add_shared_options_for "plugin"
138
+
139
+ alias_method :plugin_path, :app_path
140
+
141
+ class_option :dummy_path, :type => :string, :default => "test/dummy",
142
+ :desc => "Create dummy application at given path"
143
+
144
+ class_option :full, :type => :boolean, :default => false,
145
+ :desc => "Generate rails engine with integration tests"
146
+
147
+ class_option :mountable, :type => :boolean, :default => false,
148
+ :desc => "Generate mountable isolated application"
149
+
150
+ class_option :skip_gemspec, :type => :boolean, :default => false,
151
+ :desc => "Skip gemspec file"
152
+
153
+ def initialize(*args)
154
+ raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank?
155
+
156
+ @dummy_path = nil
157
+ super
158
+ end
159
+
160
+ public_task :create_root
161
+
162
+ def create_root_files
163
+ build(:readme)
164
+ build(:rakefile)
165
+ build(:gemspec) unless options[:skip_gemspec]
166
+ build(:license)
167
+ build(:gitignore) unless options[:skip_git]
168
+ build(:gemfile) unless options[:skip_gemfile]
169
+ end
170
+
171
+ def create_app_files
172
+ build(:app)
173
+ end
174
+
175
+ def create_config_files
176
+ build(:config)
177
+ end
178
+
179
+ def create_lib_files
180
+ build(:lib)
181
+ end
182
+
183
+ def create_public_stylesheets_files
184
+ build(:stylesheets)
185
+ end
186
+
187
+ def create_javascript_files
188
+ build(:javascripts)
189
+ end
190
+
191
+ def create_images_directory
192
+ build(:images)
193
+ end
194
+
195
+ def create_script_files
196
+ build(:script)
197
+ end
198
+
199
+ def create_test_files
200
+ build(:test) unless options[:skip_test_unit]
201
+ end
202
+
203
+ def create_test_dummy_files
204
+ return if options[:skip_test_unit]
205
+ create_dummy_app
206
+ end
207
+
208
+ def finish_template
209
+ build(:leftovers)
210
+ end
211
+
212
+ public_task :apply_rails_template, :bundle_if_dev_or_edge
213
+
214
+ protected
215
+
216
+ def app_templates_dir
217
+ "../../app/templates"
218
+ end
219
+
220
+ def create_dummy_app(path = nil)
221
+ dummy_path(path) if path
222
+
223
+ say_status :vendor_app, dummy_path
224
+ mute do
225
+ build(:generate_test_dummy)
226
+ store_application_definition!
227
+ build(:test_dummy_config)
228
+ build(:test_dummy_clean)
229
+ # ensure that script/rails has proper dummy_path
230
+ build(:script, true)
231
+ end
232
+ end
233
+
234
+ def full?
235
+ options[:full] || options[:mountable]
236
+ end
237
+
238
+ def mountable?
239
+ options[:mountable]
240
+ end
241
+
242
+ def self.banner
243
+ "rails plugin new #{self.arguments.map(&:usage).join(' ')} [options]"
244
+ end
245
+
246
+ def name
247
+ @name ||= File.basename(destination_root)
248
+ end
249
+
250
+ def camelized
251
+ @camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
252
+ end
253
+
254
+ def valid_const?
255
+ if camelized =~ /^\d/
256
+ raise Error, "Invalid plugin name #{name}. Please give a name which does not start with numbers."
257
+ elsif RESERVED_NAMES.include?(name)
258
+ raise Error, "Invalid plugin name #{name}. Please give a name which does not match one of the reserved rails words."
259
+ elsif Object.const_defined?(camelized)
260
+ raise Error, "Invalid plugin name #{name}, constant #{camelized} is already in use. Please choose another application name."
261
+ end
262
+ end
263
+
264
+ def application_definition
265
+ @application_definition ||= begin
266
+
267
+ dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
268
+ unless options[:pretend] || !File.exists?(dummy_application_path)
269
+ contents = File.read(dummy_application_path)
270
+ contents[(contents.index("module Dummy"))..-1]
271
+ end
272
+ end
273
+ end
274
+ alias :store_application_definition! :application_definition
275
+
276
+ def get_builder_class
277
+ defined?(::PluginBuilder) ? ::PluginBuilder : Rails::PluginBuilder
278
+ end
279
+
280
+ def rakefile_test_tasks
281
+ <<-RUBY
282
+ require 'rake/testtask'
283
+
284
+ Rake::TestTask.new(:test) do |t|
285
+ t.libs << 'lib'
286
+ t.libs << 'test'
287
+ t.pattern = 'test/**/*_test.rb'
288
+ t.verbose = false
289
+ end
290
+ RUBY
291
+ end
292
+
293
+ def dummy_path(path = nil)
294
+ @dummy_path = path if path
295
+ @dummy_path || options[:dummy_path]
296
+ end
297
+
298
+ def mute(&block)
299
+ shell.mute(&block)
300
+ end
301
+ end
302
+ end
303
+ end