Ember-Rails and namespaced templates

。_饼干妹妹 提交于 2019-11-29 13:33:41

问题


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!


回答1:


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);
    }
  })
});


来源:https://stackoverflow.com/questions/15859552/ember-rails-and-namespaced-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!