fix relative assets and sprockets js

This commit is contained in:
Thomas Reynolds 2011-11-18 17:37:01 -08:00
parent 7d9550e9ce
commit 4ceb9bab41
5 changed files with 36 additions and 46 deletions

View file

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

View file

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

View file

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

View file

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