rails + compass: advantages vs using haml + blueprint directly

后端 未结 4 1252
死守一世寂寞
死守一世寂寞 2021-02-02 00:54

I\'ve got some experience using haml (+sass) on rails projects. I recently started using them with blueprintcss - the only thing I did was transform blueprint.css into a sass fi

4条回答
  •  悲&欢浪女
    2021-02-02 01:29

    The ideal goal is separation of style and content: it's not always possible 100%, but it can be done reasonably well by using semantic markup. Blueprint and other CSS frameworks utterly fail at this.

    The original idea behind Compass was to avoid polluting HTML with the visual markup that Blueprint generates: if you're writing class="column-4" in your markup, then you might as well put style="width:160px" in there instead. Semantically it's the same meaning, and the same amount of repetition to maintain.

    Compass turns a Blueprint class like .column-4 into a mixin which you can apply to a meaningful selector:

    #sidebar
      +column(4)
    

    This way, you only need to maintain it in the stylesheet, not across a number of templates and HTML files.

    Compass is project-aware. It will handle compiling your whole tree of stylesheets, even automatically on save when you run compass watch.

    There are some very helpful functions provided by compass, for example:

    image_url is a configurable function that can handle relative or absolute paths or even set up rotating asset hosts if you need to.

    The CSS3 module takes care of all the browser-specific style rules for rounded corners, shadows, etc.

    General utilities provide helpers for the stuff you do all the time, but with less repetition (especially for the cross-browser issues). These are some basic ones I use a lot:

    • +clearfix and +pie-clearfix (cross-browser clearing methods)
    • +float ensures you don't forget display:inline in front of it for IE... (if the time comes to drop the old IEs, it's one single change.)
    • +replace-text hides text and positions an image replacement background.
    • +hover-link adds the :hover underline rule to a base link style

    You can check these out on the new docs site for Compass.

    Then, Compass provides the facilities for a number of other style frameworks in addition to the built-in Blueprint. Do check out Susy for example, which is a Sass-native layout framework, not just a CSS port. It specializes in flexible and fluid grids.

提交回复
热议问题