middleman/middleman — pull request #1314 by tdreyno (2014-07-06 00:38:09+00:00)
Title: Untangle Rack from Application

Honestly, I can't believe I got this done in a day :)

Basically, this removes all the Rack magic crap (`call`, `call!`, etc) from `Application` and makes a nice new class called `Middleman::Rack`. You can use it like this:

```
@server_inst = ::Middleman::Application.new
rack = ::Middleman::Rack.new(@server_inst)
@browser = ::Rack::MockRequest.new(rack.to_app)
```

Which is how the tests, preview server and build CLI all run requests through Middleman (including rack middleware).

As an incredibly nice side-effect, we no longer have to `dup` `Application` every request. We don't wrap `Application` in an anonymous class for safety. Everything is safe! Finally! Simply make a new `::Middleman::Application.new` wherever you want and never worry.

This also improves the song and dance inside `Middleman::Extension` for figuring out if we have a live instance of App yet. Now, the current instance is always available. This causes some backwards incompatibilities in extensions, but I think it's worth it. Basically, it was "expected" that `app` would be a class in `initialize`, but an instance everywhere else. So anyone wanting to modify the class could do it there. That's no longer possible (for good reason), but we may want to find a way to make that transition easier? `middleman-sprockets` is current broken on this branch for that reason.