通过ember-cli-rails的Rails引擎内部的Ember Engine [英] Ember Engines inside Rails Engines via ember-cli-rails
问题描述
我们有一个高模块化的rails5应用程序,它在服务器仓库中的轨道引擎中分离,并集成为红宝石宝石。
现在我们要引入EmberJS, code>余烬-CLI-轨。主rails应用程序包含 frontend
目录中的主ember应用程序,而每个rails引擎都包含一个ember引擎(通过 ember-engine
由于迄今为止我没有找到其他解决方案,我创建了一个初始化程序,它符号链接所有轨道引擎的ember引擎目录进入消费轨道应用程序中消费的ember引擎的 node_modules
:
#获取node_modules dir
nm_dir = Rails.root.join('frontend','node_modules')
#删除现有符号链接
Dir.new(nm_dir.to_s).each {| entry | fileUtils.rm_rf(条目)如果条目=〜/^.+\-frontend$/}
#MODULES包含rails引擎gem名称的数组
MODULES.each do | module_name |
#每个模块都有一个Manifest类,加载
manifest = load_manifest(module_name)
#获取rails引擎前端目录的路径
source = Pathname.new(manifest.method(:setup).source_location [0] .split('/ lib /')[0])join('frontend')to_s
#Symlink destination
destination = nm_dir.join(#{module_name} -frontend)to_s
#Symlink it
FileUtils.symlink source,destination,force:true
end
这种方法可能不是很干净,但似乎有效。
We have a high modular rails5 app, which is splitted in rails engines over serveral repositories and integrated as ruby gems.
Now we want to introduce EmberJS by using ember-cli-rails
. The main rails application contains the main ember application in the frontend
directory while each of the rails engines contain an ember engine (via ember-engine
) in a frontend
directory.
How to mount the ember engines of the modules into the main ember engine?
Due the fact that I've found no other solution so far, I've created an initializer which symlinks the ember engine directories of all rails engines into the node_modules
of the consuming ember engine in the consuming rails app:
# Get the node_modules dir
nm_dir = Rails.root.join('frontend', 'node_modules')
# Delete existing symlinks
Dir.new(nm_dir.to_s).each { |entry| FileUtils.rm_rf(entry) if entry =~ /^.+\-frontend$/ }
# MODULES contains an array of the rails engine gem names
MODULES.each do |module_name|
# Each module has a Manifest class, load that
manifest = load_manifest(module_name)
# Get the path to the frontend dir of the rails engine
source = Pathname.new(manifest.method(:setup).source_location[0].split('/lib/')[0]).join('frontend').to_s
# Symlink destination
destination = nm_dir.join("#{module_name}-frontend").to_s
# Symlink it
FileUtils.symlink source, destination, force: true
end
This approach is probably not very clean, but it seems to work.
这篇关于通过ember-cli-rails的Rails引擎内部的Ember Engine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!