Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember-Rails and namespaced templates

I have a Rails app that is namespaced into three sections (almost 3 apps that share models). I would like for each namespaced section to have it's own Ember app. These apps are never loaded in the same layout so don't have to know anything about each other. In fact I would like to keep the code as separate as possible for when the app can eventually be really split up.

I am trying to do this using the ember-rails gem.

Basically it is like this question: How can I specify an alternative directory for my HandlebarsJS templates with the ember-rails gem?

And the answer there works, but I'm pretty sure using templates_root limits me to just one namespace. So I couldn't also have an admin.js and admin/templates namespace as well as a customer.js and customer/templates namespace.

So does anyone know if ember-rails will support multiple namespaced Ember apps and render multiple template roots as a result?

Thanks!

like image 553
ootoovak Avatar asked Apr 07 '13 06:04

ootoovak


1 Answers

As posted here you can have namespace templates by adding a custom resolver to each app.

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

App2 = Ember.Application.create({
  Resolver: Ember.DefaultResolver.extend({
    resolveTemplate: function(parsedName) {
      parsedName.fullNameWithoutType = "app2/" + parsedName.fullNameWithoutType;
      return this._super(parsedName);
    }
  })
});

App3 = Ember.Application.create({
  Resolver: Ember.DefaultResolver.extend({
    resolveTemplate: function(parsedName) {
      parsedName.fullNameWithoutType = "app3/" + parsedName.fullNameWithoutType;
      return this._super(parsedName);
    }
  })
});
like image 200
Mike Grassotti Avatar answered Oct 07 '22 01:10

Mike Grassotti