Ejemplo n.º 1
0
 public function getContentsPacked()
 {
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($this->getContentsSourceString());
     $map = $ret->getMapContentsData(false);
     $map->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName());
     return $ret;
 }
Ejemplo n.º 2
0
 public function getContentsPacked()
 {
     $basePath = 'vendor/bower_components/';
     if (file_exists($basePath . $this->_path . "/fonts/{$this->_name}.eot")) {
         //eg icomoon, ionicons
         $fontsPath = "/assets/{$this->_path}/fonts/{$this->_name}";
     } else {
         if (file_exists($basePath . $this->_path . "/fonts/" . strtolower($this->_name) . "-webfont.eot")) {
             //eg Font-Awesome
             $fontsPath = "/assets/{$this->_path}/fonts/" . strtolower($this->_name) . "-webfont";
         } else {
             throw new Kwf_Exception("Can't detect path of font");
         }
     }
     $ret = "";
     $ret .= "@font-face {\n";
     $ret .= "    font-family: '" . $this->_name . "';\n";
     $ret .= "    src: url('" . $fontsPath . ".eot');\n";
     $ret .= "    src: url('" . $fontsPath . ".eot?#iefix') format('eot'),\n";
     $ret .= "         url('" . $fontsPath . ".woff') format('woff'),\n";
     $ret .= "         url('" . $fontsPath . ".ttf') format('truetype'),\n";
     $ret .= "         url('" . $fontsPath . ".svg') format('svg');\n";
     $ret .= "}\n";
     return Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
 }
 public function getContentsPacked($language)
 {
     $c = $this->_dep->getContentsPacked($language);
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($this->_getPrependCode());
     $ret->concat($c);
     return $ret;
 }
 public static function run($pluginsInitCode, Kwf_SourceMaps_SourceMap $sourcemap)
 {
     $js = "\n            require('es6-promise').polyfill(); //required for older nodejs\n            var postcss = require('postcss');\n            var plugins = [];\n            " . $pluginsInitCode . "\n            var instance = postcss( plugins );\n            var css = '';\n            process.stdin.setEncoding('utf-8')\n            process.stdin.on('data', function(buf) { css += buf.toString(); });\n            process.stdin.on('end', function() {\n                instance.process(css).then(function (result) {\n                    process.stdout.write(result.css);\n                }).catch(function(e) {\n                    console.log(e);\n                    process.exit(1);\n                });\n            });\n            process.stdin.resume();\n        ";
     $runfile = tempnam("temp/", 'postcss');
     file_put_contents($runfile, $js);
     putenv("NODE_PATH=" . getcwd() . "/node_modules" . PATH_SEPARATOR . getcwd() . "/" . KWF_PATH . PATH_SEPARATOR . getcwd() . "/");
     $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . $runfile;
     $cmd .= " 2>&1";
     $process = new Symfony\Component\Process\Process($cmd);
     $mapData = $sourcemap->getMapContentsData(false);
     $hasSourcemap = !!$mapData->mappings;
     if ($hasSourcemap) {
         $process->setInput($sourcemap->getFileContentsInlineMap(false));
     } else {
         $process->setInput($sourcemap->getFileContents());
     }
     if ($process->run() !== 0) {
         throw new Kwf_Exception("Process '{$cmd}' failed with " . $process->getExitCode() . "\n" . $process->getOutput());
     }
     putenv("NODE_PATH=");
     unlink($runfile);
     $out = $process->getOutput();
     if (Kwf_SourceMaps_SourceMap::hasInline($out)) {
         $ret = Kwf_SourceMaps_SourceMap::createFromInline($out);
     } else {
         $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($out);
         $ret->setMimeType('text/css');
     }
     $ret->setSources($sourcemap->getSources());
     return $ret;
 }
 public function getContentsPacked()
 {
     $contents = file_get_contents($this->getAbsoluteFileName());
     $useTrl = strpos($contents, 'trl') !== false && preg_match('#trl(c|p|cp)?(Kwf)?(Static)?\\(#', $contents);
     $trlData = array();
     if ($useTrl) {
         foreach (Kwf_TrlJsParser_UnderscoreTemplateParser::parseContent($contents) as $trlElement) {
             $d = Kwf_Assets_Util_Trl::getJsReplacement($trlElement);
             $contents = str_replace($d['before'], $d['replace'], $contents);
             $trlData[] = $d['trlElement'];
         }
     }
     $contents = str_replace("\n", '\\n', $contents);
     $contents = str_replace("'", "\\'", $contents);
     $contents = "var _ = require('underscore');\n" . "module.exports = _.template('" . $contents . "');\n";
     $replacements = array();
     if (strpos($contents, 'kwfUp-') !== false) {
         if (Kwf_Config::getValue('application.uniquePrefix')) {
             $replacements['kwfUp-'] = Kwf_Config::getValue('application.uniquePrefix') . '-';
         } else {
             $replacements['kwfUp-'] = '';
         }
     }
     foreach ($replacements as $search => $replace) {
         $contents = str_replace($search, $replace, $contents);
     }
     $map = Kwf_SourceMaps_SourceMap::createEmptyMap($contents);
     $data = $map->getMapContentsData();
     $data->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName());
     if ($trlData) {
         $data->{'_x_org_koala-framework_trlData'} = $trlData;
     }
     return $map;
 }
