From 4ceb9bab418b8ab69657572ee7bd2b070c26fb66 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 18 Nov 2011 17:37:01 -0800 Subject: [PATCH] fix relative assets and sprockets js --- .../bootstrap_include.css.scss | 0 lib/middleman/base.rb | 2 +- .../core_extensions/default_helpers.rb | 5 -- lib/middleman/core_extensions/sprockets.rb | 15 +---- lib/middleman/features/relative_assets.rb | 60 ++++++++++--------- 5 files changed, 36 insertions(+), 46 deletions(-) rename fixtures/sprockets-app/source/library/{stylesheets => css}/bootstrap_include.css.scss (100%) diff --git a/fixtures/sprockets-app/source/library/stylesheets/bootstrap_include.css.scss b/fixtures/sprockets-app/source/library/css/bootstrap_include.css.scss similarity index 100% rename from fixtures/sprockets-app/source/library/stylesheets/bootstrap_include.css.scss rename to fixtures/sprockets-app/source/library/css/bootstrap_include.css.scss diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index b78a8c93..17b9a2d7 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -218,7 +218,7 @@ class Middleman::Base @current_path = @request_path.dup path, engine = found_template - + # Static File return send_file(path) if engine.nil? diff --git a/lib/middleman/core_extensions/default_helpers.rb b/lib/middleman/core_extensions/default_helpers.rb index 01baabb4..db1e7c4f 100644 --- a/lib/middleman/core_extensions/default_helpers.rb +++ b/lib/middleman/core_extensions/default_helpers.rb @@ -27,11 +27,6 @@ module Middleman::CoreExtensions::DefaultHelpers end module Helpers - - # TODO: Implement - def javascript_include_tag(path) - end - def auto_stylesheet_link_tag(separator="/") auto_tag(:css, separator) do |path| stylesheet_link_tag path diff --git a/lib/middleman/core_extensions/sprockets.rb b/lib/middleman/core_extensions/sprockets.rb index 2ee84e48..469c465e 100644 --- a/lib/middleman/core_extensions/sprockets.rb +++ b/lib/middleman/core_extensions/sprockets.rb @@ -38,7 +38,7 @@ module Middleman::CoreExtensions::Sprockets end # add paths to js_env (vendor/assets/javascripts) - app.map "/#{self.js_dir}" do + map "/#{self.js_dir}" do run js_env end end @@ -70,10 +70,7 @@ module Middleman::CoreExtensions::Sprockets class MiddlemanEnvironment < ::Sprockets::Environment def initialize(app) - full_path = app.views - full_path = File.join(app.root, app.views) unless app.views.include?(app.root) - - super File.expand_path(full_path) + super app.source_dir # Make the app context available to Sprockets context_class.send(:define_method, :app) { app } @@ -92,12 +89,9 @@ module Middleman::CoreExtensions::Sprockets class JavascriptEnvironment < MiddlemanEnvironment def initialize(app) super - - # Disable css - # unregister_processor "text/css", ::Sprockets::DirectiveProcessor self.js_compressor = app.js_compressor - + # configure search paths append_path app.js_dir end @@ -111,9 +105,6 @@ module Middleman::CoreExtensions::Sprockets class StylesheetEnvironment < MiddlemanEnvironment def initialize(app) super - - # Disable js - # unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor self.css_compressor = app.css_compressor diff --git a/lib/middleman/features/relative_assets.rb b/lib/middleman/features/relative_assets.rb index 8558c48e..9bdb56ac 100755 --- a/lib/middleman/features/relative_assets.rb +++ b/lib/middleman/features/relative_assets.rb @@ -4,35 +4,39 @@ module Middleman::Features::RelativeAssets app.compass_config do |config| config.relative_assets = true end - - app.register_asset_handler :relative_assets do |path, prefix| - begin - prefix = self.images_dir if prefix == self.http_images_path - rescue - end - - if path.include?("://") - self.before_asset_handler(:relative_assets, path, prefix) - elsif path[0,1] == "/" - path - else - path = File.join(prefix, path) if prefix.length > 0 - request_path = @request_path.dup - request_path << self.index_file if path.match(%r{/$}) - request_path.gsub!(%r{^/}, '') - parts = request_path.split('/') - - if parts.length > 1 - arry = [] - (parts.length - 1).times { arry << ".." } - arry << path - File.join(*arry) - else - path - end - end - end + + app.send :include, InstanceMethods end alias :included :registered end + + module InstanceMethods + def asset_url(path, prefix="") + begin + prefix = self.images_dir if prefix == self.http_images_path + rescue + end + + if path.include?("://") + super(path, prefix) + elsif path[0,1] == "/" + path + else + path = File.join(prefix, path) if prefix.length > 0 + request_path = @request_path.dup + request_path << self.index_file if path.match(%r{/$}) + request_path.gsub!(%r{^/}, '') + parts = request_path.split('/') + + if parts.length > 1 + arry = [] + (parts.length - 1).times { arry << ".." } + arry << path + File.join(*arry) + else + path + end + end + end + end end \ No newline at end of file