Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 5 commits
  • 20 files changed
  • 0 commit comments
  • 2 contributors
Commits on May 24, 2011
tomhuda Remaining cleanup from changes to AssetTagHelper 59f6065
tomhuda Change compressor API so that plugins can register default compressor…
…s for their stylesheet or JS engines and still allow the user to turn off compression
9701db1
tomhuda Move SCSS generators and default templates from Rails to the Sass Rai…
…ltie (d435726312601edb3ba6f97b34f562221f72c1f8).

* Sass gem registers a compressor
* Sass gem registers generators for assets and scaffold
* Create a default stylesheet_engine ("css") for apps that remove the Sass gem
ac3503c
@wycats wycats Update generator config to support hiding namespaces and pass the app…
… into generator blocks
9f815ee
@wycats wycats Hide css:* and the default stylesheet from rails g c796d69
View
8 actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
@@ -187,12 +187,8 @@ def javascript_path(source)
#
# javascript_include_tag :all, :cache => true, :recursive => true
def javascript_include_tag(*sources)
- if config.use_sprockets
- sprockets_javascript_include_tag(*sources)
- else
- @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths)
- @javascript_include.include_tag(*sources)
- end
+ @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths)
+ @javascript_include.include_tag(*sources)
end
end
end
View
8 actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
@@ -137,12 +137,8 @@ def stylesheet_path(source)
# stylesheet_link_tag :all, :concat => true
#
def stylesheet_link_tag(*sources)
- if config.use_sprockets
- sprockets_stylesheet_link_tag(*sources)
- else
- @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths)
- @stylesheet_include.include_tag(*sources)
- end
+ @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths)
+ @stylesheet_include.include_tag(*sources)
end
end
View
3 actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -4,6 +4,9 @@
module Sprockets
module Helpers
module RailsHelper
+ extend ActiveSupport::Concern
+ include ActionView::Helpers::AssetTagHelper
+
def asset_paths
@asset_paths ||= begin
config = self.config if respond_to?(:config)
View
26 actionpack/lib/sprockets/railtie.rb
@@ -9,15 +9,7 @@ def self.using_coffee?
false
end
- def self.using_scss?
- require 'sass'
- defined?(Sass)
- rescue LoadError
- false
- end
-
config.app_generators.javascript_engine :coffee if using_coffee?
- config.app_generators.stylesheet_engine :scss if using_scss?
# Configure ActionController to use sprockets.
initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app|
@@ -28,7 +20,8 @@ def self.using_scss?
# We need to configure this after initialization to ensure we collect
# paths from all engines. This hook is invoked exactly before routes
- # are compiled.
+ # are compiled, and so that other Railties have an opportunity to
+ # register compressors.
config.after_initialize do |app|
assets = app.config.assets
next unless assets.enabled
@@ -36,6 +29,8 @@ def self.using_scss?
app.assets = asset_environment(app)
ActiveSupport.on_load(:action_view) do
+ include ::Sprockets::Helpers::RailsHelper
+
app.assets.context_class.instance_eval do
include ::Sprockets::Helpers::RailsHelper
end
@@ -59,8 +54,8 @@ def asset_environment(app)
env.static_root = File.join(app.root.join("public"), assets.prefix)
env.paths.concat assets.paths
env.logger = Rails.logger
- env.js_compressor = expand_js_compressor(assets.js_compressor)
- env.css_compressor = expand_css_compressor(assets.css_compressor)
+ env.js_compressor = expand_js_compressor(assets.js_compressor) if assets.compress
+ env.css_compressor = expand_css_compressor(assets.css_compressor) if assets.compress
env
end
@@ -82,15 +77,6 @@ def expand_js_compressor(sym)
def expand_css_compressor(sym)
case sym
- when :scss
- require 'sass'
- compressor = Object.new
- def compressor.compress(source)
- Sass::Engine.new(source,
- :syntax => :scss, :style => :compressed
- ).render
- end
- compressor
when :yui
require 'yui/compressor'
YUI::CssCompressor.new
View
5 railties/lib/rails/application.rb
@@ -103,9 +103,10 @@ def load_tasks
self
end
- def load_generators
+ def load_generators(app=self)
initialize_generators
- railties.all { |r| r.load_generators }
+ railties.all { |r| r.load_generators(app) }
+
super
self
end
View
6 railties/lib/rails/configuration.rb
@@ -43,6 +43,7 @@ def merge_into(other)
class Generators #:nodoc:
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
+ attr_reader :hidden_namespaces
def initialize
@aliases = Hash.new { |h,k| h[k] = {} }
@@ -50,6 +51,7 @@ def initialize
@fallbacks = {}
@templates = []
@colorize_logging = true
+ @hidden_namespaces = []
end
def initialize_copy(source)
@@ -59,6 +61,10 @@ def initialize_copy(source)
@templates = @templates.dup
end
+ def hide_namespace(namespace)
+ @hidden_namespaces << namespace
+ end
+
def method_missing(method, *args)
method = method.to_s.sub(/=$/, '').to_sym
View
10 railties/lib/rails/generators.rb
@@ -57,7 +57,7 @@ module Generators
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
:stylesheets => true,
- :stylesheet_engine => nil,
+ :stylesheet_engine => :css,
:test_framework => false,
:template_engine => :erb
},
@@ -75,6 +75,7 @@ def self.configure!(config = Rails.application.config.generators) #:nodoc:
fallbacks.merge! config.fallbacks
templates_path.concat config.templates
templates_path.uniq!
+ hide_namespaces *config.hidden_namespaces
end
def self.templates_path
@@ -175,6 +176,7 @@ def self.hidden_namespaces
orm = options[:rails][:orm]
test = options[:rails][:test_framework]
template = options[:rails][:template_engine]
+ css = options[:rails][:stylesheet_engine]
[
"rails",
@@ -194,7 +196,11 @@ def self.hidden_namespaces
"#{test}:plugin",
"#{template}:controller",
"#{template}:scaffold",
- "#{template}:mailer"
+ "#{template}:mailer",
+ "#{css}:scaffold",
+ "#{css}:assets",
+ "css:assets",
+ "css:scaffold"
]
end
end
View
13 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
View
3 ...ails/assets/templates/stylesheet.css.scss → ...ators/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/
*/
View
16 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
View
3 railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -21,4 +21,7 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
+
+ # Do not compress assets
+ config.assets.compress = false
end
View
6 railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -11,9 +11,11 @@
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
- # Compress both stylesheets and JavaScripts
+ # Compress JavaScripts and CSS
+ config.assets.compress = true
+
+ # Specify the default JavaScript compressor
config.assets.js_compressor = :uglifier
- config.assets.css_compressor = :scss
# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
View
11 railties/lib/rails/generators/rails/assets/assets_generator.rb
@@ -13,12 +13,6 @@ def create_javascript_files
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 @@ def javascript_extension
"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
View
13 railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -11,21 +11,12 @@ class ScaffoldGenerator < ResourceGenerator #metagenerator
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
View
58 railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss
@@ -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;
- }
-}
View
4 railties/lib/rails/railtie.rb
@@ -189,8 +189,8 @@ def load_tasks
end
end
- def load_generators
- self.class.generators.each(&:call)
+ def load_generators(app)
+ self.class.generators.each { |block| block.call(app) }
end
end
end
View
6 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
View
2 railties/test/generators/controller_generator_test.rb
@@ -40,7 +40,7 @@ def test_does_not_invoke_helper_if_required
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
View
8 railties/test/generators/namespaced_generators_test.rb
@@ -252,7 +252,7 @@ def test_scaffold_on_invoke
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 @@ def test_scaffold_on_revoke
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 @@ def test_scaffold_with_namespace_on_invoke
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 @@ def test_scaffold_with_namespace_on_revoke
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
View
32 railties/test/generators/scaffold_generator_test.rb
@@ -80,9 +80,9 @@ def test_scaffold_on_invoke
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 @@ def test_scaffold_on_revoke
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 @@ def test_scaffold_with_namespace_on_invoke
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 @@ def test_scaffold_with_namespace_on_revoke
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 @@ def test_scaffold_generator_on_revoke_does_not_mutilate_legacy_map_parameter
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"

No commit comments for this range

Something went wrong with that request. Please try again.