Cassette Sass编译在CSS中生成空值

时间:2013-11-15 12:11:05

标签: sass cassette

到目前为止,我们已经有一个构建后的步骤,它在命令行上使用Sass gem生成我们的global.css。

我正在交换到Cassette,它使用Cassette.Sass,它使用SassAndCoffee,显然使用Sass 3.2.0: - )

然而,当Cassette进行编译时,我在生成的css中得到了奇怪的空值。根据页面的外观来判断,这是无效的CSS并搞砸了设计。

例如:

.pure-container {
padding: 31px null;
padding: 1.714rem null;
padding-right: 0.9375%; }

我认为可能是Sass的版本差异(因为我们使用3.2.8的sass gem),但如果我从命令行使用Sass gem版本3.2.0,我会得到相同的(有效的输出,就像我开始使用Cassette之前一样,没有空值:

.pure-container {
padding: 31px;
padding: 1.71429 rem;
padding-right: 0.9375%; }

总而言之,Cassette.Sass使用Sass 3.2.0并没有像命令行中的Sass 3.2.0 Gem那样编译我的CSS。我该怎么检查?

我不是一个前端开发人员,对scss不太熟悉,但如果相关,那就是我们的global.scss看起来像:

// ----- SCSS Helpers -----
@import "imports/_mixins.scss";
@import "imports/_variables.scss";

// ----- Pure Grid -----
@import "imports/_extend-pure.scss";

// ----- Theme -----
@import "imports/_typography.scss";
@import "imports/_helpers.scss";
@import "imports/_buttons.scss";
@import "imports/_forms.scss";
@import "imports/_modules.scss";


// ----- Media Queries -----
@import "imports/_media-phone.scss";
@import "imports/_media-tablet-query.scss";
@import "imports/_media-desktop-query.scss";

所有这些导入的文件都存在,并且没有SASS编译异常。

我能找到的唯一提到'null'的是_mixins.scss:

@mixin size($property: null, $units: 4, $importance: null, $mixin: null) {
  // This mixin will calculate the rem values defined by design (6px's in mobile and scaled up for desktop)
  // Because IE8 and below don't support rem, we insert the px equivalent for the desktop sizes just before.
  $pixel-size: round(((6*$units)*((1/$font-size-mobile)*$font-size-desktop))) + px $importance;
  $rem-size: ((1/$font-size-mobile)*(6*$units)) + rem $importance;
  @if $mixin == min-height {
    @include min-height($pixel-size);
    @include min-height($rem-size);
  }
  @else if $mixin == max-height {
    @include max-height($pixel-size);
    @include max-height($rem-size);
  }
  @else {
    #{$property}: $pixel-size; // This number is rounded to the nearest whole number to avoid issues with IE7
    #{$property}: $rem-size;
  }
  // EXAMPLE OF HOW TO USE
  // @include size(line-height, 4, !important); <-- important is optional
  // EXAMPLE OF HOW TO USE 2
  // @include size($mixin: min-height, $units: 4);
}

Cassette非常棒,我很乐意使用它,但这是一个很大的障碍!任何想法都会受到赞赏,包括我可以在哪里发布这个想法,希望得到一个可能有帮助的答案!我知道还有其他选项来编译Sass,如果我没有在这里获得很多快乐,我会转发Cassette,转而选择MS.Web.Optimization和NSass,但我真的想让Cassette工作,如果我可以!

谢谢, 标记

2 个答案:

答案 0 :(得分:0)

null来自$ important的默认值。

将它放在if语句中,只在值不是默认值时才应用它。

由于

@mixin size($property: null, $units: 4, $importance: null, $mixin: null) {
  // This mixin will calculate the rem values defined by design (6px's in mobile and scaled up for desktop)
  // Because IE8 and below don't support rem, we insert the px equivalent for the desktop sizes just before.
  $pixel-val: round(((6*$units)*((1/$font-size-mobile)*$font-size-desktop)));
  $rem-val: ((1/$font-size-mobile)*(6*$units));
  @if $importance == null {
      $pixel-size: $pixel-val + px;
      $rem-size: $rem-val + rem;
  } @else {
      $pixel-size: $pixel-val + px $importance;
      $rem-size: $rem-val + rem $importance;
  }

  @if $mixin == min-height {
    @include min-height($pixel-size);
    @include min-height($rem-size);
  } @else if $mixin == max-height {
    @include max-height($pixel-size);
    @include max-height($rem-size);
  } @else {
    #{$property}: $pixel-size; // This number is rounded to the nearest whole number to avoid issues with IE7
    #{$property}: $rem-size;
  }
  // EXAMPLE OF HOW TO USE
  // @include size(line-height, 4, !important); <-- important is optional
  // EXAMPLE OF HOW TO USE 2
  // @include size($mixin: min-height, $units: 4);
}

答案 1 :(得分:0)

我尝试构建上面的解决方案,但我遇到了错误。似乎在if语句中设置变量会使这些变量保持私有。

这是另一个带有anotated评论的解决方案

@mixin size($property: null, $units: 4, $importance: false, $mixin: null) { // change default value of importance to false
  $pixel-size: round(((6*$units)*((1/$font-size-mobile)*$font-size-desktop))) + px;
  $rem-size: ((1/$font-size-mobile)*(6*$units)) + rem; // remove importance from here
  @if $mixin == min-height {
    @include min-height($pixel-size);
    @include min-height($rem-size);
  }
  @else if $mixin == max-height {
    @include max-height($pixel-size);
    @include max-height($rem-size);
  }
  @else {
    @if $importance { // do the test here
        #{$property}: $pixel-size $importance;
        #{$property}: $rem-size $importance;
    } @else {
        #{$property}: $pixel-size;
        #{$property}: $rem-size;        
    }
  }
}