phpsass
phpsass copied to clipboard
font-size/line-height property doesn't compile right
Note that I've already posted this same response in the following issue but since this is another bug, I think it needs a seperate issue.
p {
$font-size: 12px;
$line-height: 30px;
font: #{$font-size}/#{$line-height};
}
This example is right off of the SASS reference page. Search for:
"If you want to use variables along with a plain CSS /, you can use #{} to insert them."
and you'll find it.
Where it says:
is compiled to:
p {
font: 12px/30px;
}
Which is obviously not the case, since trying it in the SASS command line and the /try of PHPSASS, I get a positive result in the command line and a negative result online.
What I get when running it in the SASS command line from my PC:
p {
$font-size: 12px;
$line-height: 30px;
font: #{$font-size}/#{$line-height};
}
Is compiled via sass --watch sass:compiled to:
p {
font: 12px/30px; }
Online the editor itself returns:
p {
font: 0px;
}
And the ruby console returns nothing.
Clearly a bug?
This is what I did, I don't know if its the right fix, but it seems to be working for me:
In SassNumber.php, line 26 is the regex that determines whether to treat something as a number, I added a rule to ignore something that would match [number]px/[number]px like so:
const MATCH = '/^(?!\d+px/)((?:-)?(?:\d_.)?\d+)(([a-z%]+)(\s_[*/]\s_[a-z%]+)_)?/i';
And it seems to just pass through the value as a string which creates the proper output.
Again, I don't know if this is the RIGHT solution as I am not an expert on phpsass and have only been working with it for a couple of days. Also, this does not take into account other units like em, pt, pc etc...
thomp538: you can test changes to the compiler aganist the test suite by running test.php in a browser.
Unfortunately in this case, the change breaks the compiler quite heavily.
I suspect the method of solving this would be to add some specific code for any property named "font", but first choice is to examine how the ruby compiler solves it.
Would it not be easier to simply have #{} style variables inserted into the stylesheet after the math has been done? Because that seems to me to be the reason #{} exists in the first place. (Not 100% on this, as I've barely needed variables so far, let alone needed them in explicit var/var style often enough to get familiar with them, so I could be completely wrong)