Ejemplo n.º 6
0
 public function getContentsPacked()
 {
     if (!$this->_features) {
         return null;
     }
     $modernizrPath = getcwd() . '/node_modules/modernizr';
     $outputFile = tempnam('./temp', 'modernizr');
     $configAll = json_decode(file_get_contents($modernizrPath . '/lib/config-all.json'), true);
     $allFeatureDetects = $configAll['feature-detects'];
     $options = array();
     foreach ($configAll['options'] as $i) {
         $options[$i] = false;
     }
     $options['mq'] = true;
     $options['setClasses'] = true;
     $featureDetects = array();
     foreach ($this->_features as $f) {
         if (isset($options[strtolower($f)])) {
             //for prefixed
             $options[strtolower($f)] = true;
         } else {
             $filter = new Zend_Filter_Word_CamelCaseToSeparator('/');
             $fFiltered = strtolower($filter->filter($f));
             if (!in_array($fFiltered, $allFeatureDetects)) {
                 throw new Kwf_Exception("Invalid Modernizr Dependency, test doesn't exist: '" . $f . "'");
             }
             $featureDetects[] = $fFiltered;
         }
     }
     foreach ($options as $k => $i) {
         if (!$i) {
             unset($options[$k]);
         }
     }
     $options = array_keys($options);
     $classPrefix = '';
     if (Kwf_Config::getValue('application.uniquePrefix')) {
         $classPrefix = Kwf_Config::getValue('application.uniquePrefix') . '-';
     }
     $config = array('classPrefix' => $classPrefix, 'options' => $options, 'feature-detects' => $featureDetects);
     $configFile = tempnam('temp/', 'modernizrbuild');
     unlink($configFile);
     $configFile .= '.json';
     file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT));
     $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node {$modernizrPath}/bin/modernizr --config {$configFile} --uglify --dest " . $outputFile;
     exec($cmd, $out, $retVar);
     if ($retVar) {
         throw new Kwf_Exception("modernizr failed: " . implode("\n", $out));
     }
     $ret = file_get_contents($outputFile);
     unlink($configFile);
     unlink($outputFile);
     //remove comments containing selected tests
     $ret = preg_replace("#\n/\\*!\n\\{.*?\\}\n!\\*/\n#s", '', $ret);
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
     $map = $ret->getMapContentsData(false);
     $map->{'_x_org_koala-framework_masterFiles'} = array(getcwd() . '/node_modules/modernizr/package.json');
     return $ret;
 }
 public function getContentsPacked()
 {
     $config = array('providerList' => get_class($this->_providerList));
     $ret = "";
     $ret .= "if (!window.Kwf) window.Kwf = {};\n";
     $ret .= "if (!window.Kwf.Loader) window.Kwf.Loader = {};\n";
     $ret .= "window.Kwf.Loader.config = " . json_encode($config) . ";\n";
     return Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
 }
Ejemplo n.º 8
0
 public function getContentsPacked()
 {
     if (!Kwf_Config::getValue('ravenJs.dsn')) {
         throw new Kwf_Exception('ravenJS.dsn config setting is required');
     }
     $data = array('dsn' => Kwf_Config::getValue('ravenJs.dsn'));
     $ret = "Kwf.RavenJsConfig = " . json_encode($data) . ";";
     return Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
 }
    public static function filter($map, $uniquePrefix)
    {
        $head = '
        (function() {
            if (!window.' . $uniquePrefix . ') window.' . $uniquePrefix . ' = {};
            var kwfUp = window.' . $uniquePrefix . ';

            var kwfNamespaces = ["Kwf", "Kwc", "Ext2", "Ext", "$", "jQuery", "Modernizr", "require", "define", "_kwfTrl", "_kwfTrlp"];

            var kwfOrigExports = {};
            for (var i=0; i<kwfNamespaces.length; i++) {
                var name = kwfNamespaces[i];
                kwfOrigExports[name] = window[name];
                if (kwfUp[name]) {
                    window[name] = kwfUp[name];
                } else {
                    window[name] = undefined;
                    try {
                        delete window[name];
                    } catch (e) {
                    }
                }
            }
            if (!window.Ext2) window.Ext2 = {};
        ';
        $foot = '
        for (var i=0; i<kwfNamespaces.length; i++) {
                var name = kwfNamespaces[i];
                try {
                    kwfUp[name] = window[name] || eval(name);
                } catch(e) {
                }
                if (kwfOrigExports[name]) {
                    window[name] = kwfOrigExports[name];
                } else {
                    window[name] = undefined;
                    try {
                        delete window[name];
                    } catch (e) {
                    }
                }
                eval("var "+name+" = kwfUp."+name+";");
            }
        })();
        ';
        $ret = Kwf_SourceMaps_SourceMap::createEmptyMap('');
        $ret->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($head));
        $ret->concat($map);
        $ret->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($foot));
        $mapData = $map->getMapContentsData(false);
        if (isset($mapData->{'_x_org_koala-framework_sourcesContent'})) {
            $retData = $ret->getMapContentsData(false);
            $retData->{'_x_org_koala-framework_sourcesContent'} = $mapData->{'_x_org_koala-framework_sourcesContent'};
        }
        return $ret;
    }
