aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/guides/source/active_record_validations_callbacks.textile2
-rw-r--r--railties/guides/source/command_line.textile4
-rw-r--r--railties/guides/source/generators.textile2
-rw-r--r--railties/guides/source/getting_started.textile2
-rw-r--r--railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb16
-rw-r--r--railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css.scss58
-rw-r--r--railties/test/generators/stylesheets_generator_test.rb12
8 files changed, 89 insertions, 9 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index b4c774d508..a4f0d31971 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.1.0 (unreleased)*
+* The scaffold controller will now produce SCSS file if Sass is available [Prem Sichanugrist]
+
* 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]
* jQuery is the new default JavaScript library. [fxn]
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 514d0322b9..c65dd52e48 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -822,7 +822,7 @@ The selectors to customize the style of error messages are:
* +#errorExplanation p+ - Style for the paragraph that holds the message that appears right below the header of the +div+ element.
* +#errorExplanation ul li+ - Style for the list items with individual error messages.
-Scaffolding for example generates +public/stylesheets/scaffold.css+, which defines the red-based style you saw above.
+Scaffolding for example generates +app/assets/stylesheets/scaffold.css.scss+, which later compiles to +app/assets/stylesheets/scaffold.css+ and defines the red-based style you saw above.
The name of the class and the id can be changed with the +:class+ and +:id+ options, accepted by both helpers.
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index f3e8d880df..9d8a9caf08 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -215,13 +215,13 @@ $ rails generate scaffold HighScore game:string score:integer
create app/views/layouts/
exists test/functional/
create test/unit/
- create public/stylesheets/
+ create app/assets/stylesheets/
create app/views/high_scores/index.html.erb
create app/views/high_scores/show.html.erb
create app/views/high_scores/new.html.erb
create app/views/high_scores/edit.html.erb
create app/views/layouts/high_scores.html.erb
- create public/stylesheets/scaffold.css
+ create app/assets/stylesheets/scaffold.css.scss
create app/controllers/high_scores_controller.rb
create test/functional/high_scores_controller_test.rb
create app/helpers/high_scores_helper.rb
diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile
index d32ba48003..cd8ac3d6fd 100644
--- a/railties/guides/source/generators.textile
+++ b/railties/guides/source/generators.textile
@@ -190,7 +190,7 @@ $ rails generate scaffold User name:string
invoke test_unit
create test/unit/helpers/users_helper_test.rb
invoke stylesheets
- create public/stylesheets/scaffold.css
+ create app/assets/stylesheets/scaffold.css.scss
</shell>
Looking at this output, it's easy to understand how generators work in Rails 3.0 and above. The scaffold generator doesn't actually generate anything, it just invokes others to do the work. This allows us to add/replace/remove any of those invocations. For instance, the scaffold generator invokes the scaffold_controller generator, which invokes erb, test_unit and helper generators. Since each generator has a single responsibility, they are easy to reuse, avoiding code duplication.
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 5906f953bf..3f9bd2b6da 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -368,7 +368,7 @@ The scaffold generator will build 15 files in your application, along with some
|test/functional/posts_controller_test.rb |Functional testing harness for the posts controller|
|test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper|
|config/routes.rb |Edited to include routing information for posts|
-|public/stylesheets/scaffold.css |Cascading style sheet to make the scaffolded views look better|
+|app/assets/stylesheets/scaffold.css.scss |Cascading style sheet to make the scaffolded views look better|
h4. Running a Migration
diff --git a/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb b/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb
index 12bd3920f8..d06db25292 100644
--- a/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb
+++ b/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb
@@ -2,7 +2,21 @@ module Rails
module Generators
class StylesheetsGenerator < Base
def copy_stylesheets_file
- template "scaffold.css", "app/assets/stylesheets/scaffold.css" if behavior == :invoke
+ 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
diff --git a/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css.scss b/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css.scss
new file mode 100644
index 0000000000..45116b53f6
--- /dev/null
+++ b/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css.scss
@@ -0,0 +1,58 @@
+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/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb
index aaeb686daa..4b86cdd1c7 100644
--- a/railties/test/generators/stylesheets_generator_test.rb
+++ b/railties/test/generators/stylesheets_generator_test.rb
@@ -4,14 +4,20 @@ require 'rails/generators/rails/stylesheets/stylesheets_generator'
class StylesheetsGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper
- def test_copy_stylesheets
+ def test_copy_scss_stylesheet
+ self.generator_class.any_instance.stubs(:using_sass?).returns(true)
run_generator
- assert_file "public/stylesheets/scaffold.css"
+ assert_file "app/assets/stylesheets/scaffold.css.scss"
+ end
+
+ def test_copy_css_stylesheet
+ run_generator
+ assert_file "app/assets/stylesheets/scaffold.css"
end
def test_stylesheets_are_not_deleted_on_revoke
run_generator
run_generator [], :behavior => :revoke
- assert_file "public/stylesheets/scaffold.css"
+ assert_file "app/assets/stylesheets/scaffold.css"
end
end