diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..5b86ed71 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/VERSION.yml b/VERSION.yml index 594f4d73..f8ec44cf 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -4,4 +4,4 @@ :patch: 0 :state: alpha :build: 0 -:name: Alnilam +:name: Alnilam \ No newline at end of file diff --git a/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss b/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss index d40740dc..1b268a84 100644 --- a/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss +++ b/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss @@ -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); } } } diff --git a/lib/compass/app_integration/rails.rb b/lib/compass/app_integration/rails.rb index dcd1b0e2..a850d8d7 100644 --- a/lib/compass/app_integration/rails.rb +++ b/lib/compass/app_integration/rails.rb @@ -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! diff --git a/lib/compass/app_integration/rails/actionpack2x.rb b/lib/compass/app_integration/rails/actionpack2x.rb new file mode 100644 index 00000000..f48299bb --- /dev/null +++ b/lib/compass/app_integration/rails/actionpack2x.rb @@ -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 diff --git a/lib/compass/app_integration/rails/actionpack2/action_controller.rb b/lib/compass/app_integration/rails/actionpack2x/action_controller.rb similarity index 100% rename from lib/compass/app_integration/rails/actionpack2/action_controller.rb rename to lib/compass/app_integration/rails/actionpack2x/action_controller.rb diff --git a/lib/compass/app_integration/rails/actionpack2/sass_plugin.rb b/lib/compass/app_integration/rails/actionpack2x/sass_plugin.rb similarity index 100% rename from lib/compass/app_integration/rails/actionpack2/sass_plugin.rb rename to lib/compass/app_integration/rails/actionpack2x/sass_plugin.rb diff --git a/lib/compass/app_integration/rails/actionpack2/urls.rb b/lib/compass/app_integration/rails/actionpack2x/urls.rb similarity index 100% rename from lib/compass/app_integration/rails/actionpack2/urls.rb rename to lib/compass/app_integration/rails/actionpack2x/urls.rb diff --git a/lib/compass/app_integration/rails/actionpack30.rb b/lib/compass/app_integration/rails/actionpack30.rb new file mode 100644 index 00000000..05e24df8 --- /dev/null +++ b/lib/compass/app_integration/rails/actionpack30.rb @@ -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 diff --git a/lib/compass/app_integration/rails/actionpack3/railtie.rb b/lib/compass/app_integration/rails/actionpack30/railtie.rb similarity index 89% rename from lib/compass/app_integration/rails/actionpack3/railtie.rb rename to lib/compass/app_integration/rails/actionpack30/railtie.rb index a3fc5498..2e52ae3b 100644 --- a/lib/compass/app_integration/rails/actionpack3/railtie.rb +++ b/lib/compass/app_integration/rails/actionpack30/railtie.rb @@ -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 \ No newline at end of file diff --git a/lib/compass/app_integration/rails/actionpack31.rb b/lib/compass/app_integration/rails/actionpack31.rb new file mode 100644 index 00000000..bbd2d531 --- /dev/null +++ b/lib/compass/app_integration/rails/actionpack31.rb @@ -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 + diff --git a/lib/compass/app_integration/rails/actionpack31/railtie.rb b/lib/compass/app_integration/rails/actionpack31/railtie.rb new file mode 100644 index 00000000..6604e836 --- /dev/null +++ b/lib/compass/app_integration/rails/actionpack31/railtie.rb @@ -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 \ No newline at end of file diff --git a/lib/compass/app_integration/rails/configuration_defaults.rb b/lib/compass/app_integration/rails/configuration_defaults.rb index fbab17e2..06aaf311 100644 --- a/lib/compass/app_integration/rails/configuration_defaults.rb +++ b/lib/compass/app_integration/rails/configuration_defaults.rb @@ -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,11 +30,7 @@ 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 + File.join("app", "stylesheets") end def default_css_dir @@ -28,11 +46,7 @@ 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 + File.join("public", "javascripts") end def default_http_images_path diff --git a/lib/compass/app_integration/rails/runtime.rb b/lib/compass/app_integration/rails/runtime.rb index d2765ef0..815fd29f 100644 --- a/lib/compass/app_integration/rails/runtime.rb +++ b/lib/compass/app_integration/rails/runtime.rb @@ -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}" - end + require 'compass/app_integration/rails/actionpack2x' end - rescue LoadError => e + rescue LoadError, NameError $stderr.puts "Compass could not access the rails environment." - rescue NameError => e - $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 diff --git a/lib/compass/configuration/helpers.rb b/lib/compass/configuration/helpers.rb index db6f8af6..9017f735 100644 --- a/lib/compass/configuration/helpers.rb +++ b/lib/compass/configuration/helpers.rb @@ -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 diff --git a/lib/compass/configuration/serialization.rb b/lib/compass/configuration/serialization.rb index ff41ecc2..bf7a5288 100644 --- a/lib/compass/configuration/serialization.rb +++ b/lib/compass/configuration/serialization.rb @@ -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 diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index 7639f4da..d006d3ee 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -34,7 +34,7 @@ module Compass::SassExtensions::Functions::Sprites # # background: url('/images/icons.png?12345678') 0 -24px no-repeat; def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO) - sprite = convert_sprite_name(sprite) + sprite = convert_sprite_name(sprite) verify_map(map) unless sprite.is_a?(Sass::Script::String) raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.) diff --git a/lib/compass/sprite_importer.rb b/lib/compass/sprite_importer.rb index d46403d9..1bda1162 100644 --- a/lib/compass/sprite_importer.rb +++ b/lib/compass/sprite_importer.rb @@ -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 diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 99a7d63e..3db8e640 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -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; @@ -472,8 +472,33 @@ class SpritesTest < Test::Unit::TestCase } CSS end + + 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 corret sprite with css selectors via magic mixin" do + it "should render correct sprite with css selectors via magic mixin" do css = render <<-SCSS @import "selectors/*.png"; a { @@ -499,6 +524,7 @@ class SpritesTest < Test::Unit::TestCase } CSS end + it "should not render corret sprite with css selectors via magic mixin" do css = render <<-SCSS