Is there not equal ( !== ) statement in SCSS? - if-statement

How to add additional style if the value is passed? Or is there any way to do it?
#mixin link($color, $color-hover:false){
color: $color;
#if $color-hover !== false {
&:hover { color: $color-hover; }
}
}

Is != not working for you? I suppose you are trying with !==. i.e. a Double '=' instead of a single '=' prefixed with '!'. For SCSS, equality operators (==, !=) are supported for all types.

Related

How do I test if two lists are equal?

var a=[1,2,3]
var b=[1,2,3]
var c=[1,2,4]
System.print(a==b)
System.print(a==c)
How do I check if two lists are equal? I tried the equality operator == but this doesn't work; it prints false and false
There is no built-in operator or algorithm for list equality in wren - you must check the elements individually.
An example algorithm is available here: https://github.com/minirop/wren-helpers/blob/master/algorithms/algorithm.wren#L6-L17
static equal(list1, list2) {
if (list1.count != list2.count) {
return false
}
for (i in 0...list1.count) {
if (list1[i] != list2[i]) {
return false
}
}
return true
}
There is an open discussion on whether to add support for an equality list function: here https://github.com/wren-lang/wren/issues/606

Using "each loop variables" inside if statement in SASS

I am trying to generate a bunch of styles through an each loop in SASS. The styles should only be generated, if the variable the each loop is looking at right now is set.
I tried different variable "styles", e.g.: $use-#{$type}, but I'm kinda lost. Even tried to do it with a function, but it seems like functions can not access the variables of loops.
$typo: (t1, t2);
$use-t1: 1; $t1-color: black;
$use-t2: 1; $t2-color: black;
#each $type in $typo{
#if $#{use-$type} == 1{
.#{$type}{
color: $#{$type}-color;
}
}
}
I would expect the variables in the first round of the each loop to be:
$#{use-$type} -> $use-t1 -> 1
$#{$type}-color -> $t1-color -> black
But both throw "Expected identifier." or "Unknown variable", depending on how I try it.
You can't reference a variable using interpolation – in your case $#{$type}-color.
I would recommend you to use a map instead – like:
$map: (
t1: (use: 1, color: black),
t2: (use: 2, color: white)
);
#each $key, $value in $map {
#if map-get($value, use) == 1 {
.#{$key} { color: map-get($value, color); }
}
}
// output
.t1 { color: black; }
As a side note it's worth knowing Sass will not print properties with null values or classes without properties – why you can do the above without checking use
$map: (
t1: (color: black),
t2: (color: null) // no color => no prop => empty class => nothing printed
);
#each $key, $value in $map {
.#{$key} { color: map-get($value, color); }
}
// output
.t1 { color: black; }

Using #if statement inside a sass mixing outside the css selector brackets?

I'm having trouble getting an #if statement too work inside a #mixin.
This mixin is basically emulating an 'if less than or equal too' ie statement, as I'm using php to populate the body class.
// less than or equal too mixin
#mixin lte-ie($ver:'9') {
#if $ver >= '9' { .ie-9 &, }
#if $ver >= '8' { .ie-8 &, }
#if $ver >= '7' { .ie-7 &, }
.ie-6 &
{
#content;
}
}
But the mixin fails and I get this error when I try and run it.
Invalid CSS after "...f $ver >= '9' {": expected "}", was ".ie-9 &, }"
on line 9 at column 20
I've made a sassmeister but i've had to comment out the #mixin as you cannot save a broken gist.. but you can uncomment to test the above code :)
http://www.sassmeister.com/gist/7bbd084be7e12845866311a6ddbf0cdf
Any help would be much appreciated.
How about little extension for now, while you think of more efficient solution (on the other hand as it's a part of preprocessor, so you don't need to have it PERFECTLY optimized)
#mixin lte-ie($ver:9) {
#if $ver >= 9 {
.ie-9 &, .ie-6 & {
#content;
}
}
#if $ver >= 8 {
.ie-8 &, .ie-6 & {
#content;
}
}
#if $ver >= 7 {
.ie-7 &, .ie-6 & {
#content;
}
}
#if $ver > 7 {
.ie-6 & {
#content;
}
}
}
HEADER {
overflow: hidden;
#include lte-ie(9) {
position: relative;
}
}

Array extension in Swift 3

The following filter method will return true if the elements in the array of Bool is all true.
print([false, true].filter({!$0}).isEmpty) // yields false
print([true, true].filter({!$0}).isEmpty) // yields true
How do I create an extension method on the Array in Swift 3 that will allow me to represent it like this:
[false, true].allElementsTrue()
This should answer your question:
extension Collection where Iterator.Element == Bool {
var allElementsTrue: Bool {
return self.filter({!$0}).isEmpty
}
}
or
extension Collection where Iterator.Element == Bool {
func allElementsTrue() -> Bool {
return self.filter({!$0}).isEmpty
}
}
But I prefer using computed properties when there's no parameter to give.
Note: as an alternative you could also return !self.contains(false) to get the same result more efficiently (short-circuiting).

I want to write the ternary operator equivalent of the following if condition

String destinationFile = request.getParameter("destinationFile ");
if (destinationFile == null || "".equals(destinationFile))
response.sendRedirect("/astro/login/index.jsp?destinationFile =customerLogin.jsp");
I have written it as
String destinationFile = request.getParameter("destinationFile ");
response.sendRedirect((destinationFile==null || "".equals(destinationFile)) ? "/astro/login/index.jsp?destinationFile =customerLogin.jsp" : destinationFile);
the problem with terinary operator is that what should be placed after :
In if condition i have not mentioned any else. I have to verify the directory structure should be pre-pended to destinatedFile.
You simply cannot do that.
The ternary operator produces an expression which can be used e. g. as function argument.
That said, you could use the terary operator if you had an else branch which would send something as well.
So
if (a) {
response.sendRedirect(b);
} else {
response.sendRedirect(c);
}
could be rewritten as
response.sendRedirect(a ? b : c);
but if your else branch does something completely else (or nothing at all, as in your case), you are stuck with the normal if clause.
using ternary operator--->
var reult =
(request.getParameter("destinationFile").ToString() != String.Empty || request.getParameter("destinationFile") != null) ? response.sendRedirect("/astro/login/index.jsp?destinationFile =customerLogin.jsp") :
null;
You can't do that...
A terniary operator implicates a IF-ELSE condition, and you only have the IF part.
For instance, suppose you have this code:
String destinationFile = request.getParameter("destinationFile ");
if (!String.IsNullOrEmpty(destinationFile))
response.sendRedirect(destinationFile);
else
response.sendRedirect("/astro/login/index.jsp?destinationFile=customerLogin.jsp");
then you can change it to:
String destinationFile = request.getParameter("destinationFile ");
response.sendRedirect(!String.IsNullOrEmpty(destinationFile) ? destinationFile : "/astro/login/index.jsp?destinationFile=customerLogin.jsp"));