phpsass icon indicating copy to clipboard operation
phpsass copied to clipboard

Mixin parameters inside @font-face

Open ghost opened this issue 12 years ago • 2 comments

This mixin returns the same output for every call despite passed arguments are different

@mixin webfont($fontname){
    @font-face{
        font-family: $fontname;
    }
}
@include webfont('first-fontname');
@include webfont('second-fontname');

Renders as:

@font-face {  font-family: 'first-fontname';}
@font-face {  font-family: 'first-fontname';}

ghost avatar Dec 27 '12 19:12 ghost

I really don't now what is wrong with scss2Token function but it returns null in the second case

jmverges avatar Dec 29 '12 12:12 jmverges

Hi, I ran into the same problem and found a possible fix. The problem lay in SassDirectiveNode which, when parsed, modified itself instead of returning a clone. If the directive was used more than once (i.e. when in a mixin), then the second time it was used it was already compiled with the first context.

I don't know Git, so I'll just paste the diff.

tree/SassDirectiveNode.php

@@ -44,11 +44,12 @@
    */
   public function parse($context)
   {
-    $this->token->source = self::interpolate_nonstrict($this->token->source, $context);
+    $node = clone $this;
+    $node->token->source = self::interpolate_nonstrict($this->token->source, $context);

-    $this->children = $this->parseChildren($context);
+    $node->children = $this->parseChildren($context);

-    return array($this);
+    return array($node);
   }

   /**
@@ -66,6 +67,16 @@
   }

   /**
+   * @see parse
+   */
+  public function __clone()
+  {
+    parent::__clone();
+    $this->token = clone $this->token;
+  }
+  
+  /**
    * Returns a value indicating if the token represents this type of node.
    * @param object $token token
    * @return boolean true if the token represents this type of node, false if not

gabrielfin avatar Apr 26 '14 20:04 gabrielfin