Gulp-sass not compiling Foundation 6 properly - gulp-sass

I'm having some issues with Foundation 6 files, for some reasons they are just not including all of the sass components. I tried to use Foundation 5 and it worked fine.
Here is my gulp task:
gulp.task('styles', ['clearCss'], function() {
gulp.src('assets/sass/app.scss')
.pipe(plumber(plumberErrorHandler))
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed'
})
.on('error', notify.onError(function(error) {
return "Error: " + error.message;
}))
)
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie >= 9']
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./assets/dist/css'))
.pipe(browserSync.stream({match: '**/*.css'}))
.pipe(notify({
message: "Styles task complete!"
}));
});
And here is my app.scss:
// Import Foundation
#import "../components/foundation/scss/foundation";
It works with my own sass files, but completely ignoring foundation parts.

You should import a file foundation-sites.scss, not scss/foundation.scss. File foundation.scss has only a #mixin foundation-everything which is included in foundation-sites.scss:
#include foundation-everything;
However foundation-sites.scss has an error in 6.0.4, this is my log:
Error in plugin 'sass'
Message:
bower_components\foundation-sites\foundation-sites.scss
Error: File to import not found or unreadable: foundation
Parent style sheet: stdin
on line 1 of stdin
>> #import 'foundation';
The fix:
Change line nr 1 in file foundation-sites.scss from
#import 'foundation'; to #import 'scss/foundation';

