Genius / perspectives

Render shared views on the client OR on the server
https://github.com/RapGenius/perspectives
MIT License
77 stars 5 forks source link

Using Perspectives in an Engine #2

Open emerson-h opened 9 years ago

emerson-h commented 9 years ago

I'm working on an application that uses a component based approach, so we have several engines. I would love to keep the views as dumb as possible and Perspectives seems to be a great way to do that.

The project is setup something like this:

/var/www/
   /app
   /bin
   /components
      /foo_engine
         /app
            /assets
            /perspectives
               /bar
                  show.rb
            /mustaches
               /bar
                  show.mustache
            ...
        /bin
        ...
   /config
   ...

When visiting the engine's routes in the URL (e.g. foo_engine/bars/1/show), perspectives raises this error:

No such file or directory @ rb_sysopen - /var/www/app/mustaches/bar/show.mustache

It seems like it's not recognizing that it's running within an engine, so it's looking for mustaches in the top level app folder.

a-warner commented 9 years ago

@emerson-h you should be able to configure the template path to whatever you want. The default railtie configures it to be app/mustaches relative to the project root (link), but you can change that:

Perspectives.configure do |c|
  c.template_path = app.root.join('whatever', 'you', 'want')
end
emerson-h commented 9 years ago

@a-warner Thanks! I saw that a couple of minutes ago as I was looking for a possible fix. It seems like it might be more robust to have the railtie default the template path to be relative to the directory of the including railtie, so for instance, if included in an engine, it would default to /app/mustaches/ for that engine.

If you think that's a good idea, I'm happy to submit a pull request

a-warner commented 9 years ago

@emerson-h i'd love to see a pull request. the template path should be relative to the root of the including engine/app for sure.

emerson-h commented 9 years ago

@a-warner I'm working on a fix for this, but so far it's proving more intractable than I hoped.

A stop-gap solution is to symlink the mustaches folder from an engine into the including application.

a-warner commented 9 years ago

ugh, that's a deeply unsatisfying stop-gap though :smile:

it seems like Rails probably handles this pretty well, I guess by allowing railties/engines to append to the view_paths instead of having one total view path for the app? maybe a similar solution here would make sense? (although how do you distinguish between users/show in your app vs the engine..or maybe that's not a big deal?)