2

How do I convert the following mixin written in LESS to SASS?

.box_gradient (@from, @to) when (iscolor(@from)) and (iscolor(@to)) {
  background-image: -webkit-gradient(linear, left top, left bottom, from(@from), to(@to)); /* Saf4+, Chrome */
  background-image: -webkit-linear-gradient(top, @from, @to); /* Chrome 10+, Saf5.1+, iOS 5+ */
  background-image:    -moz-linear-gradient(top, @from, @to); /* FF3.6 */
  background-image:     -ms-linear-gradient(top, @from, @to); /* IE10 */
  background-image:      -o-linear-gradient(top, @from, @to); /* Opera 11.10+ */
  background-image:         linear-gradient(to bottom, @from, @to);
}
Arkhitech
  • 475
  • 3
  • 11
  • 1
    SO is not a code conversion service (see: http://meta.stackoverflow.com/questions/296119/is-how-do-i-convert-code-from-this-languange-to-this-language-too-broad). Have you tried anything, anything at all? – cimmanon Oct 25 '15 at 11:08
  • 1
    If the question is about guarded namespaces, the source doesn't show it. – Mr Lister Oct 25 '15 at 11:33
  • 1
    @cimmanon all I was looking for was validation that whether converting something like this was even possible or not. A simple answer such as 'this can be accomplished' using conditionals with reference to SCSS would have been a better answer rather than raising flags over if its an appropriate question or not. – Arkhitech Oct 25 '15 at 18:49
  • 1
    You made zero effort here, that's the point I am trying to get across to you. You didn't even think about what guards are or how one might do something in a language that doesn't have guards. It's purely phrased as "translate some code for me", and we don't do that here. – cimmanon Oct 25 '15 at 18:57

1 Answers1

2

This is accomplished in SASS using conditionals:

.box_gradient (@from, @to) {
  @if (iscolor(@from) and iscolor(@to)) {
    background-image: -webkit-gradient(linear, left top, left bottom, from(@from),   to(@to)); /* Saf4+, Chrome */
    background-image: -webkit-linear-gradient(top, @from, @to); /* Chrome 10+,   Saf5.1+, iOS 5+ */
    background-image:    -moz-linear-gradient(top, @from, @to); /* FF3.6 */
    background-image:     -ms-linear-gradient(top, @from, @to); /* IE10 */
    background-image:      -o-linear-gradient(top, @from, @to); /* Opera 11.10+ */
    background-image:         linear-gradient(to bottom, @from, @to);
  }
}
Arkhitech
  • 475
  • 3
  • 11