Ember-Rails和命名空间的模板 [英] Ember-Rails and namespaced templates

查看:136
本文介绍了Ember-Rails和命名空间的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails应用程序,命名为三个部分(共3个应用程序共享模型)。我想为每个命名空间部分拥有自己的Ember应用程序。这些应用程序从未在相同的布局中加载,因此不必了解彼此的任何内容。实际上,我希望保持代码尽可能分开,因为该应用最终可能会被分解。



我正在尝试使用ember-rails宝贝。



基本上是这样的问题:
如何使用ember-rails gem指定我的HandlebarsJS模板的替代目录



答案在那里有效,但我很确定使用templates_root限制我只有一个命名空间。所以我也不能有一个admin.js和admin / templates命名空间以及一个customer.js和customer / templates命名空间。



所以有人知道如果ember -rails将支持多个命名空间的Ember应用程序并渲染多个模板根结果?



谢谢!

解决方案

已发布这里,您可以使用命名空间通过向每个应用程序添加自定义解析器来模板。

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


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!

解决方案

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

这篇关于Ember-Rails和命名空间的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