This commit is contained in:
Scott Davis 2011-07-25 22:47:29 -04:00
commit 38cf0e571b
19 changed files with 319 additions and 40 deletions

156
Gemfile.lock Normal file
View File

@ -0,0 +1,156 @@
GIT
remote: git://github.com/johnbintz/fakefs.git
revision: 7363b6f13bfcd9f583bbf7cd1e0d65c2dc656db7
specs:
fakefs (0.3.1)
PATH
remote: .
specs:
compass (0.11.3.rails.0.2124003)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
GEM
remote: http://rubygems.org/
specs:
ZenTest (4.5.0)
abstract (1.0.0)
actionmailer (3.0.9)
actionpack (= 3.0.9)
mail (~> 2.2.19)
actionpack (3.0.9)
activemodel (= 3.0.9)
activesupport (= 3.0.9)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
rack (~> 1.2.1)
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.9)
activesupport (= 3.0.9)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.9)
activemodel (= 3.0.9)
activesupport (= 3.0.9)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activeresource (3.0.9)
activemodel (= 3.0.9)
activesupport (= 3.0.9)
activesupport (3.0.9)
addressable (2.2.6)
arel (2.0.10)
autotest (4.4.6)
ZenTest (>= 4.4.1)
autotest-fsevent (0.2.5)
sys-uname
builder (2.1.2)
chunky_png (1.2.0)
compass-validator (3.0.1)
css_parser (1.0.1)
cucumber (0.9.4)
builder (~> 2.1.2)
diff-lcs (~> 1.1.2)
gherkin (~> 2.2.9)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
diff-lcs (1.1.2)
em-dir-watcher (0.9.4)
em-websocket (0.3.0)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
erubis (2.6.6)
abstract (>= 1.0.0)
eventmachine (0.12.10)
fssm (0.2.7)
gherkin (2.2.9)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
haml (3.1.2)
i18n (0.5.0)
json (1.4.6)
livereload (1.6)
em-dir-watcher (>= 0.1)
em-websocket (>= 0.1.2)
ruby-json (>= 1.1.2)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
mocha (0.9.12)
polyglot (0.3.1)
rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.9)
actionmailer (= 3.0.9)
actionpack (= 3.0.9)
activerecord (= 3.0.9)
activeresource (= 3.0.9)
activesupport (= 3.0.9)
bundler (~> 1.0)
railties (= 3.0.9)
railties (3.0.9)
actionpack (= 3.0.9)
activesupport (= 3.0.9)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.4)
rake (0.9.2)
rb-fsevent (0.4.0)
rcov (0.9.9)
rdoc (3.6.1)
rspec (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
rspec-mocks (~> 2.0.1)
rspec-core (2.0.1)
rspec-expectations (2.0.1)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
ruby-json (1.1.2)
ruby-prof (0.10.7)
rubyzip (0.9.4)
sass (3.1.3)
sys-uname (0.8.5)
term-ansicolor (1.0.5)
thor (0.14.6)
timecop (0.3.5)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.28)
PLATFORMS
ruby
DEPENDENCIES
autotest
autotest-fsevent
compass!
compass-validator (= 3.0.1)
css_parser (~> 1.0.1)
cucumber (~> 0.9.2)
diff-lcs (~> 1.1.2)
fakefs!
haml (~> 3.1)
livereload
mocha
rails (~> 3.0.0.rc)
rb-fsevent
rcov
rspec (~> 2.0.0)
ruby-prof
rubyzip
sass (~> 3.1)
timecop

View File

