Sha256: f8f030c36e59920a4ab8070d8cf387446d0e41de6f881f0f13e3ca06579172ab

Contents?: true

Size: 1.09 KB

Versions: 26

Compression:

Stored size: 1.09 KB

Contents

begin
  require 'sprockets'
  require 'middleman/rack/sprockets+ruby19' # Sprockets ruby 1.9 duckpunch
rescue LoadError
  puts "Sprockets not available. Install it with: gem install sprockets"
end
  
module Middleman
  module Rack
    class Sprockets
      def initialize(app, options={})
        @app = app
      end

      def call(env)
        path   = env["PATH_INFO"]
        source = File.join(Middleman::Base.views, path)
            
        if path.match(/\.js$/) && File.exists?(source)
          secretary = ::Sprockets::Secretary.new( :root   => Middleman::Base.root,
                                                  :source_files => [ File.join("views", path) ],
                                                  :load_path    => [ File.join("public", Middleman::Base.js_dir),
                                                                     File.join("views", Middleman::Base.js_dir) ])

          [200, { "Content-Type" => "text/javascript" }, [secretary.concatenation.to_s]]
        else
          @app.call(env)
        end
      end
    end
  end
end

Middleman::Base.supported_formats << "js"

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
middleman-0.10.0 lib/middleman/rack/sprockets.rb
middleman-0.9.23 lib/middleman/rack/sprockets.rb
middleman-0.9.22 lib/middleman/rack/sprockets.rb
middleman-0.9.21 lib/middleman/rack/sprockets.rb
middleman-0.9.20 lib/middleman/rack/sprockets.rb
middleman-0.9.18 lib/middleman/rack/sprockets.rb