Ejemplo n.º 10
0
    public static function filter($map, $uniquePrefix)
    {
        $head = '
        (function() {
            if (!window.' . $uniquePrefix . ') window.' . $uniquePrefix . ' = {};
            var kwfUp = window.' . $uniquePrefix . ';

            var kwfNamespaces = ["Kwf", "Kwc", "Ext2", "$", "jQuery", "Modernizr", "require", "trl", "trlp"];

            var kwfOrigExports = {};
            for (var i=0; i<kwfNamespaces.length; i++) {
                var name = kwfNamespaces[i];
                kwfOrigExports[name] = window[name];
                if (kwfUp[name]) {
                    window[name] = kwfUp[name];
                } else {
                    try {
                        delete window[name];
                    } catch (e) {
                        window[name] = undefined;
                    }
                }
            }
            if (!window.Ext2) window.Ext2 = {};
        ';
        $foot = '
        for (var i=0; i<kwfNamespaces.length; i++) {
                var name = kwfNamespaces[i];
                try {
                    kwfUp[name] = window[name] || eval(name);
                } catch(e) {
                    continue;
                }
                if (kwfOrigExports[name]) {
                    window[name] = kwfOrigExports[name];
                } else {
                    try {
                        delete window[name];
                    } catch (e) {
                        window[name] = undefined;
                    }
                }
                eval("var "+name+" = kwfUp."+name+";");
            }
        })();
        ';
        $ret = Kwf_SourceMaps_SourceMap::createEmptyMap('');
        $ret->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($head));
        $ret->concat($map);
        $ret->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($foot));
        return $ret;
    }
 public function filter(Kwf_SourceMaps_SourceMap $sourcemap)
 {
     $temp = tempnam('temp/', 'commonjs');
     file_put_contents($temp, $sourcemap->getFileContents());
     $parsedFile = Kwf_Assets_CommonJs_ModuleDepsParser::parse($temp);
     unlink($temp);
     $newSourceMap = Kwf_SourceMaps_SourceMap::createEmptyMap($parsedFile['source']);
     if (isset($sourcemap->getMapContentsData(false)->{'_x_org_koala-framework_trlData'})) {
         $newSourceMap->getMapContentsData(false)->{'_x_org_koala-framework_trlData'} = $sourcemap->getMapContentsData(false)->{'_x_org_koala-framework_trlData'};
     }
     if (isset($sourcemap->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'})) {
         $newSourceMap->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'} = $sourcemap->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'};
     }
     return $newSourceMap;
 }
Ejemplo n.º 12
0
 public function getContentsPacked($language)
 {
     if (!isset($this->_cacheContents)) {
         $contents = $this->getContents($language);
         $contents = str_replace("\r", "\n", $contents);
         // remove comments
         //$contents = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents);
         // multiple whitespaces
         $contents = str_replace("\t", " ", $contents);
         $contents = preg_replace('/(\\n)\\n+/', '$1', $contents);
         $contents = preg_replace('/(\\n)\\ +/', '$1', $contents);
         $contents = preg_replace('/(\\ )\\ +/', '$1', $contents);
         $this->_cacheContents = $contents;
     }
     return Kwf_SourceMaps_SourceMap::createEmptyMap($this->_cacheContents);
 }
