Пример #1
0
 /**
  * Execute preprocessors instances suitable to convert source content type into a destination one
  *
  * @param Chain $chain
  * @return void
  */
 public function process(Chain $chain)
 {
     $type = $chain->getTargetContentType();
     foreach ($this->getPreProcessors($type) as $preProcessor) {
         $preProcessor->process($chain);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(Chain $chain)
 {
     $callback = function ($path) {
         return $this->notationResolver->convertVariableNotation($path);
     };
     $chain->setContent($this->cssResolver->replaceRelativeUrls($chain->getContent(), $callback));
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)
 {
     $asset = $chain->getAsset();
     $replaceCallback = function ($matchContent) use($asset) {
         return $this->replace($matchContent, $asset);
     };
     $chain->setContent(preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $chain->getContent()));
 }
 /**
  * {@inheritdoc}
  */
 public function process(Chain $chain)
 {
     $asset = $chain->getAsset();
     $callback = function ($path) use($asset) {
         return $this->notationResolver->convertModuleNotationToPath($asset, $path);
     };
     $chain->setContent($this->cssResolver->replaceRelativeUrls($chain->getContent(), $callback));
 }
Пример #5
0
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param Chain $chain
  * @return void
  */
 public function process(Chain $chain)
 {
     if ($this->isDictionaryPath($chain->getTargetAssetPath())) {
         $context = $chain->getAsset()->getContext();
         $themePath = $context instanceof FallbackContext ? $context->getThemePath() : '*/*';
         $chain->setContent(json_encode($this->dataProvider->getData($themePath)));
         $chain->setContentType('json');
     }
 }
Пример #6
0
 public function testProcess()
 {
     $expectedContent = 'updated content';
     $tmpFile = 'tmp/file.ext';
     $this->fileGenerator->expects($this->once())->method('generateFileTree')->with($this->chain)->will($this->returnValue($tmpFile));
     $this->adapter->expects($this->once())->method('process')->with($tmpFile)->will($this->returnValue($expectedContent));
     $this->object->process($this->chain);
     $this->assertEquals($expectedContent, $this->chain->getContent());
     $this->assertEquals('css', $this->chain->getContentType());
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)
 {
     $chain->setContentType('less');
     $tmpFile = $this->fileGenerator->generateFileTree($chain);
     $cssContent = $this->adapter->process($tmpFile);
     $cssTrimmedContent = trim($cssContent);
     if (!empty($cssTrimmedContent)) {
         $chain->setContent($cssContent);
     }
     $chain->setContentType('css');
 }
Пример #8
0
 /**
  * @param string $sourceContentType
  * @param string $targetContentType
  * @param array $expectedResult
  *
  * @dataProvider getPreProcessorsDataProvider
  */
 public function testProcess($sourceContentType, $targetContentType, array $expectedResult)
 {
     $this->processorChain->expects($this->any())->method('getOrigContentType')->willReturn($sourceContentType);
     $this->processorChain->expects($this->any())->method('getTargetContentType')->willReturn($targetContentType);
     $processorMaps = [];
     foreach ($expectedResult as $processor) {
         $processorMock = $this->getMock($processor, ['process'], [], '', false);
         $processorMock->expects($this->any())->method('process')->with($this->processorChain);
         $processorMaps[] = [$processor, $processorMock];
     }
     $this->objectManager->expects(static::atLeastOnce())->method('get')->willReturnMap($processorMaps);
     $this->processorPool->process($this->processorChain);
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 public function process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)
 {
     $asset = $chain->getAsset();
     $contentType = $chain->getContentType();
     $replaceCallback = function ($matchContent) use($asset, $contentType) {
         return $this->replace($matchContent, $asset, $contentType);
     };
     $content = $this->removeComments($chain->getContent());
     $processedContent = preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $content);
     if ($processedContent !== $content) {
         $chain->setContent($processedContent);
     }
 }
Пример #10
0
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param Chain $chain
  * @return void
  */
 public function process(Chain $chain)
 {
     if ($this->config->isEmbeddedStrategy()) {
         $context = $chain->getAsset()->getContext();
         $areaCode = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE;
         if ($context instanceof FallbackContext) {
             $areaCode = $context->getAreaCode();
             $this->translate->setLocale($context->getLocale());
         }
         $area = $this->areaList->getArea($areaCode);
         $area->load(\Magento\Framework\App\Area::PART_TRANSLATE);
         $chain->setContent($this->translate($chain->getContent()));
     }
 }
Пример #11
0
 /**
  * @inheritdoc
  * @throws \UnexpectedValueException
  */
 public function process(Chain $chain)
 {
     $path = $chain->getAsset()->getFilePath();
     $content = $chain->getContent();
     if (trim($content) !== '') {
         return;
     }
     try {
         $this->lockerProcess->lockProcess($this->lockName);
         $module = $chain->getAsset()->getModule();
         /** @var FallbackContext $context */
         $context = $chain->getAsset()->getContext();
         $chain->setContent($this->processContent($path, $content, $module, $context));
     } finally {
         $this->lockerProcess->unlockProcess();
     }
 }
Пример #12
0
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param Chain $chain
  * @return void
  */
 public function process(Chain $chain)
 {
     if ($this->isDictionaryPath($chain->getTargetAssetPath())) {
         $context = $chain->getAsset()->getContext();
         $themePath = '*/*';
         $areaCode = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE;
         if ($context instanceof FallbackContext) {
             $themePath = $context->getThemePath();
             $areaCode = $context->getAreaCode();
             $this->translate->setLocale($context->getLocale());
         }
         $area = $this->areaList->getArea($areaCode);
         $area->load(\Magento\Framework\App\Area::PART_TRANSLATE);
         $chain->setContent(json_encode($this->dataProvider->getData($themePath)));
         $chain->setContentType('json');
     }
 }
Пример #13
0
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param PreProcessor\Chain $chain
  * @return void
  */
 public function process(PreProcessor\Chain $chain)
 {
     if ($this->minification->isEnabled(pathinfo($chain->getTargetAssetPath(), PATHINFO_EXTENSION)) && $this->minification->isMinifiedFilename($chain->getTargetAssetPath()) && !$this->minification->isMinifiedFilename($chain->getOrigAssetPath())) {
         $content = $this->adapter->minify($chain->getContent());
         $chain->setContent($content);
     }
 }
Пример #14
0
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param Chain $chain
  * @return void
  */
 public function process(Chain $chain)
 {
     $chain->setContentType($chain->getTargetContentType());
 }
Пример #15
0
 /**
  * A callback for affecting preprocessor chain in the test
  *
  * @param Chain $chain
  */
 public function chainTestCallback(Chain $chain)
 {
     $chain->setContentType('ext');
     $chain->setContent('processed');
 }
Пример #16
0
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param Chain $chain
  * @return void
  */
 public function process(Chain $chain)
 {
     if ($this->config->isEmbeddedStrategy()) {
         $chain->setContent($this->translate($chain->getContent()));
     }
 }
Пример #17
0
 /**
  * @param LocalInterface $asset
  * @param string $origContent
  * @param string $origContentType
  * @param null $origAssetPath
  */
 public function __construct(LocalInterface $asset, $origContent, $origContentType, $origAssetPath = null)
 {
     parent::__construct($asset, $origContent, $origContentType);
     $this->targetContentType = $this->origContentType;
     $this->targetAssetPath = $origAssetPath;
 }
Пример #18
0
 /**
  * @param string $content
  * @param string $type
  * @param bool $expected
  * @dataProvider isChangedDataProvider
  */
 public function testIsChanged($content, $type, $expected)
 {
     $this->object->setContent($content);
     $this->object->setContentType($type);
     $this->assertEquals($expected, $this->object->isChanged());
 }
Пример #19
0
 /**
  * A callback for affecting preprocessor chain in the test
  *
  * @param \Magento\Framework\View\Asset\PreProcessor\Chain $chain
  */
 public function chainTestCallback(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)
 {
     $chain->setContentType('ext');
     $chain->setContent('processed');
 }