Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #18742 from jmcanterafonseca/pages_as_shared_resource
Browse files Browse the repository at this point in the history
Bug 1001370 - Add a new type of shared element (pages) for the build sys...
  • Loading branch information
jmcanterafonseca committed Apr 29, 2014
2 parents 6c6f82d + 3de666c commit 5e09ffe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
6 changes: 6 additions & 0 deletions build/test/unit/webapp-shared.test.js
Expand Up @@ -428,6 +428,12 @@ suite('webapp-shared.js', function() {
blockName + '2.css');
});

test('copySharedPage', function() {
var path = 'import/test_page.html';
webappShared.copyPage(path);
assert.equal(result[0].path, 'shared/pages' + '/' + path);
});

teardown(function() {
lsFiles.length = 0;
result.length = 0;
Expand Down
10 changes: 9 additions & 1 deletion build/webapp-optimize.js
Expand Up @@ -605,7 +605,7 @@ function optimize_compile(webapp, file, callback) {
// selecting a language triggers `XMLHttpRequest' and `dispatchEvent' above
debug('localizing: ' + file.path);

// if LOCALE_BASEDIR is set, we're going to show missing strings at
// if LOCALE_BASEDIR is set, we're going to show missing strings at
// buildtime.
var debugL10n = config.LOCALE_BASEDIR != "";

Expand Down Expand Up @@ -724,6 +724,14 @@ function execute(options) {

// optimize all HTML documents in the webapp
let files = utils.ls(webapp.buildDirectoryFile, true, /^(shared|tests?)$/);

// We need to optimize shared pages as well
let sharedPagesDir = webapp.buildDirectoryFile.clone();
sharedPagesDir.append('shared');
sharedPagesDir.append('pages');
let filesSharedPages = utils.ls(sharedPagesDir, true);
files = files.concat(filesSharedPages);

files.forEach(function(file) {
if (/\.html$/.test(file.leafName)) {
filesToProcess.push(file);
Expand Down
32 changes: 31 additions & 1 deletion build/webapp-shared.js
Expand Up @@ -15,7 +15,8 @@ WebappShared.prototype.setOptions = function(options) {
resources: [], // List of resources to copy
styles: [], // List of stable style names to copy
unstable_styles: [], // List of unstable style names to copy
elements: [] // List of elements names to copy
elements: [], // List of elements names to copy,
pages: [] // List of pages to copy
};
this.localesFile = utils.resolve(this.config.LOCALES_FILE,
this.config.GAIA_DIR);
Expand Down Expand Up @@ -154,6 +155,29 @@ WebappShared.prototype.pushJS = function(path) {
this.moveToBuildDir(file, pathInStage);
};

WebappShared.prototype.copyPage = function(path) {
var file = this.gaia.sharedFolder.clone();
file.append('pages');
path.split('/').forEach(function(segment) {
file.append(segment);
});

if (!file.exists()) {
throw new Error('Using inexistent shared page file: ' + path +
' from: ' + webapp.domain);
}

var pathInStage = 'shared/pages/' + path;
this.moveToBuildDir(file, pathInStage);

let extension = utils.getExtension(file.leafName);
// If it is an HTML file we need to check for the referenced shared
// resources
if (extension === 'html') {
this.filterSharedUsage(file);
}
}

WebappShared.prototype.pushResource = function(path) {
let file = this.gaia.sharedFolder.clone();
file.append('resources');
Expand Down Expand Up @@ -249,6 +273,12 @@ WebappShared.prototype.pushFileByType = function(kind, path) {
}

switch (kind) {
case 'pages':
if (this.used.pages.indexOf(path) === -1) {
this.used.pages.push(path);
this.copyPage(path);
}
break;
case 'js':
if (this.used.js.indexOf(path) === -1) {
this.used.js.push(path);
Expand Down

0 comments on commit 5e09ffe

Please sign in to comment.