Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember-rails project as a mountable engine?

Ember & Rails newb here with a serious question about both.

I'm building a project that leverages the ember-rails setup as exemplified here: https://github.com/dgeb/ember_data_example

However, to make things even more complicated, the project is intended to be packaged as a gem, for inclusion in a larger app. To that end I've created a mountable engine, containing a dummy project for testing.

Problem is, ember-rails, and and specifically handlebars cannot find the templates in their intended location. This prevents a lot of the functionality from working properly.

In terms of moving the handlebars template directory, I have found a solution here: How can I specify an alternative directory for my HandlebarsJS templates with the ember-rails gem?

In summary it states we can specify the path to the templates in application.rb by setting the value of config.handlebars.templates_root

However, I think this will cause a conflict should another ember-rails engine need to be loaded into a larger app.. and that one will need its own configuration setting.

Does anyone have experience with these setups, and is there any way to make a namespaced ember app play nice within a larger context?

By the way, this is rails 4 running the latest ember-rails on ruby 1.9.2.

like image 652
Alexandros K Avatar asked Jun 18 '13 13:06

Alexandros K


2 Answers

After doing a lot of research, it seems that Ember supports overriding the Default Resolver: http://emberjs.com/api/classes/Ember.DefaultResolver.html

You can instruct it to look for templates in your namespaced application by following the instructions here: https://github.com/emberjs/ember.js/pull/2354

In essence, a resolver can be added to your Ember.Application.create(): (to quote @lukemelia in the aforementioned pull request)

App1 = Ember.Application.create({
    resolver: Ember.DefaultResolver.extend({
        resolveTemplate: function(parsedName) {
          parsedName.fullNameWithoutType = "app1/" + parsedName.fullNameWithoutType;
          return this._super(parsedName);
        }
    })
});

This seems to be a part of ember rc5 at the time of writing.

like image 167
Alexandros K Avatar answered Oct 07 '22 10:10

Alexandros K


I just created an ember app inside a rails engine and I had the same issues as you did w/ getting handlebars support. I couldn't get ember-rails to work inside an engine so I looked at ember-rails source and I ended up just registering handlebars w/ tilt in my engine directly. There are some configurations inside ember-rails to change the root template path: handlebars.templates_root. However I didn't have success in getting that to work inside a rails engine.

https://github.com/andrewmp1/spree_outlet

I still haven't really grokked how I would do integration tests w/ the dummy app. But its coming along.

like image 33
Drew P Avatar answered Oct 07 '22 09:10

Drew P