diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2011-04-14 12:23:21 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2011-04-14 12:23:21 +0200 |
commit | 6c91b699bf4c5b9288f8ac0136672d30e4989d7b (patch) | |
tree | 7c6fd7b871f85a525503231d3270909ff3c67f32 /railties/lib/rails/generators/rails | |
parent | bd032fe97eabed62130bb745b0955090099fe525 (diff) | |
download | rails-6c91b699bf4c5b9288f8ac0136672d30e4989d7b.tar.gz rails-6c91b699bf4c5b9288f8ac0136672d30e4989d7b.tar.bz2 rails-6c91b699bf4c5b9288f8ac0136672d30e4989d7b.zip |
The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use Coffee and Sass, if those libraries are available. [DHH]
Diffstat (limited to 'railties/lib/rails/generators/rails')
7 files changed, 72 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/rails/assets/USAGE b/railties/lib/rails/generators/rails/assets/USAGE new file mode 100644 index 0000000000..6667323dbc --- /dev/null +++ b/railties/lib/rails/generators/rails/assets/USAGE @@ -0,0 +1,20 @@ +Description: + Stubs out a new asset placeholders. Pass the asset name, either CamelCased + or under_scored. + + To create assets within a folder, specify the assets name as a + path like 'parent/name'. + + This generates a JavaScript stub in app/assets/javascripts and a stylesheet + stub in app/assets/stylesheets. + + If CoffeeScript is available, JavaScripts will be generated with the .coffee extension. + If Sass 3 is available, stylesheets will be generated with the .css extension. + +Example: + `rails generate assets posts` + + Posts assets. + Javascript: app/assets/javascripts/posts.js + Stylesheet: app/assets/stylesheets/posts.css + diff --git a/railties/lib/rails/generators/rails/assets/assets_generator.rb b/railties/lib/rails/generators/rails/assets/assets_generator.rb new file mode 100644 index 0000000000..59239d1a03 --- /dev/null +++ b/railties/lib/rails/generators/rails/assets/assets_generator.rb @@ -0,0 +1,37 @@ +module Rails + module Generators + # TODO: Add hooks for using other asset pipelines, like Less + class AssetsGenerator < NamedBase + def create_asset_files + copy_file "javascript.#{javascript_extension}", + File.join('app/assets/javascripts', "#{file_name}.#{javascript_extension}") + + copy_file "stylesheet.#{stylesheet_extension}", + File.join('app/assets/stylesheets', "#{file_name}.#{stylesheet_extension}") + end + + private + def javascript_extension + using_coffee? ? "js.coffee" : "js" + end + + def using_coffee? + require 'coffee-script' + defined?(CoffeeScript) + rescue LoadError + false + end + + def stylesheet_extension + using_sass? ? "css.scss" : "css" + end + + def using_sass? + require 'sass' + defined?(Sass) + rescue LoadError + false + end + end + end +end diff --git a/railties/lib/rails/generators/rails/assets/templates/javascript.js b/railties/lib/rails/generators/rails/assets/templates/javascript.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/railties/lib/rails/generators/rails/assets/templates/javascript.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/railties/lib/rails/generators/rails/assets/templates/javascript.js.coffee b/railties/lib/rails/generators/rails/assets/templates/javascript.js.coffee new file mode 100644 index 0000000000..09b2da094a --- /dev/null +++ b/railties/lib/rails/generators/rails/assets/templates/javascript.js.coffee @@ -0,0 +1,3 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. +// You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/railties/lib/rails/generators/rails/assets/templates/stylesheet.css b/railties/lib/rails/generators/rails/assets/templates/stylesheet.css new file mode 100644 index 0000000000..7594abf268 --- /dev/null +++ b/railties/lib/rails/generators/rails/assets/templates/stylesheet.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss b/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss new file mode 100644 index 0000000000..ba95e217cc --- /dev/null +++ b/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss @@ -0,0 +1,5 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. + You can use Sass (SCSS) here: http://sass-lang.com/ +*/ diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index 9788c0d0bc..74aa0432a8 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -14,7 +14,7 @@ module Rails end end - hook_for :template_engine, :test_framework, :helper + hook_for :template_engine, :test_framework, :helper, :assets end end end |