Ejemplo n.º 13
0
 public function getContentsPacked()
 {
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap('');
     $trlData = array();
     $masterFiles = array();
     foreach ($this->_componentDependencies as $dep) {
         $c = $dep->getContentsPacked();
         $data = $c->getMapContentsData(false);
         if (isset($data->{'_x_org_koala-framework_trlData'})) {
             $trlData = array_merge($trlData, $data->{'_x_org_koala-framework_trlData'});
         }
         if (isset($data->{'_x_org_koala-framework_masterFiles'})) {
             $masterFiles = array_merge($masterFiles, $data->{'_x_org_koala-framework_masterFiles'});
         }
         $sourcesCount = 0;
         $packageData = $ret->getMapContentsData(false);
         if (isset($packageData->sources)) {
             $sourcesCount = count($packageData->sources);
         }
         unset($packageData);
         if (Kwf_Config::getValue('application.uniquePrefix')) {
             $c->stringReplace('kwcBem--', $this->_getKwcClass() . '--');
             $c->stringReplace('kwcBem__', $this->_getKwcClass() . '__');
         } else {
             $c->stringReplace('kwcBem--', '');
             $c->stringReplace('kwcBem__', '');
         }
         $c->stringReplace('.kwcClass', '.' . $this->_getKwcClass());
         $ret->concat($c);
         //copy sourcesContent to packageMap with $sourcesCount offset
         $packageData = $ret->getMapContentsData(false);
         if (isset($data->{'_x_org_koala-framework_sourcesContent'})) {
             if (!isset($packageData->{'_x_org_koala-framework_sourcesContent'})) {
                 $packageData->{'_x_org_koala-framework_sourcesContent'} = array();
             }
             foreach ($data->{'_x_org_koala-framework_sourcesContent'} as $k => $i) {
                 $packageData->{'_x_org_koala-framework_sourcesContent'}[$k + $sourcesCount] = $i;
             }
         }
         unset($packageData);
     }
     $ret->getMapContentsData(false)->{'_x_org_koala-framework_trlData'} = $trlData;
     $ret->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'} = $masterFiles;
     $ret->setMimeType('text/javascript');
     return $ret;
 }
 public function testRemoveReplacedMapping()
 {
     //0         1         2         3         4
     //01234567890123456789012345678901234567890123456789
     $map = Kwf_SourceMaps_SourceMap::createEmptyMap('(function($,window,document,undefined){var x=1;});');
     $map->addMapping(1, 1, 1, 1, 'foo.js');
     $map->addMapping(1, 10, 1, 11, 'foo.js', '$');
     $map->addMapping(1, 12, 1, 14, 'foo.js', 'window');
     $map->addMapping(1, 19, 1, 22, 'foo.js', 'document');
     $map->addMapping(1, 28, 1, 32, 'foo.js', 'undefined');
     $map->addMapping(1, 43, 2, 5, 'foo.js', 'x');
     $map->stringReplace('(function($,window,document,undefined){', "var \$=jQuery=require('jQuery');");
     $mappings = $map->getMappings();
     $this->assertEquals(2, count($mappings));
     $this->assertEquals($mappings[0], array('generatedLine' => 1, 'generatedColumn' => 1, 'originalSource' => 'foo.js', 'originalLine' => 1, 'originalColumn' => 1, 'originalName' => null));
     $this->assertEquals($mappings[1], array('generatedLine' => 1, 'generatedColumn' => 43 + 31 - 39, 'originalSource' => 'foo.js', 'originalLine' => 2, 'originalColumn' => 5, 'originalName' => 'x'));
 }
Ejemplo n.º 15
0
 public function getContentsPacked()
 {
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap('');
     $masterFiles = array();
     foreach ($this->_componentDependencies as $dep) {
         $c = $dep->getContentsPacked();
         $data = $c->getMapContentsData(false);
         if (isset($data->{'_x_org_koala-framework_masterFiles'})) {
             $masterFiles = array_merge($masterFiles, $data->{'_x_org_koala-framework_masterFiles'});
         }
         $sourcesCount = 0;
         $packageData = $ret->getMapContentsData(false);
         if (isset($packageData->sources)) {
             $sourcesCount = count($packageData->sources);
         }
         unset($packageData);
         $replacements = array();
         if (Kwf_Config::getValue('application.uniquePrefix')) {
             $replacements['kwcBem--'] = $this->_getKwcClass() . '--';
             $replacements['kwcBem__'] = $this->_getKwcClass() . '__';
         } else {
             $replacements['kwcBem--'] = '';
             $replacements['kwcBem__'] = '';
         }
         $replacements['kwcClass'] = $this->_getKwcClass();
         $filter = new Kwf_Assets_Filter_Css_SelectorReplace($replacements);
         $c = $filter->filter($c);
         $ret->concat($c);
         //copy sourcesContent to packageMap with $sourcesCount offset
         $packageData = $ret->getMapContentsData(false);
         if (isset($data->{'_x_org_koala-framework_sourcesContent'})) {
             if (!isset($packageData->{'_x_org_koala-framework_sourcesContent'})) {
                 $packageData->{'_x_org_koala-framework_sourcesContent'} = array();
             }
             foreach ($data->{'_x_org_koala-framework_sourcesContent'} as $k => $i) {
                 $packageData->{'_x_org_koala-framework_sourcesContent'}[$k + $sourcesCount] = $i;
             }
         }
         unset($packageData);
     }
     $ret->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'} = $masterFiles;
     $ret->setMimeType('text/css');
     return $ret;
 }
 public static function filter($ret)
 {
     $uniquePrefix = Kwf_Config::getValue('application.uniquePrefix');
     if ($uniquePrefix) {
         $uniquePrefix = $uniquePrefix . '.';
     }
     $head = '
     ' . $uniquePrefix . 'Kwf.loadDeferred(function() {
     ';
     $foot = '
     });
     ';
     $map = Kwf_SourceMaps_SourceMap::createEmptyMap('');
     $map->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($head));
     $map->concat($ret);
     $map->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($foot));
     $ret = $map;
     return $ret;
 }
