简体   繁体   English

如何在Rails 2.3应用程序中使捆绑的gem中的静态资产保持同步?

[英]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 installbundle 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 installbundle 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.

相关问题 如何保持实时的MediaSource视频流同步? - How to keep a live MediaSource video stream in-sync? 如何从我的JavaScript文件链接到Django静态资产? - How do I link to Django static assets from my JavaScript files? 如何使我的数据与场景图保持同步? - How do I keep my data in sync with the scene graph? 如何从Rails的“查看”页面中的/ app / assets / javascripts文件夹中调用JS脚本? - How can I call upon a JS script in my /app/assets/javascripts folder from a View page in Rails? 您如何将静态资产打包在gem中以用于Sinatra应用程序? - How do you package static assets in a gem for use in Sinatra applications? flask-assets - 如何防止特定应用程序的静态 js 文件被另一个应用程序使用 - flask-assets - How to keep an specific app's static js files from being used by another app 如何将JQuery从模板添加到我的Rails应用程序? - How do I add JQuery from a template to my rails app? 如何在Rails 2.3应用程序的单个页面上替换原型? - How do I replace prototype on a single page of my rails 2.3 application? 如何使用凭据替换同步ajax调用以保持应用程序的状态稳定 - How can I replace a sync ajax call with credentials to keep my app's state stable 我如何拥有一个可以在我的 React 应用程序中的任何文件中使用的资产文件,而不必总是导航到资产文件夹 - How do i have an assets file that i can use in any file in my react app without always having to navigate to the assets folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM