[英]How do I keep static assets from a bundled gem in-sync in my Rails 2.3 app?
I am working on a Rails 2.3 application and would like to refactor some of my static assets (JS, CSS) into a separate gem. 我正在开发Rails 2.3应用程序,并希望将我的一些静态资产(JS,CSS)重构为单独的gem。 The problem is that Rails 2.3 engines don't have the support for public directories that Rails 3 engines do, so the only way to access these files from the app is to copy them over.
问题在于,Rails 2.3引擎不像Rails 3引擎那样支持公共目录,因此从应用程序访问这些文件的唯一方法是将它们复制过来。
One thought I had was to use some sort of "afterBundle" hook of some sort that I could use to automatically copy the assets after "bundle install" completes. 我曾经想到的是使用某种“ afterBundle”挂钩,在“捆绑包安装”完成后,可以使用该挂钩自动复制资产。 I took a look at Bundler's documentation and source and didn't find anything like what I'm thinking.
我查看了Bundler的文档和来源,却没有发现我所想的东西。 How have others solved this problem?
别人如何解决这个问题?
One issue in using Bundler is that there are now two install paths for you gem, gem install
and bundle install
. 使用Bundler的一个问题是,gem现在有两个安装路径,
gem install
和bundle install
。 Even if you do hack a Bundler post install action to Bundler it won't run if some one does gem install
. 即使您确实对Bundler进行了Bundler安装后操作,但如果有人
gem install
它也不会运行。 One solution is to make the gemspec relatively empty, example: 一种解决方案是使gemspec相对为空,例如:
https://github.com/hedgehog/fog/blob/bundler/fog.gemspec https://github.com/hedgehog/fog/blob/bundler/fog.gemspec
Then simulate a post install hook for gem install
, which in fact invokes bundle install
: 然后模拟
gem install
后钩子,它实际上会调用bundle install
:
https://github.com/hedgehog/fog/commit/32878aaa9ef1fd3add148039fecd6e4059873d5d https://github.com/hedgehog/fog/commit/32878aaa9ef1fd3add148039fecd6e4059873d5d
With this work around you can add your post install actions after bundle install
is run. 通过此方法,您可以在运行
bundle install
后添加安装后操作。
However, by adding the post install steps to gem install
you have re-introduced the opening problem - two different install paths, just that now gem install
does more (the post install steps) than bundle install
does. 但是,通过将后安装步骤添加到
gem install
您又重新引入了开放性问题-两种不同的安装路径,只是现在gem install
( bundle install
后)比bundle install
功能更多。
See also: http://blog.costan.us/2008/11/post-install-post-update-scripts-for.html 另请参阅: http : //blog.costan.us/2008/11/post-install-post-update-scripts-for.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.