sinatra/sinatra — pull request #529 by blambeau (2012-06-13 14:21:33+00:00)
Title: Recognize Path-like objects in Templates#compile_template

The following commit aims at allowing the following behavior

get '/:some/:parameters' do

#
# Find an existing file that correspond to the request. Make some checks.
# Returns a Pathname or a Path instance, responding to #path
#
filepath = ...

#
# Render found file, reusing sinatra template cache, options, etc.
#
erb filepath, ...

end

The pull request allows this provided that the located file is inside the views folder. This is to match the current behavior that does not allow rendering files outside it (without extending `find_template`).

I'm not sure this pull request makes sense. However, I'm not really confortable with the following workarounds:

# assuming a relative_from method that returns another Path(name)
erb filepath.relative_from(settings.views).to_s.to_sym

# manually use Tilt, no cache support
Tilt.new(filepath).render ...

# explicit use of the template cache
template_cache.fetch(filepath){ ... }.render ...

What do you think?