Coder Social home page Coder Social logo

Comments (7)

nesquena avatar nesquena commented on August 19, 2024

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?

from rabl.

ismasan avatar ismasan commented on August 19, 2024

Maybe just:

Rabl.configure do |config|
    config.views_path = 'my_own_custom_path'
end

from rabl.

nesquena avatar nesquena commented on August 19, 2024

Actually yeah that is much more reasonable, I think that would be the best bet.

from rabl.

nesquena avatar nesquena commented on August 19, 2024

This should be fixed for Sinatra (has been for a while), finally closing.

from rabl.

delphaber avatar delphaber commented on August 19, 2024

Hi. I think this solution does not work no more. :(

NoMethodError: undefined method `views_path=' for #Rabl::Configuration:0xb04dad4

from rabl.

nesquena avatar nesquena commented on August 19, 2024

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

from rabl.

delphaber avatar delphaber commented on August 19, 2024

I'm using subfolders. I've fixed using another tip from another user in this github
Hope this could help someone else :)

views/activities/index.rabl:
collection @activities

extends 'show', {:view_path => 'views/activities/'}

This should load views/activities/show.rabl for each activity in @activities

from rabl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.