Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/templates/layout.base.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path('', 'favicon-touch.png')); ?>">
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('', 'favicon-mask.svg')); ?>" color="#1d2d44">
<?php foreach ($_['cssfiles'] as $cssfile): ?>
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="screen">
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>">
<?php endforeach; ?>
<?php foreach($_['printcssfiles'] as $cssfile): ?>
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print">
<?php endforeach; ?>
<?php foreach ($_['jsfiles'] as $jsfile): ?>
<script src="<?php print_unescaped($jsfile); ?>"></script>
Expand Down
5 changes: 4 additions & 1 deletion core/templates/layout.guest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path('', 'favicon-touch.png')); ?>">
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('', 'favicon-mask.svg')); ?>" color="#1d2d44">
<?php foreach($_['cssfiles'] as $cssfile): ?>
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="screen">
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>">
<?php endforeach; ?>
<?php foreach($_['printcssfiles'] as $cssfile): ?>
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print">
<?php endforeach; ?>
<?php foreach($_['jsfiles'] as $jsfile): ?>
<script src="<?php print_unescaped($jsfile); ?>"></script>
Expand Down
5 changes: 4 additions & 1 deletion core/templates/layout.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path($_['appid'], 'favicon-touch.png')); ?>">
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path($_['appid'], 'favicon-mask.svg')); ?>" color="#1d2d44">
<?php foreach($_['cssfiles'] as $cssfile): ?>
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="screen">
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>">
<?php endforeach; ?>
<?php foreach($_['printcssfiles'] as $cssfile): ?>
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print">
<?php endforeach; ?>
<?php foreach($_['jsfiles'] as $jsfile): ?>
<script src="<?php print_unescaped($jsfile); ?>"></script>
Expand Down
48 changes: 39 additions & 9 deletions lib/private/templatelayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ public function __construct( $renderAs, $appId = '' ) {
$web = $info[1];
$file = $info[2];

$this->append( 'cssfiles', $web.'/'.$file . '?v=' . self::$versionHash);
if (substr($file, -strlen('print.css')) === 'print.css') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be documented in the app developer documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this to the css documentation as soon as this is merged.

$this->append( 'printcssfiles', $web.'/'.$file . '?v=' . self::$versionHash);
} else {
$this->append( 'cssfiles', $web.'/'.$file . '?v=' . self::$versionHash);
}
}
}
}
Expand Down Expand Up @@ -249,10 +253,35 @@ public function generateAssets() {
}

$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
$cssHash = self::hashFileNames($cssFiles);

if (!file_exists("$assetDir/assets/$cssHash.css")) {
$cssFiles = array_map(function ($item) {
// differentiate between screen stylesheets and printer stylesheets
$screenCssFiles = array_filter($cssFiles, function($cssFile) {
return substr_compare($cssFile[2], 'print.css', -strlen('print.css')) !== 0;
});
$screenCssAsset = $this->generateCssAsset($screenCssFiles);

$printCssFiles = array_filter($cssFiles, function($cssFile) {
return substr_compare($cssFile[2], 'print.css', -strlen('print.css')) === 0;
});
$printCssAsset = $this->generateCssAsset($printCssFiles);

$this->append('jsfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$jsHash.js"));
$this->append('cssfiles', $screenCssAsset);
$this->append('printcssfiles', $printCssAsset);
}

/**
* generates a single css asset file from an array of css files if at least one of them has changed
* otherwise it just returns the path to the old asset file
* @param $files
* @return string
*/
private function generateCssAsset($files) {
$assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT);
$hash = self::hashFileNames($files);

if (!file_exists("$assetDir/assets/$hash.css")) {
$files = array_map(function ($item) {
$root = $item[0];
$file = $item[2];
$assetPath = $root . '/' . $file;
Expand All @@ -268,16 +297,17 @@ public function generateAssets() {
$sourceRoot,
$sourcePath
);
}, $cssFiles);
$cssCollection = new AssetCollection($cssFiles);
$cssCollection->setTargetPath("assets/$cssHash.css");
}, $files);

$cssCollection = new AssetCollection($files);
$cssCollection->setTargetPath("assets/$hash.css");

$writer = new AssetWriter($assetDir);
$writer->writeAsset($cssCollection);

}

$this->append('jsfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$jsHash.js"));
$this->append('cssfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$cssHash.css"));
return \OC::$server->getURLGenerator()->linkTo('assets', "$hash.css");
}

/**
Expand Down