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; }
public function parse($output) { $trlElements = array(); $fileCount = iterator_count($this->_fileFinder); $output->writeln('UnderscoreTemplate-Files:'); $progress = new ProgressBar($output, $fileCount); foreach ($this->_fileFinder as $file) { $progress->advance(); $trlElements = array_merge($trlElements, \Kwf_TrlJsParser_UnderscoreTemplateParser::parseContent($file->getContents())); } $progress->finish(); $output->writeln(''); return $trlElements; }
/** * @dataProvider parseDataProvider */ public function testParseData($content, $expectedTrlCalls) { $trlCalls = Kwf_TrlJsParser_UnderscoreTemplateParser::parseContent($content); foreach ($trlCalls as $key => $trlCall) { //$trlCall['error'] $this->assertEquals($trlCall['before'], $expectedTrlCalls[$key]['before']); $this->assertEquals($trlCall['text'], $expectedTrlCalls[$key]['text']); $this->assertEquals($trlCall['source'], $expectedTrlCalls[$key]['source']); $this->assertEquals($trlCall['type'], $expectedTrlCalls[$key]['type']); if (isset($expectedTrlCalls[$key]['context'])) { $this->assertEquals($trlCall['context'], $expectedTrlCalls[$key]['context']); } else { $this->assertEquals($trlCall['context'], null); } if (isset($expectedTrlCalls[$key]['plural'])) { $this->assertEquals($trlCall['plural'], $expectedTrlCalls[$key]['plural']); } else { $this->assertEquals($trlCall['plural'], null); } } }
public static function parseContent($content) { $parser = new Kwf_TrlJsParser_UnderscoreTemplateParser($content); return $parser->getTrlCalls(); }