@@ -160,7 +160,11 @@ public function __construct( $renderAs, $appId = '' ) {
160160 $ web = $ info [1 ];
161161 $ file = $ info [2 ];
162162
163- $ this ->append ( 'cssfiles ' , $ web .'/ ' .$ file . '?v= ' . self ::$ versionHash );
163+ if (substr ($ file , -strlen ('print.css ' )) === 'print.css ' ) {
164+ $ this ->append ( 'printcssfiles ' , $ web .'/ ' .$ file . '?v= ' . self ::$ versionHash );
165+ } else {
166+ $ this ->append ( 'cssfiles ' , $ web .'/ ' .$ file . '?v= ' . self ::$ versionHash );
167+ }
164168 }
165169 }
166170 }
@@ -227,10 +231,35 @@ public function generateAssets() {
227231 }
228232
229233 $ cssFiles = self ::findStylesheetFiles (\OC_Util::$ styles );
230- $ cssHash = self ::hashFileNames ($ cssFiles );
231234
232- if (!file_exists ("$ assetDir/assets/ $ cssHash.css " )) {
233- $ cssFiles = array_map (function ($ item ) {
235+ // differentiate between screen stylesheets and printer stylesheets
236+ $ screenCssFiles = array_filter ($ cssFiles , function ($ cssFile ) {
237+ return substr_compare ($ cssFile [2 ], 'print.css ' , -strlen ('print.css ' )) !== 0 ;
238+ });
239+ $ screenCssAsset = $ this ->generateCssAsset ($ screenCssFiles );
240+
241+ $ printCssFiles = array_filter ($ cssFiles , function ($ cssFile ) {
242+ return substr_compare ($ cssFile [2 ], 'print.css ' , -strlen ('print.css ' )) === 0 ;
243+ });
244+ $ printCssAsset = $ this ->generateCssAsset ($ printCssFiles );
245+
246+ $ this ->append ('jsfiles ' , \OC ::$ server ->getURLGenerator ()->linkTo ('assets ' , "$ jsHash.js " ));
247+ $ this ->append ('cssfiles ' , $ screenCssAsset );
248+ $ this ->append ('printcssfiles ' , $ printCssAsset );
249+ }
250+
251+ /**
252+ * generates a single css asset file from an array of css files if at least one of them has changed
253+ * otherwise it just returns the path to the old asset file
254+ * @param $files
255+ * @return string
256+ */
257+ private function generateCssAsset ($ files ) {
258+ $ assetDir = \OC ::$ server ->getConfig ()->getSystemValue ('assetdirectory ' , \OC ::$ SERVERROOT );
259+ $ hash = self ::hashFileNames ($ files );
260+
261+ if (!file_exists ("$ assetDir/assets/ $ hash.css " )) {
262+ $ files = array_map (function ($ item ) {
234263 $ root = $ item [0 ];
235264 $ file = $ item [2 ];
236265 $ assetPath = $ root . '/ ' . $ file ;
@@ -246,16 +275,17 @@ public function generateAssets() {
246275 $ sourceRoot ,
247276 $ sourcePath
248277 );
249- }, $ cssFiles );
250- $ cssCollection = new AssetCollection ($ cssFiles );
251- $ cssCollection ->setTargetPath ("assets/ $ cssHash.css " );
278+ }, $ files );
279+
280+ $ cssCollection = new AssetCollection ($ files );
281+ $ cssCollection ->setTargetPath ("assets/ $ hash.css " );
252282
253283 $ writer = new AssetWriter ($ assetDir );
254284 $ writer ->writeAsset ($ cssCollection );
285+
255286 }
256287
257- $ this ->append ('jsfiles ' , \OC ::$ server ->getURLGenerator ()->linkTo ('assets ' , "$ jsHash.js " ));
258- $ this ->append ('cssfiles ' , \OC ::$ server ->getURLGenerator ()->linkTo ('assets ' , "$ cssHash.css " ));
288+ return \OC ::$ server ->getURLGenerator ()->linkTo ('assets ' , "$ hash.css " );
259289 }
260290
261291 /**
0 commit comments