2011-07-10 18:10:49 -04:00
|
|
|
require "sprockets"
|
2011-08-03 00:58:20 -04:00
|
|
|
|
2011-07-10 18:10:49 -04:00
|
|
|
module Middleman::CoreExtensions::Sprockets
|
|
|
|
class << self
|
2011-08-09 14:08:46 -04:00
|
|
|
def registered(app)
|
2011-07-10 19:02:52 -04:00
|
|
|
app.set :js_compressor, false
|
2011-08-09 14:08:46 -04:00
|
|
|
|
|
|
|
app.after_configuration do
|
|
|
|
app.map "/#{app.js_dir}" do
|
|
|
|
run JavascriptEnvironment.new(app)
|
|
|
|
end
|
2011-07-10 19:02:52 -04:00
|
|
|
end
|
2011-08-09 14:12:20 -04:00
|
|
|
|
2011-07-10 19:02:52 -04:00
|
|
|
# app.map "/#{app.css_dir}" do
|
|
|
|
# run StylesheetEnvironment.new(app)
|
2011-07-10 18:10:49 -04:00
|
|
|
# end
|
|
|
|
end
|
|
|
|
alias :included :registered
|
|
|
|
end
|
|
|
|
|
2011-08-03 00:58:20 -04:00
|
|
|
class MiddlemanEnvironment < ::Sprockets::Environment
|
2011-07-10 19:02:52 -04:00
|
|
|
def initialize(app)
|
2011-07-13 20:34:41 -04:00
|
|
|
full_path = app.views
|
|
|
|
full_path = File.join(app.root, app.views) unless app.views.include?(app.root)
|
|
|
|
|
|
|
|
super File.expand_path(full_path)
|
2011-07-10 19:02:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class JavascriptEnvironment < MiddlemanEnvironment
|
|
|
|
def initialize(app)
|
|
|
|
super
|
|
|
|
|
|
|
|
# Disable css
|
|
|
|
unregister_processor "text/css", ::Sprockets::DirectiveProcessor
|
|
|
|
|
|
|
|
self.js_compressor = app.settings.js_compressor
|
2011-07-10 18:10:49 -04:00
|
|
|
|
|
|
|
# configure search paths
|
2011-07-13 20:34:41 -04:00
|
|
|
append_path app.js_dir
|
2011-08-03 00:58:20 -04:00
|
|
|
|
|
|
|
# jQuery for Sprockets
|
|
|
|
# begin
|
|
|
|
# require "jquery-rails"
|
|
|
|
# jquery-rails / vendor / assets / javascripts
|
|
|
|
# rescue LoadError
|
|
|
|
# end
|
2011-07-10 18:10:49 -04:00
|
|
|
end
|
|
|
|
end
|
2011-07-10 19:02:52 -04:00
|
|
|
|
|
|
|
# class StylesheetEnvironment < MiddlemanEnvironment
|
|
|
|
# def initialize(app)
|
|
|
|
# super
|
|
|
|
#
|
|
|
|
# # Disable js
|
|
|
|
# unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor
|
|
|
|
#
|
|
|
|
# # configure search paths
|
|
|
|
# stylesheets_path = File.join(File.expand_path(app.views), app.css_dir)
|
|
|
|
# append_path stylesheets_path
|
|
|
|
# end
|
|
|
|
# end
|
2011-07-10 18:10:49 -04:00
|
|
|
end
|