[MediaWiki-commits] [Gerrit] Render attribution page - change (mediawiki...latex_renderer)

2014-07-29 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Render attribution page
..


Render attribution page

Change-Id: I4e6c3b6d92088fe1a600ddb35eed66abfa630327
---
M lib/index.js
1 file changed, 54 insertions(+), 16 deletions(-)

Approvals:
  Cscott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/index.js b/lib/index.js
index 772f416..1d39b00 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -112,7 +112,12 @@
// Set the default font
\\setmainfont[ + (SCRIPT_FONTS['default'].options||'') + ]{ + 
SCRIPT_FONTS['default'].name + },
\\newcommand{\\LTRfont}{},
-   \\newcommand{\\textsmall}[1]{\\small #1},
+   \\newcommand{\\textsmall}[1]{{\\small #1}},
+   // smaller size, one column for attributions
+   \\newcommand{\\attributions}{ +
+   \\renewcommand{\\textsmall}[1]{{\\scriptsize ##1}} +
+   \\footnotesize\\onecolumn +
+   },
 
\\date{}\\author{}
 ].join(\n);
@@ -723,7 +728,9 @@
 // Don't allow them in single item collections, as the article class doesn't
 // allow \chapters
 Visitor.prototype.visitHn = function(node, n) {
-   if (!this.options.hasChapters) { n -= 1; }
+   if (this.options.isAttribution) {
+   if (this.options.hasChapters) { n -= 1; }
+   } else if (!this.options.hasChapters) { n -= 1; }
if (this.options.singleItem  n === 0) {
/* the article class doesn't allow chapters */
return;
@@ -1436,7 +1443,8 @@
 // files have been written.
 var generateLatex = function(metabook, builddir, imagemap, options) {
var status = options.status;
-   status.createStage(countItems(metabook), 'Processing collection');
+   // add one to the item count to accomodate attribution 'chapter'
+   status.createStage(countItems(metabook)+1, 'Processing collection');
status.report(null, metabook.title);
 
var output = fs.createWriteStream(path.join(builddir, 'output.tex'), {
@@ -1509,16 +1517,22 @@
);
var write = {};
write.article = function(item) {
-   console.assert(item.type === 'article');
-   status.report('Processing article', item.title);
+   var isAttribution = (item.type === 'attribution');
+   console.assert(item.type === 'article' || isAttribution);
+   status.report('Processing', item.type, item.title);
var revid = item.revision;
var document, base = '', articleLanguage;
var key = (item.wiki ? (item.wiki+'|') : '') + revid;
var outfile = path.join(
-   builddir, 'latex', item.wiki + '-' + revid + '.tex'
+   builddir, 'latex',
+   isAttribution ? 'attribution.tex' :
+   (item.wiki + '-' + revid + '.tex')
);
output.write('\\input{' + outfile + '}\n');
-   return pdb.get(key, 'nojson').then(function(data) {
+   var pContents = isAttribution ?
+   P.call(fs.readFile, fs, item.filename, { encoding: 
'utf8' }) :
+   pdb.get(key, 'nojson');
+   return pContents.then(function(data) {
document = domino.createDocument(data);
var baseElem = document.querySelector('head  
base[href]');
if (baseElem) {
@@ -1542,14 +1556,17 @@
singleItem: singleItem,
hasChapters: hasChapters,
lang: collectionLanguage,
-   dir: collectionDir
+   dir: collectionDir,
+   isAttribution: isAttribution
});
-   var h1 = document.createElement('h1');
-   var span = document.createElement('span');
-   h1.appendChild(span);
-   span.textContent = item.title;
-   span.lang = articleLanguage;
-   visitor.visit(h1); // emit document title!
+   if (!isAttribution) {
+   var h1 = document.createElement('h1');
+   var span = document.createElement('span');
+   h1.appendChild(span);
+   span.textContent = item.title;
+   span.lang = articleLanguage;
+   visitor.visit(h1); // emit document title!
+   }
document.body.lang = document.body.lang || 
articleLanguage;
document.body.dir = document.body.dir ||
Polyglossia.lookup(document.body.lang).dir;
@@ -1573,7 +1590,26 

[MediaWiki-commits] [Gerrit] Render attribution page - change (mediawiki...latex_renderer)

2014-07-23 Thread Mwalker (Code Review)
Mwalker has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/148611

Change subject: Render attribution page
..

Render attribution page

Change-Id: I4e6c3b6d92088fe1a600ddb35eed66abfa630327
---
M lib/index.js
1 file changed, 44 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
 refs/changes/11/148611/1

diff --git a/lib/index.js b/lib/index.js
index 49b9ba9..f72d39a 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1289,7 +1289,7 @@
// record the final filename
pp = pp.then(function(info) {
imagemap.set(key, info.filename);
-   });
+   } ).catch(function(err) {});
p = Promise.join(p, pp); // serialize completion
}).then(function() {
// wait for the queued image renames/conversions/etc.
@@ -1340,7 +1340,7 @@
// book or article?
var hasChapters =
metabook.items.some(function(it) { return it.type === 
'chapter'; });
-   var singleItem = (!hasChapters)  metabook.items.length = 1;
+   var singleItem = (!hasChapters)  metabook.items.length = 2;
if (!singleItem) {
head = head.replace(/\]\{article\}/, ']{report}');
}
@@ -1448,6 +1448,48 @@
output.write('\\chapter{' + texEscape(item.title) + '}\n');
return P.forEachSeq(item.items, write.article);
};
+   write.attribution = function(item) {
+   console.assert(item.type === 'attribution');
+   status.report('Processing attribution');
+   if ('columns' in item  columns !== item.columns) {
+   columns = item.columns;
+   output.write(columns === 1 ? '\\onecolumn\n' : 
'\\twocolumn\n');
+   }
+   var outfile = path.join(builddir, 'latex', 'attribution.tex');
+   var document;
+
+   output.write('\\input{' + outfile + '}\n');
+   return P.call(fs.readFile, fs, path.join(builddir, 'bundle', 
item.file))
+   .then(function(fileContents) {
+   document = domino.createDocument(fileContents);
+   // We know the attribution is coming from the 
zeroth wiki
+   return sidb.get(metabook.wikis[0].baseurl);
+   }).then(function(siteinfo) {
+   var attributionLanguage = siteinfo.general.lang 
|| collectionLanguage;
+   var collectionDir = 
Polyglossia.lookup(collectionLanguage).dir;
+   var format = new Formatter(
+   fs.createWriteStream(outfile, { 
encoding: 'utf8' }), {
+   dir: collectionDir
+   });
+   var visitor = new Visitor(document, format, {
+   base: '',
+   imagemap: imagemap,
+   singleItem: singleItem,
+   hasChapters: hasChapters,
+   lang: collectionLanguage,
+   dir: collectionDir
+   });
+   document.body.lang = document.body.lang || 
attributionLanguage;
+   document.body.dir = document.body.dir ||
+   
Polyglossia.lookup(document.body.lang).dir;
+   visitor.visit(document.body);
+   visitor.usedLanguages.forEach(function(l){ 
usedLanguages.add(l); });
+   format.paragraphBreak();
+   return format.flush().then(function() {
+   return P.call(format.stream.end, 
format.stream, '');
+   });
+   });
+   };
 
return P.forEachSeq(metabook.items, function(item) {
return write[item.type](item);

-- 
To view, visit https://gerrit.wikimedia.org/r/148611
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4e6c3b6d92088fe1a600ddb35eed66abfa630327
Gerrit-PatchSet: 1
Gerrit-Project: 
mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
Gerrit-Branch: master
Gerrit-Owner: Mwalker mwal...@wikimedia.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits