diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/css/assets/assets_generator.rb | 13 | ||||
-rw-r--r-- | railties/lib/rails/generators/css/assets/templates/stylesheet.css (renamed from railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss) | 3 | ||||
-rw-r--r-- | railties/lib/rails/generators/css/scaffold/scaffold_generator.rb | 16 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/assets/assets_generator.rb | 11 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb | 13 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss | 58 | ||||
-rw-r--r-- | railties/test/generators/assets_generator_test.rb | 6 | ||||
-rw-r--r-- | railties/test/generators/controller_generator_test.rb | 2 | ||||
-rw-r--r-- | railties/test/generators/namespaced_generators_test.rb | 8 | ||||
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 32 |
11 files changed, 59 insertions, 105 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 85c67af19a..2322e581bf 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -57,7 +57,7 @@ module Rails :resource_controller => :controller, :scaffold_controller => :scaffold_controller, :stylesheets => true, - :stylesheet_engine => nil, + :stylesheet_engine => :css, :test_framework => false, :template_engine => :erb }, diff --git a/railties/lib/rails/generators/css/assets/assets_generator.rb b/railties/lib/rails/generators/css/assets/assets_generator.rb new file mode 100644 index 0000000000..492177ca2e --- /dev/null +++ b/railties/lib/rails/generators/css/assets/assets_generator.rb @@ -0,0 +1,13 @@ +require "rails/generators/named_base" + +module Css + module Generators + class AssetsGenerator < Rails::Generators::NamedBase + source_root File.expand_path("../templates", __FILE__) + + def copy_stylesheet + copy_file "stylesheet.css", File.join('app/assets/stylesheets', class_path, "#{file_name}.css") + end + end + end +end diff --git a/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss b/railties/lib/rails/generators/css/assets/templates/stylesheet.css index ba95e217cc..afad32db02 100644 --- a/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +++ b/railties/lib/rails/generators/css/assets/templates/stylesheet.css @@ -1,5 +1,4 @@ -/* +/* 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/css/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb new file mode 100644 index 0000000000..1d7fe9fac0 --- /dev/null +++ b/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb @@ -0,0 +1,16 @@ +require "rails/generators/named_base" + +module Css + module Generators + class ScaffoldGenerator < Rails::Generators::NamedBase + # In order to allow the Sass generators to pick up the default Rails CSS and + # transform it, we leave it in a standard location for the CSS stylesheet + # generators to handle. For the simple, default case, just copy it over. + def copy_stylesheet + dir = Rails::Generators::ScaffoldGenerator.source_root + file = File.join(dir, "scaffold.css") + create_file "app/assets/stylesheets/scaffold.css", File.read(file) + end + end + end +end diff --git a/railties/lib/rails/generators/rails/assets/assets_generator.rb b/railties/lib/rails/generators/rails/assets/assets_generator.rb index 2d52da77eb..db3422fe83 100644 --- a/railties/lib/rails/generators/rails/assets/assets_generator.rb +++ b/railties/lib/rails/generators/rails/assets/assets_generator.rb @@ -13,12 +13,6 @@ module Rails 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', class_path, "#{asset_name}.#{stylesheet_extension}") - end - protected def asset_name @@ -30,9 +24,8 @@ module Rails "js.#{options.javascript_engine}" : "js" end - def stylesheet_extension - options.stylesheet_engine.present? ? - "css.#{options.stylesheet_engine}" : "css" + hook_for :stylesheet_engine do |stylesheet_engine| + invoke stylesheet_engine, [name] if options[:stylesheets] 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 aa9b45c5a5..03a61a035e 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -11,21 +11,12 @@ module Rails hook_for :scaffold_controller, :required => true - 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" + hook_for :stylesheet_engine do |stylesheet_engine| + invoke stylesheet_engine, [controller_name] if options[:stylesheets] && behavior == :invoke end end end diff --git a/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss b/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss deleted file mode 100644 index 45116b53f6..0000000000 --- a/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +++ /dev/null @@ -1,58 +0,0 @@ -body { background-color: #fff; color: #333; } - -body, p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; -} - -a { - color: #000; - &:visited { color: #666; } - &:hover { color: #fff; background-color:#000; } -} - -div.field, div.actions { - margin-bottom: 10px; -} - -#notice { - color: green; -} - -.field_with_errors { - padding: 2px; - background-color: red; - display: table; -} - -#error_explanation { - width: 450px; - border: 2px solid red; - padding: 7px; - padding-bottom: 0; - margin-bottom: 20px; - background-color: #f0f0f0; - - h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px; - margin-bottom: 0px; - background-color: #c00; - color: #fff; - } - - ul li { - font-size: 12px; - list-style: square; - } -}
\ No newline at end of file diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb index 375632e5bc..2d20982d04 100644 --- a/railties/test/generators/assets_generator_test.rb +++ b/railties/test/generators/assets_generator_test.rb @@ -9,17 +9,17 @@ class AssetsGeneratorTest < Rails::Generators::TestCase def test_assets run_generator assert_file "app/assets/javascripts/posts.js.coffee" - assert_file "app/assets/stylesheets/posts.css.scss" + assert_file "app/assets/stylesheets/posts.css" end def test_skipping_assets content = run_generator ["posts", "--no-stylesheets", "--no-javascripts"] assert_no_file "app/assets/javascripts/posts.js.coffee" - assert_no_file "app/assets/stylesheets/posts.css.scss" + assert_no_file "app/assets/stylesheets/posts.css" end def test_vanilla_assets - run_generator ["posts", "--no-javascript-engine", "--no-stylesheet-engine"] + run_generator ["posts", "--no-javascript-engine"] assert_file "app/assets/javascripts/posts.js" assert_file "app/assets/stylesheets/posts.css" end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 46533b70be..3adf7be118 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -40,7 +40,7 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_invokes_assets run_generator assert_file "app/assets/javascripts/account.js.coffee" - assert_file "app/assets/stylesheets/account.css.scss" + assert_file "app/assets/stylesheets/account.css" end def test_invokes_default_test_framework diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index 6f8a9b4280..17cbac0912 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -252,7 +252,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_file "test/unit/helpers/test_app/product_lines_helper_test.rb" # Stylesheets - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" end def test_scaffold_on_revoke @@ -283,7 +283,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_no_file "test/unit/helpers/test_app/product_lines_helper_test.rb" # Stylesheets (should not be removed) - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" end def test_scaffold_with_namespace_on_invoke @@ -324,7 +324,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_file "test/unit/helpers/test_app/admin/roles_helper_test.rb" # Stylesheets - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" end def test_scaffold_with_namespace_on_revoke @@ -356,6 +356,6 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_no_file "test/unit/helpers/test_app/admin/roles_helper_test.rb" # Stylesheets (should not be removed) - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 4b07f8bcbe..2135ffac81 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -80,9 +80,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "test/unit/helpers/product_lines_helper_test.rb" # Assets - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" assert_file "app/assets/javascripts/product_lines.js.coffee" - assert_file "app/assets/stylesheets/product_lines.css.scss" + assert_file "app/assets/stylesheets/product_lines.css" end def test_scaffold_on_revoke @@ -113,9 +113,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "test/unit/helpers/product_lines_helper_test.rb" # Assets - assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/ + assert_file "app/assets/stylesheets/scaffold.css", /:visited/ assert_no_file "app/assets/javascripts/product_lines.js.coffee" - assert_no_file "app/assets/stylesheets/product_lines.css.scss" + assert_no_file "app/assets/stylesheets/product_lines.css" end def test_scaffold_with_namespace_on_invoke @@ -189,9 +189,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "test/unit/helpers/admin/roles_helper_test.rb" # Assets - assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/ + assert_file "app/assets/stylesheets/scaffold.css", /:visited/ assert_file "app/assets/javascripts/admin/roles.js.coffee" - assert_file "app/assets/stylesheets/admin/roles.css.scss" + assert_file "app/assets/stylesheets/admin/roles.css" end def test_scaffold_with_namespace_on_revoke @@ -223,9 +223,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "test/unit/helpers/admin/roles_helper_test.rb" # Assets - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" assert_no_file "app/assets/javascripts/admin/roles.js.coffee" - assert_no_file "app/assets/stylesheets/admin/roles.css.scss" + assert_no_file "app/assets/stylesheets/admin/roles.css" end def test_scaffold_generator_on_revoke_does_not_mutilate_legacy_map_parameter @@ -245,27 +245,27 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase def test_scaffold_generator_no_assets run_generator [ "posts", "--no-assets" ] - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" assert_no_file "app/assets/javascripts/posts.js.coffee" - assert_no_file "app/assets/stylesheets/posts.css.scss" + assert_no_file "app/assets/stylesheets/posts.css" end def test_scaffold_generator_no_stylesheets run_generator [ "posts", "--no-stylesheets" ] - assert_no_file "app/assets/stylesheets/scaffold.css.scss" + assert_no_file "app/assets/stylesheets/scaffold.css" assert_file "app/assets/javascripts/posts.js.coffee" - assert_no_file "app/assets/stylesheets/posts.css.scss" + assert_no_file "app/assets/stylesheets/posts.css" end def test_scaffold_generator_no_javascripts run_generator [ "posts", "--no-javascripts" ] - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" assert_no_file "app/assets/javascripts/posts.js.coffee" - assert_file "app/assets/stylesheets/posts.css.scss" + assert_file "app/assets/stylesheets/posts.css" end - def test_scaffold_generator_no_negines - run_generator [ "posts", "--no-javascript-engine", "--no-stylesheet-engine" ] + def test_scaffold_generator_no_engines + run_generator [ "posts", "--no-javascript-engine" ] assert_file "app/assets/stylesheets/scaffold.css" assert_file "app/assets/javascripts/posts.js" assert_file "app/assets/stylesheets/posts.css" |