[Pkg-javascript-commits] [pdf.js] 144/204: Adds css import preprocessing

David Prévot taffit at moszumanska.debian.org
Sat Oct 25 18:50:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 5b93cc102cc4ab45d28b7abc4230136da27d2e78
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Wed Sep 10 11:10:04 2014 -0500

    Adds css import preprocessing
---
 external/builder/builder.js | 22 +++++++++++++++++-----
 make.js                     | 31 ++++++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/external/builder/builder.js b/external/builder/builder.js
index 044741d..637e35d 100644
--- a/external/builder/builder.js
+++ b/external/builder/builder.js
@@ -123,6 +123,15 @@ function preprocessCSS(mode, source, destination) {
             deprecatedInMozcentral.test(line));
   }
 
+  function expandImports(content, baseUrl) {
+    return content.replace(/^\s*@import\s+url\(([^\)]+)\);\s*$/gm,
+        function(all, url) {
+      var file = path.join(path.dirname(baseUrl), url);
+      var imported = fs.readFileSync(file, 'utf8').toString();
+      return expandImports(imported, file);
+    });
+  }
+
   function removePrefixed(content, hasPrefixedFilter) {
     var lines = content.split(/\r?\n/g);
     var i = 0;
@@ -168,14 +177,17 @@ function preprocessCSS(mode, source, destination) {
     return lines.join('\n');
   }
 
-  if (mode !== 'firefox' && mode !== 'mozcentral') {
+  if (!mode) {
     throw new Error('Invalid CSS preprocessor mode');
   }
 
-  var content = fs.readFileSync(source, 'utf8');
-  var out = removePrefixed(content,
-    mode === 'mozcentral' ? hasPrefixedMozcentral : hasPrefixedFirefox);
-  fs.writeFileSync(destination, out);
+  var content = fs.readFileSync(source, 'utf8').toString();
+  content = expandImports(content, source);
+  if (mode === 'mozcentral' || mode === 'firefox') {
+    content = removePrefixed(content, mode === 'mozcentral' ?
+                             hasPrefixedMozcentral : hasPrefixedFirefox);
+  }
+  fs.writeFileSync(destination, content);
 }
 exports.preprocessCSS = preprocessCSS;
 
diff --git a/make.js b/make.js
index e257c11..278c505 100644
--- a/make.js
+++ b/make.js
@@ -126,7 +126,6 @@ target.generic = function() {
       [COMMON_WEB_FILES, GENERIC_DIR + '/web'],
       ['LICENSE', GENERIC_DIR],
       ['external/webL10n/l10n.js', GENERIC_DIR + '/web'],
-      ['web/viewer.css', GENERIC_DIR + '/web'],
       ['web/compatibility.js', GENERIC_DIR + '/web'],
       ['web/compressed.tracemonkey-pldi-09.pdf', GENERIC_DIR + '/web'],
       ['external/bcmaps/*', GENERIC_DIR + '/web/cmaps/'],
@@ -135,11 +134,16 @@ target.generic = function() {
     preprocess: [
       [BUILD_TARGETS, GENERIC_DIR + BUILD_DIR],
       [COMMON_WEB_FILES_PREPROCESS, GENERIC_DIR + '/web']
+    ],
+    preprocessCSS: [
+      ['generic', 'web/viewer.css',
+       GENERIC_DIR + '/web/viewer.css']
     ]
   };
   builder.build(setup);
 
   cleanupJSSource(GENERIC_DIR + '/web/viewer.js');
+  cleanupCSSSource(GENERIC_DIR + '/web/viewer.css');
 };
 
 target.jsdoc = function() {
@@ -557,6 +561,16 @@ function cleanupJSSource(file) {
   content.to(file);
 }
 
+function cleanupCSSSource(file) {
+  var content = cat(file);
+
+  // Strip out all license headers in the middle.
+  var reg = /\n\/\* Copyright(.|\n)*?Mozilla Foundation(.|\n)*?\*\//g;
+  content = content.replace(reg, '');
+
+  content.to(file);
+}
+
 //
 // make minified
 // Builds the minified production viewer that should be compatible with most
@@ -588,7 +602,6 @@ target.minified = function() {
     defines: defines,
     copy: [
       [COMMON_WEB_FILES, MINIFIED_DIR + '/web'],
-      ['web/viewer.css', MINIFIED_DIR + '/web'],
       ['web/compressed.tracemonkey-pldi-09.pdf', MINIFIED_DIR + '/web'],
       ['external/bcmaps/*', MINIFIED_DIR + '/web/cmaps'],
       ['web/locale', MINIFIED_DIR + '/web']
@@ -596,10 +609,16 @@ target.minified = function() {
     preprocess: [
       [BUILD_TARGETS, MINIFIED_DIR + BUILD_DIR],
       [COMMON_WEB_FILES_PREPROCESS, MINIFIED_DIR + '/web']
+    ],
+    preprocessCSS: [
+      ['minified', 'web/viewer.css',
+       MINIFIED_DIR + '/web/viewer.css']
     ]
   };
   builder.build(setup);
 
+  cleanupCSSSource(MINIFIED_DIR + '/web/viewer.css');
+
   var viewerFiles = [
     'web/compatibility.js',
     'external/webL10n/l10n.js',
@@ -750,6 +769,7 @@ target.firefox = function() {
   cleanupJSSource(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.js');
   cleanupJSSource(FIREFOX_BUILD_DIR + 'bootstrap.js');
   cleanupJSSource(FIREFOX_BUILD_CONTENT_DIR + 'PdfjsChromeUtils.jsm');
+  cleanupCSSSource(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.css');
 
   // Remove '.DS_Store' and other hidden files
   find(FIREFOX_BUILD_DIR).forEach(function(file) {
@@ -872,6 +892,7 @@ target.mozcentral = function() {
   cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/web/viewer.js');
   cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/PdfJs.jsm');
   cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/PdfjsChromeUtils.jsm');
+  cleanupCSSSource(MOZCENTRAL_CONTENT_DIR + '/web/viewer.css');
 
   // Remove '.DS_Store' and other hidden files
   find(MOZCENTRAL_DIR).forEach(function(file) {
@@ -982,18 +1003,22 @@ target.chromium = function() {
        CHROME_BUILD_DIR],
       ['extensions/chromium/pageAction/*.*', CHROME_BUILD_DIR + '/pageAction'],
       ['external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web'],
-      ['web/viewer.css', CHROME_BUILD_CONTENT_DIR + '/web'],
       ['external/bcmaps/*', CHROME_BUILD_CONTENT_DIR + '/web/cmaps'],
       ['web/locale', CHROME_BUILD_CONTENT_DIR + '/web']
     ],
     preprocess: [
       [BUILD_TARGETS, CHROME_BUILD_CONTENT_DIR + BUILD_DIR],
       [COMMON_WEB_FILES_PREPROCESS, CHROME_BUILD_CONTENT_DIR + '/web']
+    ],
+    preprocessCSS: [
+      ['chrome', 'web/viewer.css',
+       CHROME_BUILD_CONTENT_DIR + '/web/viewer.css']
     ]
   };
   builder.build(setup);
 
   cleanupJSSource(CHROME_BUILD_CONTENT_DIR + '/web/viewer.js');
+  cleanupCSSSource(CHROME_BUILD_CONTENT_DIR + '/web/viewer.css');
 
   // Update the build version number
   sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list