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

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

问题描述

我有一个 Rails 应用程序,它的命名空间分为三个部分(几乎 3 个共享模型的应用程序).我希望每个命名空间部分都有自己的 Ember 应用程序.这些应用程序永远不会以相同的布局加载,因此不必了解彼此的任何信息.事实上,当应用最终可以真正拆分时,我希望尽可能将代码分开.

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.

我正在尝试使用 ember-rails gem 来做到这一点.

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

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

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

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.

那么有谁知道 ember-rails 是否会支持多个命名空间的 Ember 应用程序并因此渲染多个模板根?

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

谢谢!

推荐答案

发布于 here 您可以通过向每个应用程序添加自定义解析器来拥有命名空间模板.

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天全站免登陆