@ -53,13 +53,13 @@ $disable-magic-sprite-selectors:false !default;
// If a base class is provided, then each class will extend it.
//
// If `$dimensions` is `true`, the sprite dimensions will specified.
@mixin sprites($map, $sprite-names, $base-class: false, $dimensions: false, $prefix: sprite-map-name($map)) {
@mixin sprites($map, $sprite-names, $base-class: false, $dimensions: false, $prefix: sprite-map-name($map), $offset-x: 0, $offset-y: 0) {
@each $sprite-name in $sprite-names {
@if sprite_does_not_have_parent($map, $sprite-name) {
$full-sprite-name: "#{$prefix}-#{$sprite-name}";
.#{$full-sprite-name} {
@if $base-class { @extend #{$base-class}; }
@include sprite($map, $sprite-name, $dimensions);
@include sprite($map, $sprite-name, $dimensions, $offset-x, $offset-y);
}
}
}

View File

@ -24,8 +24,10 @@ module Compass
end
def configuration
Compass::Configuration::Data.new('rails').
extend(ConfigurationDefaults)
config = Compass::Configuration::Data.new('rails')
config.extend(ConfigurationDefaults)
config.extend(ConfigurationDefaultsWithAssetPipeline) if Sass::Util.ap_geq?('3.1.0.beta')
config
end
def env
@ -48,12 +50,17 @@ module Compass
end
end
def initialize!(config = nil)
def check_for_double_boot!
if booted?
Compass::Util.compass_warn("Warning: Compass was booted twice. Compass has a Railtie now; please remove your initializer.")
else
booted!
end
end
# Rails 2.x projects use this in their compass initializer.
def initialize!(config = nil)
check_for_double_boot!
config ||= Compass.detect_configuration_file(root)
Compass.add_project_configuration(config, :project_type => :rails)
Compass.discover_extensions!

View File

@ -0,0 +1,10 @@
%w(action_controller sass_plugin urls).each do |lib|
require "compass/app_integration/rails/actionpack2x/#{lib}"
end
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
class Sass::Script::Functions::EvaluationContext
include Sass::Script::Functions
private
include ActionView::Helpers::AssetTagHelper
end

View File

@ -0,0 +1,11 @@
# TODO figure something out so image_path works with rails integration
%w(railtie).each do |lib|
require "compass/app_integration/rails/actionpack30/#{lib}"
end
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
class Sass::Script::Functions::EvaluationContext
include Sass::Script::Functions
private
include ActionView::Helpers::AssetTagHelper
end

View File

@ -40,7 +40,10 @@ module Compass
initializer "compass.initialize_rails" do |app|
# Configure compass for use within rails, and provide the project configuration
# that came via the rails boot process.
Compass::AppIntegration::Rails.initialize!(app.config.compass)
Compass::AppIntegration::Rails.check_for_double_boot!
Compass.discover_extensions!
Compass.configure_sass_plugin!
Compass.handle_configuration_change!
end
end
end

View File

@ -0,0 +1,5 @@
# TODO figure something out so image_path works with rails integration
%w(railtie).each do |lib|
require "compass/app_integration/rails/actionpack31/#{lib}"
end

View File

@ -0,0 +1,50 @@
require 'compass'
require 'rails'
class Rails::Railtie::Configuration
# Adds compass configuration accessor to the application configuration.
#
# If a configuration file for compass exists, it will be read in and
# the project's configuration values will already be set on the config
# object.
#
# For example:
#
# module MyApp
# class Application < Rails::Application
# config.compass.line_comments = !Rails.env.production?
# config.compass.fonts_dir = "app/assets/fonts"
# end
# end
#
# It is suggested that you create a compass configuration file if you
# want a quicker boot time when using the compass command line tool.
#
# For more information on available configuration options see:
# http://compass-style.org/help/tutorials/configuration-reference/
def compass
@compass ||= begin
data = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file))
config_data
else
Compass::Configuration::Data.new("rails_config")
end
data.project_type = :rails # Forcing this makes sure all the rails defaults will be loaded.
Compass.add_project_configuration(data)
data
end
@compass
end
end
module Compass
class Railtie < Rails::Railtie
initializer "compass.initialize_rails" do |app|
# Configure compass for use within rails, and provide the project configuration
# that came via the rails boot process.
Compass::AppIntegration::Rails.check_for_double_boot!
Compass.discover_extensions!
Compass.configure_rails!(app)
end
end
end

View File

@ -1,6 +1,28 @@
module Compass
module AppIntegration
module Rails
module ConfigurationDefaultsWithAssetPipeline
# These methods overwrite the old rails defaults
# when rails 3.1 is detected.
def default_sass_dir
File.join("app", "assets", "stylesheets")
end
def default_images_dir
File.join("app", "assets", "images")
end
def default_fonts_dir
File.join("app", "assets", "fonts")
end
def default_javascripts_dir
File.join("app", "assets", "javascripts")
end
end
module ConfigurationDefaults
def project_type_without_default
@ -8,12 +30,8 @@ module Compass
end
def default_sass_dir
if Sass::Util.ap_geq?('3.1.0.beta')
File.join("app", "assets", "stylesheets")
else
File.join("app", "stylesheets")
end
end
def default_css_dir
File.join("public", "stylesheets")
@ -28,12 +46,8 @@ module Compass
end
def default_javascripts_dir
if Sass::Util.ap_geq?('3.1.0.beta')
File.join("app", "assets", "javascripts")
else
File.join("public", "javascripts")
end
end
def default_http_images_path
"#{top_level.http_path}images"

View File

