如何在 Sinatra 应用程序中链接 Sass 文件?
我正在尝试将 Sass 文件链接到 Sinatra 应用程序。我有一个 public/sass/styles.scss
文件,我试图将其链接到我的 views/layout.haml
文件中。我可以使用 layout.haml
中的以下链接链接常规 css 文件:%link(rel="stylesheet" href="styles.css")
。但是,当我尝试链接到我的 sass/styles.scss 时,它不起作用。有人可以告诉我如何在 Sinatra 应用程序中链接 Sass css 文件吗?谢谢!
I am trying to link a Sass file to a Sinatra app. I have a public/sass/styles.scss
file and I am trying to link it in my views/layout.haml
file. I am able to link a regular css file using the following link in my layout.haml
: %link(rel="stylesheet" href="styles.css")
. However, when I try and link to my sass/styles.scss
, it does not work. Can someone please tell me how to link a Sass css file in a Sinatra app? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 Sass::Plugin::Rack
首先安装 Sass gem。
如果您使用 Bundler,请将其添加到 Gemfile 中:
gem 'sass'
。在您的 config.ru 中添加:
然后在 public/stylesheets/sass/ 中创建一个文件夹,并将所有 .scss 和 .sass 文件放入其中。
这将在
public/stylesheets/
中创建相应的 .css例如:
public/stylesheets/sass/style.scss
将生成public/stylesheets/style.css 就这样
,您可以更改默认路径并更改 参考文档
You can use Sass::Plugin::Rack
First install the Sass gem.
Add it in your Gemfile, if you are using Bundler:
gem 'sass'
.In your
config.ru
add:Then create a folder in
public/stylesheets/sass/
, and drop all your .scss and .sass files there.This will create the corresponding .css in
public/stylesheets/
For example:
public/stylesheets/sass/style.scss
will generatepublic/stylesheets/style.css
And that's it, you can change the paths from the default ones and change other options mentioned in the reference docs
您不需要使用单独的 gem 来编译 .scss 文件,Sass 具有内置功能。
sass --watch style.scss:style.css
将设置 Sass 在 style.scss 发生更改时自动将其编译为 style.css。从 Sass 网站,You don't need to use a separate gem to compile your .scss files, Sass has that built-in.
sass --watch style.scss:style.css
will set Sass to automatically compile style.scss into style.css whenever it gets changed. From the Sass website,你可以这样做:
You could do:
你不链接scss,像sass这样的scss不是一个应该由浏览器解释的文件,你需要一个编译器来处理这个文件并将其转换为css。
您需要指南针 gem 从您的 scss 自动生成 css,然后按照您之前提到的方式链接该 css
这里有一个 sinatra 指南针配置的示例:
You dont link the scss, a scss like a sass is not a file that is supposed to be interpreted by the browser, you need a compiler that process this file and convert it to css.
You need the compass gem to automatically generate the css from your scss and then you link the css as you were referring before
Here you have an example of compass configuration for sinatra: