Cassette Sass compiling is generating nulls in CSS - sass

Until now we have had a post-build step that uses the Sass gem on the command line to generate our global.css.
I'm swapping over to Cassette, which uses Cassette.Sass, which uses SassAndCoffee, which apparently uses Sass 3.2.0 :-)
However when Cassette does the compiling, I get weird nulls in the generated css. Judging by how the page looks, this is invalid css and screwing up the design.
For eg:
.pure-container {
padding: 31px null;
padding: 1.714rem null;
padding-right: 0.9375%; }
I thought it may be down to a version difference of Sass (as we were using the sass gem for 3.2.8), but if I use the Sass gem version 3.2.0 from the command line, I get the same (valid) output as before I started using Cassette, without nulls:
.pure-container {
padding: 31px;
padding: 1.71429 rem;
padding-right: 0.9375%; }
So to summarize, Cassette.Sass using Sass 3.2.0 is not compiling my CSS in the same way as the Sass 3.2.0 Gem from the command line. What should I check?
I am not a front-end dev and not very familiar with scss, but if it's relevant, this is what our global.scss looks like:
// ----- 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";
And all those imported files exist and there are no SASS compiling exceptions.
The only mentions of 'null' that I can find is in _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 is otherwise quite awesome and I would love to use it, but this is quite a big barrier! Any thoughts appreciated, including where else I could post this in the hopes of an answer that might help! I am aware that there are other options for compiling Sass, and if I don't get much joy here I'll dump Cassette in favour of MS.Web.Optimization in combination with NSass, but I really want to get Cassette working if I can!
Thanks,
Mark.

null is coming from the default value of $importance.
Put that in an if statement and only apply it when the value is not the default null.
Thanks
#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);
}

I tried to build the solution above and i had errors. It seems that setting variables in an if statement keeps those variables private.
here is another solution with anotated comments
#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;
}
}
}

Related

Interpolation within #mixin-name for dynamic #include

I want to dynamicaly #include other #mixins in a #mixin.
But it seems like #include can't accept a variable as a #mixin-name,
is there any trick to do this?
Here is situation:
#mixin foo($_Value){
#include #{$_Value}
}
#mixin bar(){...}
#mixin baz(){...}
I want to be able to use #include A(B) or #include A(C), to include B or C additionally.
I have a second solution, but that's not the answer I am mainly looking for. I want to explicitly know, if there's any trick to use some sort of interpolation within #mixin-names.
#mixin foo($_Value...){
#if (length($_Value) > 0) {
#if (index($_Value, bar)) { #include bar }
#if (index($_Value, baz)) { #include baz }
}
}
#mixin bar(){...}
#mixin baz(){...}
Interpolation within #function or #mixin name is not supported.
You can't. As well as #functions #mixins don't support interpolation (yet).
This is indeed the best way to achieve what you want.
#mixin A($_Value...){
#if (length($_Value) > 0) {
#if (index($_Value, B)) { #include B }
#if (index($_Value, C)) { #include C }
}
}
I work with a trick to solve this situation.
#mixin foo($_Value...){
#if (length($_Value) > 0) {
#each $_ThisValue in $_Value{
#extend .#{$_ThisValue}
}
}
}
#mixin bar(){...}
#mixin baz(){...}
.bar{
#include bar;
}
.baz{
#include baz;
}
mixin with extend to do this trick
and it also can do with class or limited $_ThisValue

How to define grid margins for each breakpoint when semantically building a Foundation XY-grid

I want to build a grid using the mixins for XY-grid in Zurb Foundation 6.6, but I run into problems when I want to set the negative margins for the grid itself only on specific breakpoints.
Using the mixin xy-gutters() creates margins for each breakpoint, and I cannot choose to use margins just for some of them.
In the example below I want breakpoint(medium) to have a cell without margin gutters.
How is this meant to be done?
.hero {
&__container {
#include xy-grid-container;
}
&__grid {
#include xy-grid();
// This generates gutter margins for all breakpoints so I cannot choose to have without gutters for some breakpoints
#include xy-gutters(
$gutter-type: margin,
$gutter-position: right left,
$negative: true
);
}
&__cell {
#include xy-cell($size: 4, $gutter-type: margin);
#include breakpoint(medium) {
#include xy-cell($size: 6, $gutter-type: none);
}
#include breakpoint(large) {
#include xy-cell($size: 4, $gutter-type: margin);
}
}
}
I would use the
#include xy-cell-gutters($gutters, $gutter-type, $gutter-position, $breakpoint, $vertical);
mixin on your .cell
Set gutters to a px or rem value or Sass map;

Remove outside gutters in Neat 2

I've upgraded to Bourbon Neat v2 which includes the addition of gutters on the left and right side of the container grid.
In v1 I could use block-collapse in the span-columns mixin to eat the gutters either side of the element, however, in v2 this mixin has been removed. There is a grid-collapse function in v2 but that doesn't quite work as I expected. My current markup is as below (reduced for brevity):
.wrapper {
#include grid-container; // columns: 12, gutter: 1rem
#include grid-visual(lime);
}
.sidebar {
#include grid-columns(2 of 12);
}
.container {
#include grid-columns(10 of 12);
}
How do I remove the outer gutters, an collapse the gutter between column 2 & 3 so that my sidebar and container sit next to each other?
You were correct in looking at the grid-collapse mixin to take care of this.
To do a flush grid like the one you described, your markup would be:
.wrapper {
#include grid-container;
overflow-x: hidden;
}
.wrapper-inner {
#include grid-collapse;
}
.sidebar {
#include grid-column(2 of 12);
}
.container {
#include grid-column(10 of 12);
}
just expanding on the top answer, you need to also make sure to include grid-collapse within grid-media declarations when using multiple grids due to the fact that grid-collapse is based on your gutter values for each grid.
.wrapper {
#include grid-container;
}
.wrapper-inner {
#include grid-collapse;
#include grid-media($sm-neat-grid, $md-neat-grid, $lg-neat-grid) {
#include grid-collapse;
}
}
.sidebar {
#include grid-column(1 of 1);
#include grid-media($sm-neat-grid, $md-neat-grid) {
#include grid-column(3 of 12)
}
#include grid-media($lg-neat-grid) {
#include grid-column(5 of 15)
}
}
.container {
#include grid-column(1 of 1);
#include grid-media($sm-neat-grid, $md-neat-grid) {
#include grid-column(9 of 12)
}
#include grid-media($lg-neat-grid) {
#include grid-column(10 of 15)
}
}
by the way, my example is using a modified version of grid-media that allows declaring multiple grids that will share the same values but differ in gutter sizes:
// overrides bourbon-neat grid-media to include more than one grid
#mixin grid-media($grids...) {
#each $grid in $grids {
$_media: _retrieve-neat-setting($grid, media);
$_query: _neat-parse-media($_media);
#media #{$_query} {
$_default-neat-grid: $neat-grid;
$neat-grid: map-merge($neat-grid, $grid) !global;
#content;
$neat-grid: $_default-neat-grid !global;
}
}
}
can't for the life of me remember where I got it from but I've used it in all my projects

how to use variable for #include name inide #each loop SCSS

I want to replace this SCSS code with #each usage.
body{
#include us(){
#include define-breakpoint("us")
}
#include xs(){
#include define-breakpoint("xs")
}
#include sm(){
#include define-breakpoint("xs")
}
#include md(){
#include define-breakpoint("md")
}
#include lg(){
#include define-breakpoint("lg")
}
#include xl(){
#include define-breakpoint("xl")
}
}
When I use #each function compiler throws out an error - invalid css with #include #{$bp}(){...}
$list: us xs sm md lg xl;
#each $bp in $list{
body{
#include #{$bp}(){
#include define-breakpoint("#{$bp}")
}
}
}
Does everybody know how to handle this error?
Appreciate any help
The problem with this code is that interpolation can't be used to convert a variable to an identifier. The Sass compiler won't allow it. At the point where you interpolate $bp, the compiler expects an identifier. It will treat anything at that point as an identifier and not something that should be interpolated.
From your code it appears you've defined several mixins with #content passed within the block like so
#mixin us() { #content; }
#mixin sm() ( #contnet; }
which is why they are called like so
#include us(){
#include define-breakpoint("us");
}
You could refactor your code to make use of only one mixin since the only thing that's actually changing is the code in the block.
$list: us xs sm md lg xl;
#mixin screen-size() { #content; }
body {
#each $size in $list {
#include screen-size() {
#include define-breakpoint($size);
}
}
}
Another option would be to define the mixin to take a parameter instead and have the code within that block include the define-breakpoint mixin passing the parameter as an argument.
$list: us xs sm md lg xl;
#mixin screen-size($size) {
#include define-breakpoint($size);
}
body {
#each $size in $list {
#include screen-size($size);
}
}
UPDATED ANSWER
To achieve the added functionality specified in your code you can make the following adjustments to the previous answer
//list now takes media query also
$list: 'us' '(max-width: 519px)',
'xs' '(min-width: 520px) and (max-width: 767px)',
'sm' '(max-width: 768px)',
'md' '(min-width: 769px)',
'lg' '(min-width: 519px) and (max-width: 960px)',
'xl' '(min-width: 961px)';
//mixin takes media query as argument
#mixin screen-size($query) {
#media #{$query} {
#content;
}
}
body {
#each $map in $list {
#include screen-size( nth($map, 2) ) {
#include define-breakpoint( nth($map,1) );
}
}
}
Hope this solves your problem

Nested grid with pixel measures

I'm beggining with singularitygs (and grids systems), and of course I run into problems. Here it is.
I have this HTML markup:
<div id="wrapper">
<div id="main">
<div id="first-column">content</div>
<div id="second-column">content2</div>
</div>
</div>
I have setup this assymetric grid:
$grids : 97px 263px 263px 97px;
$gutters : 70px;
And this scss:
#wrapper {
#include background-grid;
width: 930px;
margin: 0 auto;
}
#main {
//#include background-grid;
#include grid-span(2, 2); //this element is spanned acros two columns in the middle
}
#first-column {
#include grid-span(1, 1); //should be spanned acros first column in #main
}
#second-column {
#include grid-span(1, 2); //this element should be spanned acros second column in #main
}
The question is how can I makes the inner divs be aware of the fact that #main should have only two columns (and one gutter). Instead it looks like that the #main inherit the default grid setup.
I've tryed lots of options like changing #main grid via #include layout. Or tell the columns to adapt to the correct context by adding #include grid-span(1, 1, 2); (the third number should tell the div that it's in the default grids context.
But with no avail.
I suspect that the problem is in my px definition of the default grid. Because the inner divs gets lots of time only 1.356% wide, and this look kind of suscpicious to me. Am I right? What can I do?
Thanks for any suggestion.
EDIT:
I try add the exact px dimension and in combination with adding the nested context its looks like its supossed, but I think thats its not how it should work??
#block-formblock-contact-form {
#include grid-span(1, 2, 2);
width: 263px;
}
#block-system-main {
#include grid-span(1, 1, 2);
width: 263px;
}
The issue that you're running in to is that, while you've changed your grid to a two column symmetric grid, you haven't changed your gutters in proportion. What Singularity is seeing with how you've currently set it up is that you've got a 2 column grid, each column is width 1, and a gutter of width 70. Now, there are two ways you can solve this. The first is to explicitly state what your sub grid is in relation to the main grid. That would look like the following:
#first-column {
#include grid-span(1, 1, 263px 263px);
}
#second-column {
#include grid-span(1, 2, 263px 263px);
}
or, with #include layout
#include layout(263px 263px) {
#first-column {
#include grid-span(1, 1);
}
#second-column {
#include grid-span(1, 2);
}
}
The second option is to set up the correct ratio for columns to gutters when using sub grids. Singularity works best when it's dealing with small ratios instead of large "absolute" values.
#include layout(2, (70px / 263px)) {
#first-column {
#include grid-span(1, 1);
}
#second-column {
#include grid-span(1, 2);
}
}
Hope this helps!

Resources