sstephenson/sprockets — pull request #555 by josh (2014-04-10 04:54:37+00:00)
Title: Early feedback: New processor API

As part of the source map long game, we're going to need to rework the template processor api. All processors are going to need to accept and return extra metadata instead of just the String data. This means we need to get off the Tilt api which is locked into a single value String return and has constrained inputs.

The new API is more function based and works kinda like Rack's call interface.

``` ruby
module CoffeeScriptTemplate
def self.call(input)
::CoffeeScript.compile(input[:data])
end
end
```

`input` is a simple hash of metadata like `:data`, `:filename`, `:content_type` etc. I'm still figuring out what plugin developers are going to want access to here. But trying to keep it scoped as tightly as possible.

You can then return a simple `String` or a `Hash`. The `Hash` return type gives us the ability to do:

``` ruby
module CoffeeScriptTemplate
def self.call(input)
[js, sourcemap] = ::CoffeeScript.compile(input[:data])
{ data: js, map: sourcemap }
end
end
```

This type of return type should be more extendable going forward since future keys will just be ignored by old versions.

**The Plan**

After I get my shit together, I will cut an "early developer beta" of Sprockets 3.0.0.beta. My plan is to bother any developer on GitHub hosting a sprockets processor plugin and try to get feedback on the API.

I want Sprockets 3.x to be as backwards compatible as possible with 2.x in regard to "user facing apis". Basically the APIs you use from a Rails application. Then do my best to shim "plugin apis" to ease the transition from 2.x and 3.x. It should be straight forward to write a sprockets plugin that supports both 2.x and 3.x

Then 4.x will drop with source maps and kill 2.x legacy APIs. Plugins should be able to then target 3.x and 4.x.

/cc @maccman @dgraham @mislav @rafaelfranca @guilleiguaran