Esempio 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();
}
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];
}
Esempio n. 3
0
    public function testCompress()
    {
        $render = new CM_Frontend_Render();
        $css = <<<'EOD'
.foo {
	color: red;
}
EOD;
        $expected = '.foo{color:red;}';
        $css = new CM_Asset_Css($render, $css, ['autoprefixerBrowsers' => 'Chrome 30']);
        $this->assertSame(trim($expected), $css->get(true));
    }
Esempio n. 4
0
 /**
  * @param CM_Asset_Css $asset
  */
 protected function _setAsset(CM_Asset_Css $asset)
 {
     $this->_setContent($asset->get());
 }
Esempio n. 5
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];
     });
 }
Esempio n. 6
0
 /**
  * @param CM_Asset_Css $asset
  */
 protected function _setAsset(CM_Asset_Css $asset)
 {
     $compress = !CM_Bootloader::getInstance()->isDebug();
     $this->_setContent($asset->get($compress));
 }