lessphp icon indicating copy to clipboard operation
lessphp copied to clipboard

Namespace Mixins (#gradient > .horizontal) from twitter Bootstrap preboot not compiled

Open emkayy opened this issue 15 years ago • 15 comments

Hi there,

I'm using twitters Bootstrap (http://twitter.github.com/bootstrap/) and everything seems to work fine. Just the parametric mixins #font and #gradient won't work. They are included in the preboot.less file and look like that (shortend version):

#font {
  .shorthand(@weight: normal, @size: 14px, @lineHeight: 20px) {
    font-size: @size;
    font-weight: @weight;
    line-height: @lineHeight;
  }
  .sans-serif(@weight: normal, @size: 14px, @lineHeight: 20px) {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: @size;
    font-weight: @weight;
    line-height: @lineHeight;
  }
}

#gradient {
  .horizontal (@startColor: #555, @endColor: #333) {
    background-color: @endColor;
    background-repeat: repeat-x;
    background-image: -khtml-gradient(linear, left top, right top, from(@startColor), to(@endColor)); // Konqueror
    background-image: -moz-linear-gradient(left, @startColor, @endColor); // FF 3.6+
    background-image: -ms-linear-gradient(left, @startColor, @endColor); // IE10
    background-image: -webkit-gradient(linear, left top, right top, color-stop(0%, @startColor), color-stop(100%, @endColor)); // Safari 4+, Chrome 2+
    background-image: -webkit-linear-gradient(left, @startColor, @endColor); // Safari 5.1+, Chrome 10+
    background-image: -o-linear-gradient(left, @startColor, @endColor); // Opera 11.10
    background-image: linear-gradient(left, @startColor, @endColor); // Le standard
  }
  .vertical (@startColor: #555, @endColor: #333) {
    background-color: @endColor;
    background-repeat: repeat-x;
    background-image: -khtml-gradient(linear, left top, left bottom, from(@startColor), to(@endColor)); // Konqueror
    background-image: -moz-linear-gradient(@startColor, @endColor); // FF 3.6+
    background-image: -ms-linear-gradient(@startColor, @endColor); // IE10
    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, @startColor), color-stop(100%, @endColor)); // Safari 4+, Chrome 2+
    background-image: -webkit-linear-gradient(@startColor, @endColor); // Safari 5.1+, Chrome 10+
    background-image: -o-linear-gradient(@startColor, @endColor); // Opera 11.10
    background-image: linear-gradient(@startColor, @endColor); // The standard
  }
}

There are no errors when compiling but the rules are included in the stylesheet like that:

#font .shorthand(@weight: normal, #font $size: 14px, #font $lineHeight: 20px) {
  font-size:;
  font-weight:;
  line-height:;
}

but not when I'm using them like that:

#gradient > .vertical(lighten(@blue, 20%), @blue);
#font > .shorthand(bold, 15px, 1.2);

I don't understand why though since this works on your example page (http://leafo.net/lessphp/#demo):

#bundle {
  .button (@color: #000) {
    border: 1px solid @color;
    background-color: grey;
  }
}
#header a {
  color: orange;
  #bundle > .button(#ccc);
}

emkayy avatar Sep 06 '11 12:09 emkayy

change #gradient to @gradient and the commas between parameters to semicolon. It works fine.

shazdeh avatar Sep 18 '11 08:09 shazdeh

Thank you very much! I'll try that!

Maybe it would still be good to "fix" this so you can use your less files without having to change parts of a framework like Bootstrap.

emkayy avatar Sep 18 '11 11:09 emkayy

OK, much better. However it still doesn't work perfectly. Button gradients are just left out and so buttons are just gray.

And - if I change the syntax as you suggested, I get syntax errors when using less.js

emkayy avatar Sep 23 '11 10:09 emkayy

The lessjs syntax and lessphp syntax is different. Go with one! I changed Bootstrap to work with lessphp and it successfully compiled. The compile result is the same file as bootstrap-1.3.0-min.css. You just have to change the syntax to be compatible with lessphp. (or change nothing and use less.js)

shazdeh avatar Sep 26 '11 11:09 shazdeh

I'm having the same problem. I have a variables file defined that contains font stacks:

@serif:               "Cambria", Georgia, serif;
@sans:                Helvetica, Arial, sans-serif;

