aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-04-17 11:44:52 +0200
committerJosé Valim <jose.valim@gmail.com>2011-04-17 11:44:52 +0200
commit3a68aec1a1c6329bfcbf0f87bdc2fbd75cb98feb (patch)
treedb2df7eaca91860f9ea6e57c0ef3b13b682cfc82 /railties/lib
parent8f75c3abcde4f2ff64e855178027e1bd93976de9 (diff)
downloadrails-3a68aec1a1c6329bfcbf0f87bdc2fbd75cb98feb.tar.gz
rails-3a68aec1a1c6329bfcbf0f87bdc2fbd75cb98feb.tar.bz2
rails-3a68aec1a1c6329bfcbf0f87bdc2fbd75cb98feb.zip
Make generators more modular, add hooks and improve test suite.
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/generators.rb9
-rw-r--r--railties/lib/rails/generators/rails/assets/assets_generator.rb48
-rw-r--r--railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb21
-rw-r--r--railties/lib/rails/generators/rails/scaffold/templates/scaffold.css (renamed from railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css)0
-rw-r--r--railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss (renamed from railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css.scss)0
-rw-r--r--railties/lib/rails/generators/rails/stylesheets/USAGE5
-rw-r--r--railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb23
7 files changed, 52 insertions, 54 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index be61b087f9..82171d0832 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -24,9 +24,11 @@ module Rails
:rails => {
:actions => '-a',
:orm => '-o',
+ :javascript_engine => '-je',
:resource_controller => '-c',
:scaffold_controller => '-c',
:stylesheets => '-y',
+ :stylesheet_engine => '-se',
:template_engine => '-e',
:test_framework => '-t'
},
@@ -43,15 +45,18 @@ module Rails
DEFAULT_OPTIONS = {
:rails => {
+ :assets => true,
:force_plural => false,
:helper => true,
- :assets => true,
- :orm => nil,
:integration_tool => nil,
+ :javascripts => true,
+ :javascript_engine => nil,
+ :orm => nil,
:performance_tool => nil,
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
:stylesheets => true,
+ :stylesheet_engine => nil,
:test_framework => nil,
:template_engine => :erb
},
diff --git a/railties/lib/rails/generators/rails/assets/assets_generator.rb b/railties/lib/rails/generators/rails/assets/assets_generator.rb
index 59239d1a03..80beb7abfe 100644
--- a/railties/lib/rails/generators/rails/assets/assets_generator.rb
+++ b/railties/lib/rails/generators/rails/assets/assets_generator.rb
@@ -1,36 +1,38 @@
module Rails
module Generators
- # TODO: Add hooks for using other asset pipelines, like Less
class AssetsGenerator < NamedBase
- def create_asset_files
+ class_option :javascripts, :type => :boolean, :desc => "Generate javascripts"
+ class_option :stylesheets, :type => :boolean, :desc => "Generate stylesheets"
+
+ class_option :javascript_engine, :desc => "Engine for javascripts"
+ class_option :stylesheet_engine, :desc => "Engine for stylesheets"
+
+ def create_javascript_files
+ return unless options.javascripts?
copy_file "javascript.#{javascript_extension}",
- File.join('app/assets/javascripts', "#{file_name}.#{javascript_extension}")
+ File.join('app/assets/javascripts', class_path, "#{asset_name}.#{javascript_extension}")
+ end
+ def create_stylesheet_files
+ return unless options.stylesheets?
copy_file "stylesheet.#{stylesheet_extension}",
- File.join('app/assets/stylesheets', "#{file_name}.#{stylesheet_extension}")
+ File.join('app/assets/stylesheets', class_path, "#{asset_name}.#{stylesheet_extension}")
end
-
- private
- def javascript_extension
- using_coffee? ? "js.coffee" : "js"
+
+ protected
+
+ def asset_name
+ file_name
end
-
- def using_coffee?
- require 'coffee-script'
- defined?(CoffeeScript)
- rescue LoadError
- false
+
+ def javascript_extension
+ options.javascript_engine.present? ?
+ "js.#{options.javascript_engine}" : "js"
end
-
+
def stylesheet_extension
- using_sass? ? "css.scss" : "css"
- end
-
- def using_sass?
- require 'sass'
- defined?(Sass)
- rescue LoadError
- false
+ options.stylesheet_engine.present? ?
+ "css.#{options.stylesheet_engine}" : "css"
end
end
end
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index 779f933785..6eef0dbe5b 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -6,8 +6,27 @@ module Rails
remove_hook_for :resource_controller
remove_class_option :actions
+ class_option :stylesheets, :type => :boolean, :desc => "Generate stylesheets"
+ class_option :stylesheet_engine, :desc => "Engine for stylesheets"
+
hook_for :scaffold_controller, :required => true
- hook_for :stylesheets
+
+ def copy_stylesheets_file
+ if behavior == :invoke && options.stylesheets?
+ template "scaffold.#{stylesheet_extension}", "app/assets/stylesheets/scaffold.#{stylesheet_extension}"
+ end
+ end
+
+ hook_for :assets do |assets|
+ invoke assets, [controller_name]
+ end
+
+ private
+
+ def stylesheet_extension
+ options.stylesheet_engine.present? ?
+ "css.#{options.stylesheet_engine}" : "css"
+ end
end
end
end
diff --git a/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css b/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css
index 1ae7000299..1ae7000299 100644
--- a/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css
+++ b/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css
diff --git a/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css.scss b/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss
index 45116b53f6..45116b53f6 100644
--- a/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css.scss
+++ b/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss
diff --git a/railties/lib/rails/generators/rails/stylesheets/USAGE b/railties/lib/rails/generators/rails/stylesheets/USAGE
deleted file mode 100644
index 59e5495d0b..0000000000
--- a/railties/lib/rails/generators/rails/stylesheets/USAGE
+++ /dev/null
@@ -1,5 +0,0 @@
-Description:
- Copies scaffold stylesheets to public/stylesheets/.
-
-Examples:
- `rails generate stylesheets`
diff --git a/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb b/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb
deleted file mode 100644
index d06db25292..0000000000
--- a/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-module Rails
- module Generators
- class StylesheetsGenerator < Base
- def copy_stylesheets_file
- if behavior == :invoke
- template "scaffold.#{stylesheet_extension}", "app/assets/stylesheets/scaffold.#{stylesheet_extension}"
- end
- end
-
- private
- def stylesheet_extension
- using_sass? ? "css.scss" : "css"
- end
-
- def using_sass?
- require 'sass'
- defined?(Sass)
- rescue LoadError
- false
- end
- end
- end
-end