Ejemplo n.º 1
0
function smarty_block_less($params, $content, Smarty_Internal_Template $template, $open)
{
    /** @var CM_Frontend_Render $render */
    $render = $template->smarty->getTemplateVars('render');
    $assetCss = new CM_Asset_Css($render);
    $assetCss->addVariables();
    $assetCss->add($content);
    return $assetCss->get();
}
Ejemplo n.º 2
0
function smarty_function_lessVariable(array $params, Smarty_Internal_Template $template)
{
    /** @var CM_Frontend_Render $render */
    $render = $template->smarty->getTemplateVars('render');
    $variableName = (string) $params['name'];
    $assetCss = new CM_Asset_Css($render);
    $assetCss->addVariables();
    $assetCss->add('foo:@' . $variableName);
    $css = $assetCss->get(true);
    if (!preg_match('/^foo:(.+);$/', $css, $matches)) {
        throw new CM_Exception_Invalid('Cannot detect variable `' . $variableName . '` from CSS `' . $css . '`.');
    }
    return $matches[1];
}
Ejemplo n.º 3
0
    public function testAdd()
    {
        $render = new CM_Frontend_Render();
        $css = new CM_Asset_Css($render, 'font-size: 12;', ['prefix' => '#foo']);
        $css1 = <<<'EOD'
.test:visible {
	color: black;
	height:300px;
}
EOD;
        $css->add($css1, '.bar');
        $css->add('color: green;');
        $expected = <<<'EOD'
#foo {
  font-size: 12;
  color: green;
}
#foo .bar .test:visible {
  color: black;
  height: 300px;
}
EOD;
        $this->assertSame(trim($expected), $css->get());
    }
Ejemplo n.º 4
0
 /**
  * @param $variableName
  * @return string
  * @throws CM_Exception_Invalid
  */
 public function getLessVariable($variableName)
 {
     $variableName = (string) $variableName;
     $cache = new CM_Cache_Local();
     return $cache->get($cache->key(__METHOD__, $variableName), function () use($variableName) {
         $assetCss = new CM_Asset_Css($this);
         $assetCss->addVariables();
         $assetCss->add('foo:@' . $variableName);
         $css = $assetCss->get(true);
         if (!preg_match('/^foo:(.+);$/', $css, $matches)) {
             throw new CM_Exception_Invalid('Cannot detect variable from CSS.', null, ['variableName' => $variableName, 'css' => $css]);
         }
         return (string) $matches[1];
     });
 }