Ejemplo n.º 17
0
 public function getContentsPacked()
 {
     $contents = $this->getContentsSourceString();
     $contents = str_replace("\r", "\n", $contents);
     $contents = $this->_processContents($contents);
     // remove comments
     //$contents = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents);
     // multiple whitespaces
     $contents = str_replace("\t", " ", $contents);
     $contents = preg_replace('/(\\n)\\n+/', '$1', $contents);
     $contents = preg_replace('/(\\n)\\ +/', '$1', $contents);
     $contents = preg_replace('/(\\ )\\ +/', '$1', $contents);
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($contents);
     $data = $ret->getMapContentsData();
     $data->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName());
     $data->sources = array('/assets/' . $this->getFileNameWithType());
     $ret->setMimeType('text/css');
     return $ret;
 }
 public function getPackageContents($mimeType, $language, $includeSourceMapComment = true)
 {
     $ret = parent::getPackageContents($mimeType, $language, $includeSourceMapComment);
     if ($mimeType == 'text/javascript; defer') {
         $uniquePrefix = Kwf_Config::getValue('application.uniquePrefix');
         if ($uniquePrefix) {
             $uniquePrefix = $uniquePrefix . '.';
         }
         $foot = '
         if (' . $uniquePrefix . 'Kwf._loadDeferred) ' . $uniquePrefix . 'Kwf._loadDeferred.forEach(function(i) { i(); });
         ' . $uniquePrefix . 'Kwf._loadDeferred = "done";
         ';
         $map = Kwf_SourceMaps_SourceMap::createEmptyMap('');
         $map->concat($ret);
         $map->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($foot));
         $ret = $map;
     }
     return $ret;
 }
 public function getContentsPacked()
 {
     if (!Kwf_Config::getValue('googleMapsApiKey') && !Kwf_Config::getValueArray('googleMapsApiKeys')) {
         throw new Kwf_Exception('googleMapsApiKey is required in config.ini');
     }
     if (Kwf_Config::getValue('googleMapsApiKey')) {
         $json = Kwf_Config::getValue('googleMapsApiKey');
         if (Kwf_Config::getValueArray('googleMapsApiKeys')) {
             throw new Kwf_Exception('Don\'t use googleMapsApiKeys and googleMapsApiKey together, remove googleMapsApiKeys');
         }
     } else {
         //legacy
         $json = Kwf_Config::getValueArray('googleMapsApiKeys');
     }
     $json = json_encode($json);
     $ret = "module.exports = {$json};";
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
     $data = $ret->getMapContentsData();
     $data->{'_x_org_koala-framework_masterFiles'} = array('config.ini');
     return $ret;
 }
Ejemplo n.º 20
0
 public function filter(Kwf_SourceMaps_SourceMap $sourcemap)
 {
     putenv("NODE_PATH=" . getcwd() . "/node_modules");
     $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . __DIR__ . "/CssChunks.js";
     $cmd .= " 2>&1";
     $process = new Symfony\Component\Process\Process($cmd);
     $process->setInput($sourcemap->getFileContentsInlineMap(false));
     $process->mustRun();
     $out = $process->getOutput();
     $out = explode("\n/* ***** NEXT CHUNK ***** */\n", $out);
     $ret = array();
     foreach ($out as $chunk) {
         if (Kwf_SourceMaps_SourceMap::hasInline($chunk)) {
             $mapChunk = Kwf_SourceMaps_SourceMap::createFromInline($chunk);
         } else {
             $mapChunk = Kwf_SourceMaps_SourceMap::createEmptyMap($chunk);
             $mapChunk->setMimeType('text/css');
         }
         $ret[] = $mapChunk;
     }
     return $ret;
 }
