Skip to content

Commit

Permalink
per-batch absolute url option
Browse files Browse the repository at this point in the history
  • Loading branch information
Gappa committed Jan 30, 2018
1 parent be31720 commit 9363263
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
22 changes: 22 additions & 0 deletions WebLoader/Compiler.php
Expand Up @@ -43,6 +43,9 @@ class Compiler
/** @var string */
private $nonce = NULL;

/** @var bool */
private $absoluteUrl = FALSE;

public function __construct(IFileCollection $files, IOutputNamingConvention $convention, $outputDir)
{
$this->collection = $files;
Expand Down Expand Up @@ -178,6 +181,25 @@ public function setDefer($defer)
return $this;
}


/**
* @return boolean
*/
public function isAbsoluteUrl()
{
return $this->absoluteUrl;
}

/**
* @param boolean $absoluteUrl
* @return Compiler
*/
public function setAbsoluteUrl($absoluteUrl)
{
$this->absoluteUrl = $absoluteUrl;
return $this;
}

/**
* Set check last modified
* @param bool $checkLastModified
Expand Down
8 changes: 6 additions & 2 deletions WebLoader/Nette/Extension.php
Expand Up @@ -40,6 +40,7 @@ public function getDefaultConfig()
'async' => FALSE,
'defer' => FALSE,
'nonce' => NULL,
'absoluteUrl' => FALSE,
'namingConvention' => '@' . $this->prefix('jsNamingConvention'),
),
'cssDefaults' => array(
Expand All @@ -57,6 +58,7 @@ public function getDefaultConfig()
'async' => FALSE,
'defer' => FALSE,
'nonce' => NULL,
'absoluteUrl' => FALSE,
'namingConvention' => '@' . $this->prefix('cssNamingConvention'),
),
'js' => array(
Expand Down Expand Up @@ -138,10 +140,12 @@ private function addWebLoader(ContainerBuilder $builder, $name, $config)
$config['tempDir'],
));

$compiler->addSetup('setJoinFiles', array($config['joinFiles']))
$compiler
->addSetup('setJoinFiles', array($config['joinFiles']))
->addSetup('setAsync', array($config['async']))
->addSetup('setDefer', array($config['defer']))
->addSetup('setNonce', array($config['nonce']));
->addSetup('setNonce', array($config['nonce']))
->addSetup('setAbsoluteUrl', array($config['absoluteUrl']));

if ($builder->parameters['webloader']['debugger']) {
$compiler->addSetup('@' . $this->prefix('tracyPanel') . '::addLoader', array(
Expand Down
9 changes: 5 additions & 4 deletions WebLoader/Nette/LoaderFactory.php
100644 → 100755
Expand Up @@ -44,7 +44,7 @@ public function createCssLoader($name, $appendLastModified = FALSE)
{
/** @var Compiler $compiler */
$compiler = $this->serviceLocator->getService($this->extensionName . '.css' . ucfirst($name) . 'Compiler');
return new CssLoader($compiler, $this->formatTempPath($name), $appendLastModified);
return new CssLoader($compiler, $this->formatTempPath($name, $compiler->isAbsoluteUrl()), $appendLastModified);
}

/**
Expand All @@ -56,18 +56,19 @@ public function createJavaScriptLoader($name, $appendLastModified = FALSE)
{
/** @var Compiler $compiler */
$compiler = $this->serviceLocator->getService($this->extensionName . '.js' . ucfirst($name) . 'Compiler');
return new JavaScriptLoader($compiler, $this->formatTempPath($name), $appendLastModified);
return new JavaScriptLoader($compiler, $this->formatTempPath($name, $compiler->isAbsoluteUrl()), $appendLastModified);
}

/**
* @param string $name
* @return string
*/
private function formatTempPath($name)
private function formatTempPath($name, $absoluteUrl = FALSE)
{
$lName = strtolower($name);
$tempPath = isset($this->tempPaths[$lName]) ? $this->tempPaths[$lName] : Extension::DEFAULT_TEMP_PATH;
return rtrim($this->httpRequest->getUrl()->basePath, '/') . '/' . $tempPath;
$method = $absoluteUrl ? 'getBaseUrl' : 'getBasePath';
return rtrim($this->httpRequest->getUrl()->{$method}(), '/') . '/' . $tempPath;
}

}

0 comments on commit 9363263

Please sign in to comment.