Skip to content

Commit

Permalink
Add list of URLs used to end of EpubItem
Browse files Browse the repository at this point in the history
  • Loading branch information
dteviot committed Nov 4, 2017
1 parent ae7ed77 commit 5b4d59a
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 8 deletions.
4 changes: 4 additions & 0 deletions plugin/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
"message": "Include URL of Images",
"description": "Label for checkbox to record source URL of images into EPUB (in Advanced settings)."
},
"__MSG_label_Include_List_Of_Fetched_URLs__": {
"message": "Include list of fetched URLs",
"description": "Label for checkbox to add list of fetched URLs to end of EPUB (in Advanced settings)."
},
"__MSG_label_Language__": {
"message": "Language",
"description": "Label in front input for language EPUB will be in"
Expand Down
27 changes: 20 additions & 7 deletions plugin/js/EpubItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
type: XHTML or image
sourceUrl: where the html came from
id: the id value in the content.opf file
directory: subdirectory in ZIP that will hold the item
optional members:
nodes: list of nodes that make up the content (if it's XHTML content)
*/
"use strict";

class EpubItem {
constructor(sourceUrl) {
constructor(sourceUrl, directory) {
this.sourceUrl = sourceUrl;
this.isInSpine = true;
this.chapterTitle = null;
this.directory = directory || "OEBPS/Text/";
}

setIndex(index) {
Expand All @@ -23,8 +25,7 @@ class EpubItem {

// name of the item in the zip.
getZipHref() {
let that = this;
return util.makeStorageFileName("OEBPS/Text/", that.index, that.chapterTitle, "xhtml");
return util.makeStorageFileName(this.directory, this.index, this.chapterTitle, "xhtml");
}

getId() {
Expand Down Expand Up @@ -87,6 +88,19 @@ class EpubItem {
};
};
}

makeSummaryRow(doc) {
let row = doc.createElementNS(util.XMLNS, "tr");
this.addColumn(doc, row, this.sourceUrl);
this.addColumn(doc, row, this.getZipHref());
return row;
}

addColumn(doc, row, textContent) {
let header = doc.createElementNS(util.XMLNS, "td");
header.textContent = textContent;
row.appendChild(header);
}
}

//==============================================================
Expand Down Expand Up @@ -134,7 +148,7 @@ class ChapterEpubItem extends EpubItem {
*/
class ImageInfo extends EpubItem {
constructor(wrappingUrl, index, sourceUrl, dataOrigFileUrl) {
super(sourceUrl);
super(sourceUrl, "OEBPS/Images/");
super.index = index;
super.isInSpine = false;
this.wrappingUrl = wrappingUrl;
Expand All @@ -148,9 +162,8 @@ class ImageInfo extends EpubItem {
}

getZipHref() {
let that = this;
let suffix = that.findImageSuffix(that.wrappingUrl);
return util.makeStorageFileName("OEBPS/Images/", that.index, that.getImageName(that.wrappingUrl), suffix);
let suffix = this.findImageSuffix(this.wrappingUrl);
return util.makeStorageFileName(this.directory, this.index, this.getImageName(this.wrappingUrl), suffix);
}

getId() {
Expand Down
36 changes: 36 additions & 0 deletions plugin/js/EpubItemSupplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,40 @@ class EpubItemSupplier {
hasCoverImageFile() {
return (this.coverImageInfo != null);
}

addTableOfFetchedUrls() {
let item = new EpubItem(null, "OEBPS/WebToEpub/");
item.isInSpine = true;
item.chapterTitle = "URLs fetched";
let table = this.createTableOfFetchedUrls();
let title = table.ownerDocument.createElementNS(util.XMLNS, "h1");
title.textContent = item.chapterTitle;
let style = table.ownerDocument.createElementNS(util.XMLNS, "style");
style.textContent = `table { border-collapse: collapse; }
table, th, td { border: 1px solid black; }`;
item.nodes = [ style, title, table ];
item.setIndex(this.epubItems.length);
this.epubItems.push(item)
}

createTableOfFetchedUrls() {
let doc = util.createEmptyXhtmlDoc();
let table = doc.createElementNS(util.XMLNS, "table");
let body = doc.getElementsByTagName("body")[0];
body.appendChild(table);
let row = doc.createElementNS(util.XMLNS, "tr");
table.appendChild(row);
this.addHeader(doc, row, "URL");
this.addHeader(doc, row, "File in EPUB");
for(let item of this.epubItems) {
table.appendChild(item.makeSummaryRow(doc));
};
return table;
}

addHeader(doc, row, textContent) {
let header = doc.createElementNS(util.XMLNS, "th");
header.textContent = textContent;
row.appendChild(header);
}
}
1 change: 1 addition & 0 deletions plugin/js/UserPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class UserPreferences {
this.addPreference("writeErrorHistoryToFile", "writeErrorHistoryToFileCheckbox", false);
this.addPreference("createEpub3", "createEpub3Checkbox", false);
this.addPreference("chaptersPageInChapterList", "chaptersPageInChapterListCheckbox", false);
this.addPreference("listFetchedUrls", "listFetchedUrlsCheckbox", false);

this.observers = [];
};
Expand Down
6 changes: 5 additions & 1 deletion plugin/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ var main = (function () {
function packEpub(metaInfo) {
let epubVersion = epubVersionFromPreferences();
let epub = new EpubPacker(metaInfo, epubVersion);
return epub.assemble(parser.epubItemSupplier());
let supplier = parser.epubItemSupplier();
if (userPreferences.listFetchedUrls.value) {
supplier.addTableOfFetchedUrls();
}
return epub.assemble(supplier);
}

function dumpErrorLogToFile() {
Expand Down
4 changes: 4 additions & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
<td><input id="chaptersPageInChapterListCheckbox" type="checkbox" name="chaptersPageInChapterListbox" value="false"></td>
<td>__MSG_label_Chapters_Page_In_Chapters_List__</td>
</tr>
<tr id="listFetchedUrlsRow">
<td><input id="listFetchedUrlsCheckbox" type="checkbox" name="listFetchedUrlsListbox" value="false"></td>
<td>__MSG_label_Include_List_Of_Fetched_URLs__</td>
</tr>
<tr id="developerStuffRow">
<td>__MSG_label_Developer_Stuff__</td>
<td>
Expand Down
1 change: 1 addition & 0 deletions unitTest/Tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<script src='UtestUtil.js'></script>
<script src='UtestDownload.js'></script>
<script src='UtestEpubItem.js'></script>
<script src='UtestEpubItemSupplier.js'></script>
<script src='UtestEpubPacker.js'></script>
<script src='UtestChapterUrlsUI.js'></script>
<script src='UtestHttpClient.js'></script>
Expand Down
26 changes: 26 additions & 0 deletions unitTest/UtestEpubItemSupplier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

"use strict";

module("EpubItemsupplier");

QUnit.test("createSummary", function (assert) {
let imageInfo = new ImageInfo("http://dummy/cover.png", 0, "http://dummy/cover.png");
imageInfo.width = 400;
imageInfo.height = 600;
imageInfo.isCover = true;
let dummyImageCollector = {
userPreferences: makeDummyUserPreferences(true, true),
coverImageInfo: imageInfo,
imagesToPackInEpub: function () { return [imageInfo]; }
};
let epubItem = new EpubItem("http://testing/c1.html");
epubItem.chapterTitle = "ChapterOne";
epubItem.setIndex(1);
let itemSupplier = new EpubItemSupplier(null, [epubItem], dummyImageCollector);
let table = itemSupplier.createTableOfFetchedUrls().outerHTML;
assert.equal(table, "<table xmlns=\""+ util.XMLNS + "\">" +
"<tr><th>URL</th><th>File in EPUB</th></tr>"+
"<tr><td>http://dummy/cover.png</td><td>OEBPS/Images/0000_cover.png</td></tr>"+
"<tr><td>http://testing/c1.html</td><td>OEBPS/Text/0001_ChapterOne.xhtml</td></tr>"+
"</table>")
});

0 comments on commit 5b4d59a

Please sign in to comment.