移动到答案,这是因为它(只是一个位)巨额的评论,尽管我知道这是不是你确切的答案”重新寻找。
我还没有转移到rails 3.1,但我一直在使用Compass/Sass很长一段时间,我可以宽松地描述我的(不断变化的)实践。
退房罗盘在这里: http://compass-style.org/
我的目标是要尽可能模块化,和我的风格分成类别几种不同的方式。示例结构可能如下所示。我嵌入评论与文件层次结构,所以希望它是可读的。
- 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
和其他文件是简单的文件的集体进口其各自的目录。
总的想法是,部分保持尽可能薄,首当其冲的工作是在mixin中完成的。幸运的是,罗盘提供了一个完整的抓包,以及我大量使用的抓包。
对于某些这种类型的文件结构可能很笨拙,但我发现它适用于我的目的。特别是一旦你得到一个好的mixin库和可交换的partials库。它可以轻松调整一些变量定义或将一个部分或混合替换为另一个部分或混合,以便快速进行全局更改。
明智的做法,假设你没有使用框架,可能是重新考虑你的决定,并利用框架。撇开玩笑,大型项目从CSS框架中获得的好处是巨大的。代码重用,明确的(如果你做对了)关注点的分离,烘焙连接/压缩,列表继续。是的,sass + rails 3.1将会为你回答这个问题。 – numbers1311407
@ numbers1311407感谢您的建议。我听到你说的是一个很好的经验法则,但是对于我在做的事情,我认为从一个框架开始就是矫枉过正的(第一遍样式很可能会在中期抛出无论如何)。我想它仍然来自您对sass/3.1的评论,最佳做法是什么。我认为你会推荐使用sass的嵌套功能进行组织,但是组织单元是控制器还是其他什么东西,文件结构是什么? – tks