jakeboxer/hyperloop — pull request #7 by jakeboxer (2013-10-20 18:40:10+00:00)
Title: Get partials working

This branch implements partials. They work the same way as they do in Rails:

``` erb
<%# Assume there's a file at app/views/subdir/_partial.html.erb %>

This comes before the partial.

<%= render "subdir/partial" %>

This comes after the partial.

```

The actual rendering of partials is pretty easy. You can see a super dumb implementation in 57d2b269613b4ad71fbecc3864a3cca04db4c37d. Most of the important stuff in this pull is refactoring. I'll outline the two important parts here:

### `View::Scope`

[rtomayko/tilt](https://github.com/rtomayko/tilt/tree/tilt-1) allows a "scope" to be passed to `Template#render`. The scope is just an object that defines the methods you can use in the template. So, if a template has `<%= pluralize("dog") %>`, it'll look for a `pluralize` method in the scope object you passed to `Template#render`.

This branch adds `View::Scope`, which includes the `View::Scope#render` method. This is what lets us do `<%= render "subdir/partial" %>` in templates.

### `View::Registry`

Previously, views were loaded in `Application.new`, and looked up in `Application#call`. Now, `Application.new` creates a new `View::Registry`, which handles loading the views (in `View::Registry.new`) and looking them up (in `View::Registry#find_template_view`). It also handles looking up partials with `View::Registry#find_partial_view`, which `View::Scope#render` (described above) calls.

/cc @jessicard