应该看起来像rails的正确CSS文件模板是什么?

时间:2014-04-23 16:57:05

标签: html css ruby-on-rails asset-pipeline

我正在为CSS做一个Rails教程,我已被指示在app / assets / stylesheets / shmoogle.css.scss下创建一个shmoogle.css.scss文件

该文件旁边是application.css文件,如下所示:

/*
 * This is a manifest file that'll be compiled into application.css, which will include   
   all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, 
   vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a   
   relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the   
   bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any 
   styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to 
   create a new
 * file per style scope.
 *
 *= require_tree .
 *= require_self
 *= require_shmoogle
 */

请注意我要求_shmoogle的倒数第二行。它是否正确?是应该像这样被评论出来吗?

2 个答案:

答案 0 :(得分:1)

require_tree .指令会自动包含当前目录中的所有css文件,因此您不需要为该特定文件单独的require语句。

当您需要按特定顺序加载的文件时,自定义需要派上用场。例如:

*= require_self
*= require load_me_first
*= require load_me_next
*= require_tree ./subfolder_to_require_next
*= require_tree .

该代码将包含您指定顺序的文件,最终require_tree .将包含其他所有内容。如果您不想包含其他所有内容,则可以删除require_tree .指令并手动要求所有内容。

清单文件的注释性质是预期的。特殊指令(以*=开头)会在资产管道中引起特殊行为。在注释块之外编写的任何代码都将被解释为常规css代码,并包含在require_self指令中。

您可以在Manifest Files and Directives中详细了解Assets Pipeline Rails Guide

答案 1 :(得分:0)

应该是require shmoogle,但由于您已经在执行require_tree .,因此不需要此声明。 require_tree递归地要求当前目录中的所有样式表。

因此,请将您的application.css更新为仅包含:

*= require_tree .
*= require_self
相关问题