将其移动到答案中,因为评论(只是有点)沉重,即使我意识到这不是您正在寻找的确切答案。
我还没有转向 Rails 3.1,但我已经使用 Compass/Sass 很长一段时间了,我可以大致描述一下我的(有些不断变化的)实践。
在此处查看指南针:
http://compass-style.org/
我的目标是尽可能地模块化,并以几种不同的方式将我的样式分类。示例结构可能如下所示。我将 cmets 与文件层次结构一起嵌入,因此希望它是可读的。
- stylesheets
# at top level, the files which are eventually concatenated and output, the main
# sheet, "screen", a stripped version for a wysywyg editor, and some overrides.
- screen.scss
- print.scss
- ie.scss
- wysiwg.scss
# also in this folder I tend to keep a reset
- _reset.scss
# and then separated, "includes" and "partials", includes being purely definitions
# and mixins, while partials being their application (actual CSS output)
- _includes.scss
- includes
- _definitions.scss # some global variable defs
- _typography.scss # typography mixins and defs
- _colors.scss # colors mixins and defs, and so on
- ...
- _partials.scss
- partials
- _application.scss # top level layout + tweaks that don't belong anywhere else
- _typography.scss # the generation of typography CSS
- _colors.scss # the generation of colors CSS, and so on
- ...
- _layouts.scss
- layouts # layout specific styles
- _controllers.scss
- controllers # controller specific styles
- _modules.scss
- modules # modular, reusable pieces (widgets, breadcrumbs, navs, etc)
- _vendor.scss
- vendor # everything vendor, (jquery-ui, qtip, colorbox)
基本思想是所有内容都被编译到顶级 *.scss 文件中,唯一不是带有下划线前缀的“部分”文件。这些文件非常简单,通常看起来像这样。
# screen.scss, import all partials
@import 'reset';
@import 'partials';
# wysiwyg.scss doesn't need all the partials, but needs the basic stuff
# and the semantic classes for wysiwyg users, e.g. ".red", etc.
@import 'reset';
@import 'partials/typography';
@import 'partials/colors';
@import 'partials/semantic';
_layouts.scss 和其他共享文件夹名称的文件是它们各自目录中文件的简单集体导入。
一般的想法是,partials 保持尽可能薄,而在 mixins 中完成的工作首当其冲。幸运的是,Compass 还提供了一个完整的手提袋,我经常使用它。
对于某些这种类型的文件结构可能很笨拙,但我发现它很适合我的目的。特别是一旦你获得了一个很好的 mixins 库和可交换的部分库。它使调整一些变量定义或将一个部分或混合替换为另一个以实现快速全局更改变得有些容易。