-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"partial" and "extends" support in Sinatra #50
Comments
Yeah you are absolutely right. I never investigated the best way to build the file path for a template in a sinatra app. I know there is a way to get the view_paths in the app with settings.views but I didn't have access to that in the helpers module. I always use RABL alongside Padrino / Rails so it wasn't an issue for me. If anybody has any suggestions or patches, I would be curious. One option is to support a proc inside rabl configuration: Rabl.configure do |config|
config.fetch_source = lambda do |file, options|
file_path = Dir[File.join(APP_ROOT, 'views', file + "*.rabl")].first
File.read(file_path) if file_path
end
end What do you guys think? |
Maybe just:
|
Actually yeah that is much more reasonable, I think that would be the best bet. |
This should be fixed for Sinatra (has been for a while), finally closing. |
Hi. I think this solution does not work no more. :( NoMethodError: undefined method `views_path=' for #Rabl::Configuration:0xb04dad4 |
Not sure you should have to set anything, here's where its calculated: https://github.com/nesquena/rabl/blob/master/lib/rabl/partials.rb#L52 |
I'm using subfolders. I've fixed using another tip from another user in this github views/activities/index.rabl: extends 'show', {:view_path => 'views/activities/'} This should load views/activities/show.rabl for each activity in @activities |
partial() and extends() don't work in Sinatra because the internal method fetch_source() relies on either Rails or Padrino to resolve the path for the views directory. I had to monkey-patch that method in my Sinatra app:
.. Where APP_ROOT is a constant I defined in my app.
Is there a better way?
The text was updated successfully, but these errors were encountered: