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.11.2 lib/middleman/rack/sprockets.rb
middleman-0.11.1 lib/middleman/rack/sprockets.rb
middleman-0.11.0 lib/middleman/rack/sprockets.rb
middleman-0.10.17 lib/middleman/rack/sprockets.rb
middleman-0.10.16 lib/middleman/rack/sprockets.rb
middleman-0.10.15 lib/middleman/rack/sprockets.rb
middleman-0.10.14 lib/middleman/rack/sprockets.rb
middleman-0.10.13 lib/middleman/rack/sprockets.rb
middleman-0.10.12 lib/middleman/rack/sprockets.rb
middleman-0.10.11 lib/middleman/rack/sprockets.rb
middleman-0.10.10 lib/middleman/rack/sprockets.rb
middleman-0.10.9 lib/middleman/rack/sprockets.rb
middleman-0.10.8 lib/middleman/rack/sprockets.rb
middleman-0.10.7 lib/middleman/rack/sprockets.rb
middleman-0.10.6 lib/middleman/rack/sprockets.rb
middleman-0.10.5 lib/middleman/rack/sprockets.rb
middleman-0.10.4 lib/middleman/rack/sprockets.rb
middleman-0.10.3 lib/middleman/rack/sprockets.rb
middleman-0.10.2 lib/middleman/rack/sprockets.rb
middleman-0.10.1 lib/middleman/rack/sprockets.rb