我正在研究一个包含三个不同应用程序的项目。他们应该分享一些模型和外部布局。为了避免代码重复,我试图将应用程序布局(project_name/app/views/layouts/application.html.haml
)提取到一个gem中。如何将应用程序布局打包到Ruby gem中?
我按照这些步骤:
- 里面创建
common/app/views/layouts/application.html.haml
与
bundle gem common
- 地方布局文件基本宝石结构写的Gemspec描述
# -*- encoding: utf-8 -*- require File.expand_path('../lib/common/version', __FILE__) Gem::Specification.new do |gem| gem.authors = ["Arthur Alkmim"] gem.email = ["[email protected]"] gem.description = %q{Common project files} gem.summary = %q{Common project files, including layout and migrations} gem.homepage = "" gem.files = `git ls-files`.split($\) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = "common" gem.require_paths = ["lib"] gem.version = Common::VERSION end
提交更改
gem build common.gemspec
(成功)rake install
(成功)- 将
gem 'common'
项目的Gemfile
但还是该项目将不会加载应用程序的布局。我应该怎么做才能告诉我的项目必须通过gem加载布局文件?
在此先感谢。
如何使用git子模块或svn外部?如果你走宝石路线,你将不得不建立/安装每当有变化。 – kreek
@KreeK子模块和外部设备是一种痛苦。根据我的经验处理宝石更容易 - 只需运行“捆绑安装”即可。特别是Git子模块非常烦人。 –