@font {
  .h1(@lineHeight: 36px) {
    font-family:      @sans;
    font-size:        33px;
    font-weight:      normal;
    line-height:      @lineHeight;
  }
  .h2(@stack: @sans; @color: @fidelityGreen; @lineHeight: 27px) {
    color:            @color;
    font-family:      @stack;
    font-size:        24px;
    font-weight:      bold;
    line-height:      @lineHeight;
  }
  .small(@stack: @serif; @weight: normal; @transform: none; @lineHeight: 15px) {
    font-family:      @stack;
    font-size:        12px;
    font-weight:      @weight;
    line-height:      @lineHeight;
    text-transform:   @transform;
  }
}

...etc. However, they're ignored by the compiler when used like this:

@font > .small();

With commas separating values, it ignores them. With semicolons (as above) it throws a fatal error:

lessc fatal error:
parse error: failed at `.h2(@stack: @sans; @color: @fidelityGreen; @lineHeight: 27px) {` css/lib/variables.less on line 88

Using lessphp v0.3.0

What am I doing wrong?

adamnel avatar Oct 21 '11 14:10 adamnel

It compiled fine using v0.2.1. I don't know about 0.3.0 but 0.2 is the stable version, use that instead.

shazdeh avatar Oct 23 '11 09:10 shazdeh

shazdeh:

I changed Bootstrap to work with lessphp and it successfully compiled. The compile result is the same file as bootstrap-1.3.0-min.css. You just have to change the syntax to be compatible with lessphp. (or change nothing and use less.js)

Could you share the compatible bootstrap less files? Or what exactly syntax should be changed? I'm using twitter-bootstrap-v1.4.0 and it's already using semicolons.

I have a problem with clearfix. This less code from bootstrap:

.clearfix() {
  zoom: 1;
  &:before,
  &:after {
    display: table;
    content: "";
    zoom: 1;
  }
  &:after {
    clear: both;
  }

.fixed-container() {
  width: @siteWidth;
  margin-left: auto;
  margin-right: auto;
  .clearfix();
}

}
.container {
  .fixed-container();
}

Should create:

.container:after {
    clear: both;
}

.container:before, .container:after {
    content: "";
    display: table;
}

.container:before, .container:after {
    content: "";
    display: table;
}

.container {
    margin-left: auto;
    margin-right: auto;
    width: 940px;
}

But it's actually create only this:

.container {
    margin-left: auto;
    margin-right: auto;
    width: 940px;
}

dmitriy-01 avatar Nov 04 '11 19:11 dmitriy-01

Looks like the problem with something else... :( If I remove all other code from bootstrap less files it works fine

F**k - Took me 1 hour to find a problem: Removed this code from variables.less and it started parsing fine

// More variables coming soon:
// - @basefont to @baseFontSize
// - @baseline to @baseLineHeight
// - @baseFontFamily
// - @primaryButtonColor
// - anything else? File an issue on GitHub

dmitriy-01 avatar Nov 04 '11 19:11 dmitriy-01

Just in case, here I keep a repo of a lessphp compatible bootstrap styles: https://github.com/shazdeh/Bootstrap-for-LESSPHP. (It's still 1.3.0 but I'll update it)

shazdeh avatar Nov 05 '11 21:11 shazdeh

Sorry for the long delay on getting this to work. I just pushed 0.3.0 to master. It works with twitter bootstrap now. I changed lessphp syntax to match that of lessjs.

I enhanced the lessphp documentation a bunch too, check it out: http://leafo.net/lessphp/docs/

leafo avatar Nov 28 '11 05:11 leafo

Following the mixins notation documented in the new Twitter Bootstrap 2, I fail at making it working with lessphp 0.3.2.

Following the previous examples, I tried the followings in my code:

background: @translucent .background(#221504, 0.97);
background: @translucent > .background(#221504, 0.97);
background: #translucent .background(#221504, 0.97);
background: #translucent > .background(#221504, 0.97);
background: .#translucent .background(#221504, 0.97);
background: .#translucent > .background(#221504, 0.97);

Any hint?

thom4parisot avatar Feb 17 '12 20:02 thom4parisot

Remove the "background:" in your CSS. This is working for me: body { #translucent > .background(#221504, .5); }

shazdeh avatar Feb 17 '12 22:02 shazdeh

Shame on me, you're totally right @shazdeh ! Thanks :-)

thom4parisot avatar Feb 18 '12 15:02 thom4parisot

I am using v0.3.4-2 and I am still having this problem.

#translucent > .background( [anything], [anything] );

Doesn't work. It's replaced with nothing.

aaronldunlap avatar May 15 '12 21:05 aaronldunlap

Can't reproduce this @aaronldunlap Going to close this issue because it's unrelated. Open an new one if you are still having trouble.

leafo avatar May 20 '12 21:05 leafo