Ejemplo n.º 21
0
 public function getPackageContents($mimeType, $language, $includeSourceMapComment = true)
 {
     if (!Kwf_Assets_BuildCache::getInstance()->building && !Kwf_Config::getValue('assets.lazyBuild')) {
         if (Kwf_Exception_Abstract::isDebug()) {
             //proper error message on development server
             throw new Kwf_Exception("Building assets is disabled (assets.lazyBuild). Please upload build contents.");
         } else {
             throw new Kwf_Exception_NotFound();
         }
     }
     if (!isset($this->_packageContentsCache[$mimeType])) {
         $this->_packageContentsCache[$mimeType] = $this->_buildPackageContents($mimeType);
     }
     $packageMap = $this->_packageContentsCache[$mimeType]['contents'];
     $trlData = $this->_packageContentsCache[$mimeType]['trlData'];
     if (($mimeType == 'text/javascript' || $mimeType == 'text/javascript; defer') && $trlData) {
         $js = "";
         $uniquePrefix = Kwf_Config::getValue('application.uniquePrefix');
         if ($uniquePrefix) {
             $js = "if (typeof window.{$uniquePrefix} == 'undefined') window.{$uniquePrefix} = {};";
             $uniquePrefix = "window.{$uniquePrefix}.";
             $js .= "if (!{$uniquePrefix}_kwfTrlData) {$uniquePrefix}_kwfTrlData={};";
         } else {
             $js .= "if (!window._kwfTrlData) window._kwfTrlData={};";
         }
         foreach ($trlData as $i) {
             $key = $i->type . '.' . $i->source;
             if (isset($i->context)) {
                 $key .= '.' . $i->context;
             }
             $key .= '.' . str_replace("'", "\\'", $i->text);
             $method = $i->type;
             if ($i->source == 'kwf') {
                 $method .= 'Kwf';
             }
             if ($i->type == 'trl') {
                 $trlText = Kwf_Trl::getInstance()->{$method}($i->text, array(), $language);
                 $js .= "{$uniquePrefix}_kwfTrlData['{$key}']='" . str_replace("'", "\\'", $trlText) . "';";
             } else {
                 if ($i->type == 'trlc') {
                     $trlText = Kwf_Trl::getInstance()->{$method}($i->context, $i->text, array(), $language);
                     $js .= "{$uniquePrefix}_kwfTrlData['{$key}']='" . str_replace("'", "\\'", $trlText) . "';";
                 } else {
                     if ($i->type == 'trlp') {
                         $trlText = Kwf_Trl::getInstance()->getTrlpValues(null, $i->text, $i->plural, $i->source, $language);
                         $js .= "{$uniquePrefix}_kwfTrlData['{$key}']='" . str_replace("'", "\\'", $trlText['single']) . "';";
                         $js .= "{$uniquePrefix}_kwfTrlData['{$key}.plural']='" . str_replace("'", "\\'", $trlText['plural']) . "';";
                     } else {
                         if ($i->type == 'trlcp') {
                             $trlText = Kwf_Trl::getInstance()->getTrlpValues($i->context, $i->text, $i->plural, $i->source, $language);
                             $js .= "{$uniquePrefix}_kwfTrlData['{$key}']='" . str_replace("'", "\\'", $trlText['single']) . "';";
                             $js .= "{$uniquePrefix}_kwfTrlData['{$key}.plural']='" . str_replace("'", "\\'", $trlText['plural']) . "';";
                         } else {
                             throw new Kwf_Exception("Unknown trl type");
                         }
                     }
                 }
             }
         }
         $map = Kwf_SourceMaps_SourceMap::createEmptyMap($js . "\n");
         $map->concat($packageMap);
         $packageMap = $map;
     }
     if ($mimeType == 'text/javascript') {
         $ext = 'js';
     } else {
         if ($mimeType == 'text/javascript; defer') {
             $ext = 'defer.js';
         } else {
             if ($mimeType == 'text/css') {
                 $ext = 'css';
             } else {
                 if ($mimeType == 'text/css; ie8') {
                     $ext = 'ie8.css';
                 } else {
                     throw new Kwf_Exception("Invalid mimeType: '{$mimeType}'");
                 }
             }
         }
     }
     $packageMap->setFile($this->getPackageUrl($ext, $language));
     return $packageMap;
 }
 public function getContentsPacked()
 {
     $ret = "require('kwf/responsive-el')('" . $this->_selector . "', " . json_encode($this->_breakpoints) . ");\n";
     return Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
 }
