Sinatra utiliza Tilt para hacer sus plantillas, y para asociar extensiones con ellos. Todo lo que tiene que hacer es decirle inclinarlo debe usar ERB que hace a esta extensión:
Tilt.register Tilt::ERBTemplate, 'html.erb'
get '/hi' do
erb :hello
end
Editar a responder a la pregunta de seguimiento. No hay #unregister
y también tenga en cuenta que Sinatra preferirá hello.erb sobre hello.html.erb. La forma de evitar el problema preferencia es o bien reemplazar el método erb
o hacer su propio método render:
Tilt.register Tilt::ERBTemplate, 'html.erb'
def herb(template, options={}, locals={})
render "html.erb", template, options, locals
end
get '/hi' do
herb :hello
end
que preferirán hello.html.erb, pero aún caer de nuevo hello.erb si no puede encuentra hello.html.erb. Si realmente desea evitar que se encuentren archivos .erb bajo ninguna circunstancia, podría, supongo, crear la subclase ERBTemplate y registrarla contra .html.erb, pero francamente eso no parece valer la pena.
¡Gracias! Funciona muy bien, y también deja '.erb' trabajando también. No es que me gustaría mezclar convenciones, pero aún así es útil saberlo. ¿Sabes? Si no quería manejar .erb por más tiempo y solo .html.erb, ¿podría llamar a algo diferente de '.register' para deshabilitar las extensiones .erb? – mattmc3
De nada. Mira mi edición –