From 8286879f36b19edc0e52cbc76a8872fdc3ed15f4 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sun, 5 Feb 2012 11:43:19 -0800 Subject: [PATCH] sprockets-sass was overwriting image-url and breaking relative assets. Fixes #256 --- middleman-core/bin/middleman | 13 +++--- .../lib/middleman-core/cli/build.rb | 5 ++- .../core_extensions/extensions.rb | 12 ++--- .../features/relative_assets.feature | 6 +-- .../fixtures/relative-assets-app/config.rb | 2 +- .../middleman-more/core_extensions/compass.rb | 45 ++++--------------- .../extensions/relative_assets.rb | 1 + .../lib/middleman-more/renderers/sass.rb | 5 ++- middleman-more/middleman-more.gemspec | 2 +- 9 files changed, 35 insertions(+), 56 deletions(-) diff --git a/middleman-core/bin/middleman b/middleman-core/bin/middleman index c4d46e36..e37fd292 100755 --- a/middleman-core/bin/middleman +++ b/middleman-core/bin/middleman @@ -33,17 +33,16 @@ end # Default command is server ARGV.unshift("server") if ARGV.length < 1 || ARGV.first.include?("-") -# Require Middleman -require 'middleman-core' - begin - # Rubygems - require "middleman-more" + # Local + require File.expand_path(File.join(File.dirname(File.dirname(libdir)), "middleman-more", "lib", "middleman-more")) rescue LoadError begin - # Local - require File.expand_path(File.join(File.dirname(File.dirname(libdir)), "middleman-more", "lib", "middleman-more")) + # Rubygems + require "middleman-more" rescue LoadError + # Require Middleman + require 'middleman-core' end end diff --git a/middleman-core/lib/middleman-core/cli/build.rb b/middleman-core/lib/middleman-core/cli/build.rb index c2e0f567..a16fd4b1 100644 --- a/middleman-core/lib/middleman-core/cli/build.rb +++ b/middleman-core/lib/middleman-core/cli/build.rb @@ -44,6 +44,8 @@ module Middleman::Cli exit(1) end + self.class.shared_instance(options["verbose"] || false) + if options.has_key?("relative") && options["relative"] self.class.shared_instance.activate :relative_assets end @@ -65,9 +67,10 @@ module Middleman::Cli # Middleman::Base singleton # # @return [Middleman::Base] - def shared_instance + def shared_instance(verbose=false) @_shared_instance ||= ::Middleman.server.inst do set :environment, :build + set :logging, verbose end end diff --git a/middleman-core/lib/middleman-core/core_extensions/extensions.rb b/middleman-core/lib/middleman-core/core_extensions/extensions.rb index 5bee01b0..10affbd9 100644 --- a/middleman-core/lib/middleman-core/core_extensions/extensions.rb +++ b/middleman-core/lib/middleman-core/core_extensions/extensions.rb @@ -97,17 +97,17 @@ module Middleman::CoreExtensions::Extensions # @param [Symbol, Module] ext Which extension to activate # @return [void] def activate(ext, options={}, &block) - if !ext.is_a?(Module) - ext = ::Middleman::Extensions.load(ext.to_sym) + ext_module = if ext.is_a?(Module) + ext + else + ::Middleman::Extensions.load(ext.to_sym) end - if ext.nil? + if ext_module.nil? puts "== Unknown Extension: #{ext}" - elsif ext.is_a?(String) - puts ext else puts "== Activating: #{ext}" if logging? - self.class.register(ext, options, &block) + self.class.register(ext_module, options, &block) end end diff --git a/middleman-more/features/relative_assets.feature b/middleman-more/features/relative_assets.feature index ad936a8c..ba06de53 100644 --- a/middleman-more/features/relative_assets.feature +++ b/middleman-more/features/relative_assets.feature @@ -6,7 +6,7 @@ Feature: Relative Assets And the Server is running at "relative-assets-app" When I go to "/stylesheets/relative_assets.css" Then I should not see "url('../" - And I should see "url('/images/blank.gif')" + And I should see "/images/blank.gif')" Scenario: Building css with the feature disabled Given a fixture app "relative-assets-app" @@ -46,8 +46,8 @@ Feature: Relative Assets Then I should not see "/images/blank.gif" And I should see "images/blank.gif" - Scenario: Rendering html with a custom images_dir - Given "css" feature is "enabled" + Scenario: Rendering css with a custom images_dir + Given "relative_assets" feature is "enabled" And "images_dir" is set to "img" And the Server is running at "relative-assets-app" When I go to "/stylesheets/relative_assets.css" diff --git a/middleman-more/fixtures/relative-assets-app/config.rb b/middleman-more/fixtures/relative-assets-app/config.rb index b4efaffc..88ce0817 100644 --- a/middleman-more/fixtures/relative-assets-app/config.rb +++ b/middleman-more/fixtures/relative-assets-app/config.rb @@ -1 +1 @@ -activate :relative_assets \ No newline at end of file +# activate :relative_assets \ No newline at end of file diff --git a/middleman-more/lib/middleman-more/core_extensions/compass.rb b/middleman-more/lib/middleman-more/core_extensions/compass.rb index ab251aef..872da23b 100644 --- a/middleman-more/lib/middleman-more/core_extensions/compass.rb +++ b/middleman-more/lib/middleman-more/core_extensions/compass.rb @@ -16,39 +16,16 @@ module Middleman::CoreExtensions::Compass app.after_configuration do ::Compass.configuration do |config| - config.project_path = root + config.project_path = source_dir config.environment = :development config.cache_path = File.join(root, ".sass-cache") - config.sass_dir = File.join(source, css_dir) - config.css_dir = File.join(source, css_dir) - config.javascripts_dir = File.join(source, js_dir) - config.fonts_dir = File.join(source, fonts_dir) - config.images_dir = File.join(source, images_dir) - - config.http_images_path = if respond_to? :http_images_path - http_images_path - else - File.join(http_prefix, images_dir) - end - - config.http_stylesheets_path = if respond_to? :http_css_path - http_css_path - else - File.join(http_prefix, css_dir) - end - - config.http_javascripts_path = if respond_to? :http_js_path - http_js_path - else - File.join(http_prefix, js_dir) - end + config.sass_dir = css_dir + config.css_dir = css_dir + config.javascripts_dir = js_dir + config.fonts_dir = fonts_dir + config.images_dir = images_dir + config.http_path = http_prefix - config.http_fonts_path = if respond_to? :http_fonts_path - http_fonts_path - else - File.join(http_prefix, fonts_dir) - end - config.asset_cache_buster :none config.output_style = :nested @@ -57,13 +34,9 @@ module Middleman::CoreExtensions::Compass end end - # Change paths when in build mode. Required for relative paths - # configure :build do + # if build? # ::Compass.configuration do |config| - # config.environment = :production - # config.css_dir = File.join(build_dir, css_dir) - # config.images_dir = File.join(build_dir, images_dir) - # config.fonts_dir = File.join(build_dir, fonts_dir) + # config.environment = :production # end # end diff --git a/middleman-more/lib/middleman-more/extensions/relative_assets.rb b/middleman-more/lib/middleman-more/extensions/relative_assets.rb index 4c779ff9..1f694eee 100755 --- a/middleman-more/lib/middleman-more/extensions/relative_assets.rb +++ b/middleman-more/lib/middleman-more/extensions/relative_assets.rb @@ -17,6 +17,7 @@ module Middleman::Extensions # Include instance methods app.send :include, InstanceMethods end + alias :included :registered end diff --git a/middleman-more/lib/middleman-more/renderers/sass.rb b/middleman-more/lib/middleman-more/renderers/sass.rb index b8eccd2c..af82197f 100644 --- a/middleman-more/lib/middleman-more/renderers/sass.rb +++ b/middleman-more/lib/middleman-more/renderers/sass.rb @@ -1,7 +1,10 @@ # Pull in gems -require "sass" require "sprockets" require "sprockets-sass" +require "sass" + +# Stick with Compass' asset functions +Sprockets::Sass.add_sass_functions = false # Sass renderer module Middleman::Renderers::Sass diff --git a/middleman-more/middleman-more.gemspec b/middleman-more/middleman-more.gemspec index 29ca0f52..b982be44 100644 --- a/middleman-more/middleman-more.gemspec +++ b/middleman-more/middleman-more.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| s.add_dependency("uglifier", ["~> 1.2.0"]) s.add_dependency("haml", ["~> 3.1.0"]) s.add_dependency("sass", ["~> 3.1.7"]) - s.add_dependency("compass", ["0.12.rc.0"]) + s.add_dependency("compass", ["0.12.rc.1"]) s.add_dependency("coffee-script", ["~> 2.2.0"]) s.add_dependency("execjs", ["~> 1.2.7"]) s.add_dependency("sprockets", ["~> 2.1.0"])