sprockets-sass was overwriting image-url and breaking relative assets. Fixes #256

This commit is contained in:
Thomas Reynolds 2012-02-05 11:43:19 -08:00
parent c8c6a1938e
commit 8286879f36
9 changed files with 35 additions and 56 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -1 +1 @@
activate :relative_assets
# activate :relative_assets

View file

@ -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

View file

@ -17,6 +17,7 @@ module Middleman::Extensions
# Include instance methods
app.send :include, InstanceMethods
end
alias :included :registered
end

View file

@ -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

View file

@ -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"])