2010-09-04 23:26:48 -04:00
|
|
|
class Middleman::Features::MinifyJavascript
|
2010-09-05 22:28:38 -04:00
|
|
|
def initialize(app, config)
|
2010-09-04 23:26:48 -04:00
|
|
|
Haml::Javascript.send :include, ::Haml::Filters::Base
|
|
|
|
|
|
|
|
require "middleman/features/minify_javascript/rack"
|
|
|
|
app.use Middleman::Rack::MinifyJavascript
|
|
|
|
end
|
|
|
|
|
|
|
|
module Haml
|
2009-10-22 20:25:15 -04:00
|
|
|
module Javascript
|
|
|
|
def render_with_options(text, options)
|
2010-09-04 23:26:48 -04:00
|
|
|
compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
|
|
|
|
data = compressor.compress(text)
|
|
|
|
%Q{<script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>#{data.chomp}</script>}
|
2009-10-22 20:25:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-09-04 23:26:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Middleman::Features.register :minify_javascript, Middleman::Features::MinifyJavascript
|