The Correct Approach for foundation 6 :
if you Look at the foundation.scss file (https://github.com/zurb/foundation-sites-6/blob/develop/scss/foundation.scss)
Yes it imports all the required components, but since they are now mixins and not regular sass you have to explictly tell that you want to make use of them, by simply calling the mixin.
app.scss
#import 'foundation';
#include foundation-everything; // Very important if you want to include all of foundation css to your complied css
gulpfile.js
gulp.task('scss', function() {
return gulp.src('app.scss')
.pipe(plugins.sass(
{includePaths: ['./node_modules/foundation-sites/scss']}
))
.pipe(gulp.dest('css'))
.pipe(plugins.notify({ message: 'Sass task complete' }));
});

I have gulp-sass working with foundation-sites (Foundation 6):
My main.scss file:
#charset 'UTF-8';
/**
* Main SCSS
* Version 1.0.0
* built with foundation-sites
*/
// import custom settings
#import 'settings';
// import foundation sass
#import "../bower_components/foundation-sites/scss/foundation";
/* either include all foundation components… //*/
#include foundation-everything;
/* or include specific foundation components //*/
// #include foundation-global-styles;
/* include either foundation-grid… //*/
// #include foundation-grid;
/* or foundation-flex-grid (but don't include both) //*/
// #include foundation-flex-grid;
// #include foundation-typography;
// #include foundation-button;
// #include foundation-forms;
// #include foundation-visibility-classes;
// #include foundation-float-classes;
// #include foundation-accordion;
// #include foundation-accordion-menu;
// #include foundation-badge;
// #include foundation-breadcrumbs;
// #include foundation-button-group;
// #include foundation-callout;
// #include foundation-close-button;
// #include foundation-drilldown-menu;
// #include foundation-dropdown;
// #include foundation-dropdown-menu;
// #include foundation-flex-video;
// #include foundation-label;
// #include foundation-media-object;
// #include foundation-menu;
// #include foundation-off-canvas;
// #include foundation-orbit;
// #include foundation-pagination;
// #include foundation-progress-bar;
// #include foundation-slider;
// #include foundation-sticky;
// #include foundation-reveal;
// #include foundation-switch;
// #include foundation-table;
// #include foundation-tabs;
// #include foundation-thumbnail;
// #include foundation-title-bar;
// #include foundation-tooltip;
// #include foundation-top-bar;
If you don't want to load all the foundation componenents, you don't have to. Instead of #include foundation-everything, simply #include the specific components you need.

What I did with my gulp + bower setup:
/src/scss/app.scss
#import 'settings';
#import '../../bower_components/foundation-sites/scss/foundation';
#include foundation-everything;
settings.scss contained my foundation variable overrides, custom CSS, etc. Trick for me was to #import full file path then #include the mixin.
Though it is excessive to include everything, I prefer to develop with no hassles then use uncss to clean out dead CSS code.

I had to edit the foundation-sites' bower.json file to change the main.scss foundation #import.
From:
"main": [
"scss/foundation.scss",
"js/foundation.js"
],
To:
"main": [
"foundation-sites.scss",
"js/foundation.js"
],
As well as the foundation-sites.scss file.
#import 'foundation';
To:
#import 'scss/foundation.scss';
I don't think this is the best route to take but my sass, grunt and bower knowledge is limited.

If you have a gulpfile, include 'node_modules/foundation-sites/scss' and then in your app.scss or style.scss do the following:
#import "settings/settings";
#import "foundation";
#include foundation-everything;
That way you'll import EVERYTHING Foundation has to offer. Of course, everything might be a tad overkill, but that's an optional choice.
Example of gulp task:
gulp.task('css', function() {
return gulp.src(assets + 'scss/*.scss')
.pipe(sass({
includePaths: 'node_modules/foundation-sites/scss',
errLogToConsole: true
}))
.on('error', handleError)
.pipe(prefixer())
.pipe(gulp.dest(themeDir))
.pipe(browserSync.stream());
});
Of course, handleError needs to be defined. In my case, it's defined as:
var handleError = function(err) {
if (err) {
var args = Array.prototype.slice.call(arguments);
console.log(args);
this.emit('end');
}
};
Don't forget to include the required dependencies.

Related

cgo on macOS - unknown type name NSString

In a go code i have following code:
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -L./ ${SRCDIR}/test.dylib -framework Foundation
#include "./test.h"
#include <stdlib.h>
#include <stdio.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSString.h>
*/
import "C"
test.h has a struct with NSString
On building the go code it shows
error: unknown type name 'NSString' NSString nspath,
can someone guide what's wrong here since i have included appropriate objective C libraries and headers.
Not running OSX/iOS, but looking at github, it looks like at least some developers wrap objective-c code in the cgo preamble inside a typical C function.
This looks like a particularly good example:
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/NSBundle.h>
#import <Foundation/NSString.h>
#include <stdlib.h>
#include <string.h>
const char *assets_zip_path() {
NSString *path = [[NSBundle mainBundle] pathForResource: #"aaaaxy" ofType: #"dat"];
const char *data = [path UTF8String];
if (data == NULL) {
return NULL;
}
return strdup(data);
}
*/
import "C"
func openAssetsZip() (*os.File, error) {
pathCStr := C.assets_zip_path()
...
You also may already find the bindings you need in the go/mobile package.

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

CGO undefined reference in included files

Wraping up OpenJtalk in Go, files are successfully included and types are referenced without an issue, but functions trigger an undefined reference error.
jtalk.go:
package main
// #cgo CFLAGS: -I/home/vagrant/open_jtalk/njd [...etc]
/*
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
// Main headers
#include "mecab.h"
#include "njd.h"
#include "jpcommon.h"
#include "HTS_engine.h"
// Sub headers
#include "text2mecab.h"
#include "mecab2njd.h"
#include "njd_set_pronunciation.h"
#include "njd_set_digit.h"
#include "njd_set_accent_phrase.h"
#include "njd_set_accent_type.h"
#include "njd_set_unvoiced_vowel.h"
#include "njd_set_long_vowel.h"
#include "njd2jpcommon.h"
*/
import "C"
type Open_JTalk struct {
mecab C.Mecab each of these struct references are fine
njd C.NJD
jpcommon C.JPCommon
engine C.HTS_Engine
}
func (open_jtalk *Open_JTalk) Open_JTalk_initialize() {
C.Mecab_initialize(&open_jtalk.mecab) // when any function is called the error happens
C.NJD_initialize(&open_jtalk.njd)
C.JPCommon_initialize(&open_jtalk.jpcommon)
C.HTS_Engine_initialize(&open_jtalk.engine)
}
func main() {
}
And the weird part is that those same functions are declared right after the types:
mecab.h
// line 1584
typedef struct _Mecab{
char **feature;
int size;
mecab_t *mecab;
} Mecab;
BOOL Mecab_initialize(Mecab *m);
Project webpage: http://open-jtalk.sourceforge.net/
You need to add cgo linker options (LDFLAGS) with the path to and the name of your library. e.g.
// #cgo CFLAGS: -Iyour-include-path
// #cgo LDFLAGS: -Lyour-library-path -lyour-library-name-minus-the-lib-part

Cassette Sass compiling is generating nulls in CSS

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;
}
}
}

Resources