Ejemplo n.º 23
0
 public function testWithoutMappingInLastLine()
 {
     $d1 = Kwf_SourceMaps_SourceMap::createEmptyMap(".kwcClass{a:red}\n");
     $d1->addMapping(1, 0, 1, 0, 'aaa.scss');
     $d2 = Kwf_SourceMaps_SourceMap::createEmptyMap('aaa');
     $d2->addMapping(1, 0, 3, 0, 'bbb.scss');
     $map = Kwf_SourceMaps_SourceMap::createEmptyMap('');
     foreach (array($d1, $d2) as $c) {
         $map->concat($c);
     }
     $mappings = $map->getMappings();
     $this->assertEquals($mappings[0], array('generatedLine' => 1, 'generatedColumn' => 0, 'originalSource' => 'aaa.scss', 'originalLine' => 1, 'originalColumn' => 0, 'originalName' => null));
     $this->assertEquals($mappings[1], array('generatedLine' => 2, 'generatedColumn' => 0, 'originalSource' => 'bbb.scss', 'originalLine' => 3, 'originalColumn' => 0, 'originalName' => null));
 }
 public function getContentsPacked($language)
 {
     $ret = $this->_contents;
     return Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
 }
 public function getContentsPacked()
 {
     $ret = "if (typeof Kwf == 'undefined') Kwf = {};" . "Kwf.application = { assetsVersion: '" . Kwf_Assets_Dispatcher::getInstance()->getAssetsVersion() . "' };\n";
     return Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
 }
Ejemplo n.º 26
0
 public function getPackageContents($mimeType, $language, $includeSourceMapComment = true)
 {
     if (!Kwf_Assets_BuildCache::getInstance()->building && !Kwf_Config::getValue('assets.lazyBuild')) {
         if (Kwf_Exception_Abstract::isDebug()) {
             //proper error message on development server
             throw new Kwf_Exception("Building assets is disabled (assets.lazyBuild). Please upload build contents.");
         } else {
             throw new Kwf_Exception_NotFound();
         }
     }
     $packageMap = Kwf_SourceMaps_SourceMap::createEmptyMap('');
     if ($mimeType == 'text/javascript') {
         $ext = 'js';
     } else {
         if ($mimeType == 'text/javascript; defer') {
             $ext = 'defer.js';
         } else {
             if ($mimeType == 'text/css') {
                 $ext = 'css';
             } else {
                 if ($mimeType == 'text/css; media=print') {
                     $ext = 'printcss';
                 }
             }
         }
     }
     $packageMap->setFile($this->getPackageUrl($ext, $language));
     $maxMTime = 0;
     $commonJsData = array();
     $commonJsDeps = array();
     foreach ($this->_getFilteredUniqueDependencies($mimeType) as $i) {
         if ($i->getIncludeInPackage()) {
             if (($mimeType == 'text/javascript' || $mimeType == 'text/javascript') && $i->isCommonJsEntry()) {
                 $c = $i->getContentsPacked($language)->getFileContentsInlineMap(false);
                 $commonJsDeps = $this->_getCommonJsDeps($i, $language);
                 $commonJsData[$i->__toString()] = array('id' => $i->__toString(), 'source' => $c, 'sourceFile' => $i->__toString(), 'deps' => $commonJsDeps['deps'], 'entry' => true);
                 foreach ($commonJsDeps['data'] as $k => $j) {
                     if (!isset($commonJsData[$k])) {
                         $commonJsData[$k] = $j;
                     }
                 }
             } else {
                 $map = $i->getContentsPacked($language);
                 if (strpos($map->getFileContents(), "//@ sourceMappingURL=") !== false && strpos($map->getFileContents(), "//# sourceMappingURL=") !== false) {
                     throw new Kwf_Exception("contents must not contain sourceMappingURL");
                 }
                 foreach ($map->getMapContentsData(false)->sources as &$s) {
                     $s = '/assets/' . $s;
                 }
                 // $ret .= "/* *** $i */\n"; // attention: commenting this in breaks source maps
                 $packageMap->concat($map);
             }
         }
         $mTime = $i->getMTime();
         if ($mTime) {
             $maxMTime = max($maxMTime, $mTime);
         }
     }
     if ($commonJsData) {
         if ($mimeType == 'text/javascript; defer') {
             //in defer.js don't include deps that are already loaded in non-defer
             foreach ($this->_getFilteredUniqueDependencies('text/javascript') as $i) {
                 $commonJsDeps = $this->_getCommonJsDeps($i, $language);
                 foreach (array_keys($commonJsDeps['data']) as $key) {
                     if (isset($commonJsData[$key])) {
                         unset($commonJsData[$key]);
                     }
                 }
                 $c = $i->getContentsPacked($language)->getFileContentsInlineMap(false);
                 $commonJsData[$i->__toString()] = array('id' => $i->__toString(), 'source' => $c, 'sourceFile' => $i->__toString(), 'deps' => $commonJsDeps['deps'], 'entry' => true);
             }
         }
         $contents = 'window.require = ' . Kwf_Assets_CommonJs_BrowserPack::pack(array_values($commonJsData));
         $map = Kwf_SourceMaps_SourceMap::createFromInline($contents);
         $packageMap->concat($map);
     }
     if ($mimeType == 'text/javascript' || $mimeType == 'text/javascript; defer') {
         if ($uniquePrefix = Kwf_Config::getValue('application.uniquePrefix')) {
             $packageMap = Kwf_Assets_Package_Filter_UniquePrefix::filter($packageMap, $uniquePrefix);
         }
     }
     if ($includeSourceMapComment) {
         $contents = $packageMap->getFileContents();
         if ($mimeType == 'text/javascript') {
             $ext = 'js';
         } else {
             if ($mimeType == 'text/javascript; defer') {
                 $ext = 'defer.js';
             } else {
                 if ($mimeType == 'text/css') {
                     $ext = 'css';
                 } else {
                     if ($mimeType == 'text/css; media=print') {
                         $ext = 'printcss';
                     } else {
                         throw new Kwf_Exception_NotYetImplemented();
                     }
                 }
             }
         }
         if ($ext == 'js' || $ext == 'defer.js') {
             $contents .= "\n//# sourceMappingURL=" . $this->getPackageUrl($ext . '.map', $language) . "\n";
         } else {
             if ($ext == 'css' || $ext == 'printcss') {
                 $contents .= "\n/*# sourceMappingURL=" . $this->getPackageUrl($ext . '.map', $language) . " */\n";
             }
         }
         $packageMap->setFileContents($contents);
     }
     return $packageMap;
 }
