ccocchi / rabl-rails

Rails 4.2+ templating system with JSON, XML and Plist support.
MIT License
209 stars 51 forks source link

Remove format requirement in template filename when using RablRails.render #51

Closed vjt closed 9 years ago

vjt commented 10 years ago

As Rabl can render multiple templates, forcing the user to specify the template format in the file name is a limitation.

This commit removes it, while remaining backwards compatible with the legacy format and printing out a deprecation warning.

Eventually, an XML render test was added.

Thanks for considering a merge! :beers:

cc:@lleirborras

ccocchi commented 10 years ago

Having the format in the path is a Rails convention and a one I'm not going to deprecate. This is useful when you are responding with multiple formats, hence having the same file with 2 different formats.

However, we can make the format optional to simplify tests or single formats file.

vjt commented 10 years ago

Thanks, sir.

donaldpiret commented 10 years ago

This still doesn't allow you to use a single template with multiple renderers though, right? That was supposed to be one of the big advantages of Rabl, (being able to render JSON or XML outputs with the same template) which is unfortunately lost here...

vjt commented 10 years ago

@donaldpiret nope, it doesn't - but you can have a look at our fork (compare here) that accomplishes just that. :yellow_heart:

ccocchi commented 10 years ago

Actually if you are using Rails, you can already name your templates without the format (i.e. index.rabl) and Rails will find and render them using the correct format from the params.

But I agree, if you're using RablRails.render you cannot achieve the same behavior. Maybe my options wasn't wisely chosen, I'll check on that.

vjt commented 10 years ago

:+1: :smile:

ccocchi commented 9 years ago

This commit 5ac7ccd36b0ea300f879940557dedeb6aeffeae9 should fix this issue. As of version 0.4.0, format is not mandatory in your templates names.