从Rails应用程序中的gem重载CSS文件

时间:2023-02-05 09:56:11

I'm writing a Rails gem for my app. In this gem I have a CSS file. And everything works fine. But I want to be able to overload this file in my Rails app. Like this, my App will use the custom version of my CSS file.

我正在为我的应用程序编写Rails gem。在这个gem中我有一个CSS文件。一切正常。但我希望能够在我的Rails应用程序中重载此文件。像这样,我的应用程序将使用我的CSS文件的自定义版本。

Is it possible ?

可能吗 ?

Thank you in advance!

先谢谢你!

3 个解决方案

#1


1  

OK, I found it.

好的,我找到了。

I created a file with the same name in my App, but it also need to be located in a directory with the exact same path.

我在我的应用程序中创建了一个具有相同名称的文件,但它也需要位于具有完全相同路径的目录中。

In my case, I was trying to overload the file in my gem located vendor/assets/stylesheets with a file in app/assets/stylesheets

在我的情况下,我试图通过app / assets / stylesheets中的文件重载我的gem位于vendor / assets / stylesheets中的文件

#2


0  

You could also do a configuration option if the convention is too complex:

如果约定过于复杂,您还可以执行配置选项:

MyGem.configure do |config|
  config.stylesheet = 'app/stylesheets/my_style.css'
end

#3


0  

You can go with @import so that you are including stylesheets into other

您可以使用@import,以便将样式表包含在其他内容中

Is it possible to include one CSS file in another?

是否可以在另一个CSS文件中包含一个?

#1


1  

OK, I found it.

好的,我找到了。

I created a file with the same name in my App, but it also need to be located in a directory with the exact same path.

我在我的应用程序中创建了一个具有相同名称的文件,但它也需要位于具有完全相同路径的目录中。

In my case, I was trying to overload the file in my gem located vendor/assets/stylesheets with a file in app/assets/stylesheets

在我的情况下,我试图通过app / assets / stylesheets中的文件重载我的gem位于vendor / assets / stylesheets中的文件

#2


0  

You could also do a configuration option if the convention is too complex:

如果约定过于复杂,您还可以执行配置选项:

MyGem.configure do |config|
  config.stylesheet = 'app/stylesheets/my_style.css'
end

#3


0  

You can go with @import so that you are including stylesheets into other

您可以使用@import,以便将样式表包含在其他内容中

Is it possible to include one CSS file in another?

是否可以在另一个CSS文件中包含一个?