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

@ -27,11 +27,6 @@ module Middleman::CoreExtensions::DefaultHelpers
end end
module Helpers module Helpers
# TODO: Implement
def javascript_include_tag(path)
end
def auto_stylesheet_link_tag(separator="/") def auto_stylesheet_link_tag(separator="/")
auto_tag(:css, separator) do |path| auto_tag(:css, separator) do |path|
stylesheet_link_tag path stylesheet_link_tag path

View file

@ -38,7 +38,7 @@ module Middleman::CoreExtensions::Sprockets
end end
# add paths to js_env (vendor/assets/javascripts) # add paths to js_env (vendor/assets/javascripts)
app.map "/#{self.js_dir}" do map "/#{self.js_dir}" do
run js_env run js_env
end end
end end
@ -70,10 +70,7 @@ module Middleman::CoreExtensions::Sprockets
class MiddlemanEnvironment < ::Sprockets::Environment class MiddlemanEnvironment < ::Sprockets::Environment
def initialize(app) def initialize(app)
full_path = app.views super app.source_dir
full_path = File.join(app.root, app.views) unless app.views.include?(app.root)
super File.expand_path(full_path)
# Make the app context available to Sprockets # Make the app context available to Sprockets
context_class.send(:define_method, :app) { app } context_class.send(:define_method, :app) { app }
@ -93,9 +90,6 @@ module Middleman::CoreExtensions::Sprockets
def initialize(app) def initialize(app)
super super
# Disable css
# unregister_processor "text/css", ::Sprockets::DirectiveProcessor
self.js_compressor = app.js_compressor self.js_compressor = app.js_compressor
# configure search paths # configure search paths
@ -112,9 +106,6 @@ module Middleman::CoreExtensions::Sprockets
def initialize(app) def initialize(app)
super super
# Disable js
# unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor
self.css_compressor = app.css_compressor self.css_compressor = app.css_compressor
# configure search paths # configure search paths

View file

@ -5,14 +5,20 @@ module Middleman::Features::RelativeAssets
config.relative_assets = true config.relative_assets = true
end end
app.register_asset_handler :relative_assets do |path, prefix| app.send :include, InstanceMethods
end
alias :included :registered
end
module InstanceMethods
def asset_url(path, prefix="")
begin begin
prefix = self.images_dir if prefix == self.http_images_path prefix = self.images_dir if prefix == self.http_images_path
rescue rescue
end end
if path.include?("://") if path.include?("://")
self.before_asset_handler(:relative_assets, path, prefix) super(path, prefix)
elsif path[0,1] == "/" elsif path[0,1] == "/"
path path
else else
@ -33,6 +39,4 @@ module Middleman::Features::RelativeAssets
end end
end end
end end
alias :included :registered
end
end end