@ -3,25 +3,15 @@ unless defined?(Compass::RAILS_LOADED)
begin
require 'action_pack/version'
if ActionPack::VERSION::MAJOR >= 3
# TODO figure something out so image_path works with rails integration
%w(railtie).each do |lib|
require "compass/app_integration/rails/actionpack3/#{lib}"
if ActionPack::VERSION::MINOR < 1
require 'compass/app_integration/rails/actionpack30'
else
require 'compass/app_integration/rails/actionpack31'
end
else
%w(action_controller sass_plugin urls).each do |lib|
require "compass/app_integration/rails/actionpack2/#{lib}"
require 'compass/app_integration/rails/actionpack2x'
end
end
rescue LoadError => e
$stderr.puts "Compass could not access the rails environment."
rescue NameError => e
rescue LoadError, NameError
$stderr.puts "Compass could not access the rails environment."
end
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
class Sass::Script::Functions::EvaluationContext
include Sass::Script::Functions
private
include ActionView::Helpers::AssetTagHelper
end
end

View File

@ -77,6 +77,12 @@ module Compass
end
end
def configure_rails!(app)
app.config.compass.to_sass_engine_options.each do |key, value|
app.config.sass.send(:"#{key}=", value)
end
end
def sass_engine_options
configuration.to_sass_engine_options
end

View File

@ -27,6 +27,7 @@ module Compass
if @added_import_paths
self.additional_import_paths ||= []
self.additional_import_paths += @added_import_paths
self.additional_import_paths.uniq!
end
issue_deprecation_warnings
end

View File

@ -132,13 +132,13 @@ $#{name}-layout:vertical !default;
@include sprite($#{name}-sprites, $name, $dimensions, $offset-x, $offset-y)
}
@mixin #{name}-sprites($sprite-names, $dimensions: $#{name}-sprite-dimensions, $prefix: sprite-map-name($#{name}-sprites)) {
@include sprites($#{name}-sprites, $sprite-names, $#{name}-sprite-base-class, $dimensions, $prefix)
@mixin #{name}-sprites($sprite-names, $dimensions: $#{name}-sprite-dimensions, $prefix: sprite-map-name($#{name}-sprites), $offset-x: 0, $offset-y: 0) {
@include sprites($#{name}-sprites, $sprite-names, $#{name}-sprite-base-class, $dimensions, $prefix, $offset-x, $offset-y)
}
// Generates a class for each sprited image.
@mixin all-#{name}-sprites($dimensions: $#{name}-sprite-dimensions, $prefix: sprite-map-name($#{name}-sprites)) {
@include #{name}-sprites(#{sprite_names(uri).join(" ")}, $dimensions, $prefix);
@mixin all-#{name}-sprites($dimensions: $#{name}-sprite-dimensions, $prefix: sprite-map-name($#{name}-sprites), $offset-x: 0, $offset-y: 0) {
@include #{name}-sprites(#{sprite_names(uri).join(" ")}, $dimensions, $prefix, $offset-x, $offset-y);
}
SCSS
end

View File

@ -448,7 +448,7 @@ class SpritesTest < Test::Unit::TestCase
CSS
end
it "should render corret sprite with css selectors via issue#248" do
it "should render correct sprite with css selectors via issue#248" do
css = render <<-SCSS
@import "selectors/*.png";
@include all-selectors-sprites;
@ -473,7 +473,32 @@ class SpritesTest < Test::Unit::TestCase
CSS
end
it "should render corret sprite with css selectors via magic mixin" do
it "should honor offsets when rendering selectors via issue#449" do
css = render <<-SCSS
@import "selectors/*.png";
@include all-selectors-sprites($offset-x: 20px, $offset-y: 20px);
SCSS
assert_correct css, <<-CSS
.selectors-sprite, .selectors-ten-by-ten {
background: url('/selectors-sedfef809e2.png') no-repeat;
}
.selectors-ten-by-ten {
background-position: 20px 20px;
}
.selectors-ten-by-ten:hover, .selectors-ten-by-ten.ten-by-ten_hover, .selectors-ten-by-ten.ten-by-ten-hover {
background-position: 20px 0;
}
.selectors-ten-by-ten:target, .selectors-ten-by-ten.ten-by-ten_target, .selectors-ten-by-ten.ten-by-ten-target {
background-position: 20px -10px;
}
.selectors-ten-by-ten:active, .selectors-ten-by-ten.ten-by-ten_active, .selectors-ten-by-ten.ten-by-ten-active {
background-position: 20px 10px;
}
CSS
end
it "should render correct sprite with css selectors via magic mixin" do
css = render <<-SCSS
@import "selectors/*.png";
a {
@ -500,6 +525,7 @@ class SpritesTest < Test::Unit::TestCase
CSS
end
it "should not render corret sprite with css selectors via magic mixin" do
css = render <<-SCSS
@import "selectors/*.png";