Ejemplo n.º 27
0
 public function getContentsPacked($language)
 {
     $contents = $this->getContents($language);
     return Kwf_SourceMaps_SourceMap::createEmptyMap($contents);
 }
Ejemplo n.º 28
0
 public function getContentsPacked($language)
 {
     $hash = '';
     foreach ($this->_componentDependencies as $dep) {
         $src = $dep->getContentsSource();
         if ($src['type'] == 'file') {
             $hash .= md5_file($src['file']);
         } else {
             if ($src['type'] == 'contents') {
                 $hash .= md5($src['contents']);
             } else {
                 throw new Kwf_Exception_NotYetImplemented();
             }
         }
     }
     $hash = md5($hash);
     $cacheFile = "cache/componentassets/{$this->_componentClass}" . ($this->usesLanguage() ? "-{$language}" : '') . "-" . Kwf_Config::getValue('application.uniquePrefix') . "-{$hash}";
     if (file_exists($cacheFile)) {
         $ret = Kwf_SourceMaps_SourceMap::createFromInline(file_get_contents($cacheFile));
     } else {
         $ret = Kwf_SourceMaps_SourceMap::createEmptyMap('');
         foreach ($this->_componentDependencies as $dep) {
             $c = $dep->getContentsPacked($language);
             if (Kwf_Config::getValue('application.uniquePrefix')) {
                 $c->stringReplace('kwcBem--', $this->_getKwcClass() . '--');
                 $c->stringReplace('kwcBem__', $this->_getKwcClass() . '__');
             } else {
                 $c->stringReplace('kwcBem--', '');
                 $c->stringReplace('kwcBem__', '');
             }
             $c->stringReplace('.kwcClass', '.' . $this->_getKwcClass());
             $ret->concat($c);
         }
         file_put_contents($cacheFile, $ret->getFileContentsInlineMap());
     }
     return $ret;
 }
Ejemplo n.º 29
0
 protected function _getContents($language, $pack)
 {
     if ($pack) {
         $compiledContents = $this->_getCompliedContents();
         $map = $compiledContents['contents'];
         $trlElements = $compiledContents['trlElements'];
     } else {
         $contents = $this->_getRawContents(null);
         $map = Kwf_SourceMaps_SourceMap::createEmptyMap($contents);
         $trlElements = Kwf_Trl_Parser_JsParser::parseContent($contents);
         unset($contents);
     }
     if ($trlElements) {
         $buildFile = false;
         if ($pack) {
             $buildFile = "cache/assets/" . $this->getFileNameWithType() . '-' . $language;
             $dir = dirname($buildFile);
             if (!file_exists($dir)) {
                 mkdir($dir, 0777, true);
             }
         }
         if (!$buildFile || !file_exists("{$buildFile}.buildtime") || filemtime($this->getAbsoluteFileName()) != file_get_contents("{$buildFile}.buildtime")) {
             foreach ($this->_getTrlReplacements($trlElements, $map->getFileContents(), $language) as $value) {
                 $map->stringReplace($value['search'], $value['replace']);
             }
             if ($buildFile) {
                 $map->save("{$buildFile}.map", $buildFile);
                 file_put_contents("{$buildFile}.buildtime", filemtime($this->getAbsoluteFileName()));
             }
         } else {
             $map = new Kwf_SourceMaps_SourceMap(file_get_contents("{$buildFile}.map"), file_get_contents("{$buildFile}"));
         }
     }
     return $map;
 }