Skip to content
This repository was archived by the owner on Jun 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
topNode.children().first().children('[text=Content]').length == 0) {
topNode = topNode.children().first();
}
var bodyNode = new Outline(topNode, siteTitle, new HtmlGenerator(), '', '', 'html', []);
var htmlPages = bodyNode.process();
var bodyNode = new Outline(topNode, '', '', 'html', []);
var htmlPages = bodyNode.process(siteTitle, new HtmlGenerator());

var zip = new JSZip();
htmlPages.forEach(function (page) {
Expand Down
33 changes: 19 additions & 14 deletions src/outline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Outline = function (node, siteTitle, generator, title, fileName, filePath, parentNavigationObject) {
var Outline = function (node, title, fileName, filePath, parentNavigationObject) {
var navigationObject = parentNavigationObject.map(function (navBar) {
return navBar.map(function (link) {
return {
Expand All @@ -11,7 +11,7 @@
var htmlPages = [];
var navLevel = parentNavigationObject.length;

this.process = function () {
this.process = function (siteTitle, generator) {
var childPages = getChildPages();
updateNavigationObject(childPages);
if (isPage(title)) {
Expand All @@ -20,7 +20,7 @@
content: generator.generate(node, siteTitle, title, navigationObject, navLevel)
});
}
processChildren(childPages);
processChildren(childPages, siteTitle, generator);
return htmlPages;
};

Expand All @@ -29,18 +29,23 @@
$.each($(node).children(), function (index, child) {
var childTitle = getTitle(child);
if (isPage(childTitle)) {
if (childTitle[0] == '[') {
$.each(childTitle.substring(1, childTitle.length - 1).split(','), function(index, subTitle) {
pages.push({ title: subTitle, fileName: stripText(subTitle, true).toLowerCase(), node: child });
});
} else {
pages.push({ title: childTitle, fileName: stripText(childTitle, true).toLowerCase(), node: child });
}
getChildTitles(childTitle).map(function(subTitle) {
pages.push({ title: subTitle, fileName: stripText(subTitle, true).toLowerCase(), node: child });
});
}
});
return pages;
};

function getChildTitles(childTitle) {
if (childTitle[0] == '[') {
return childTitle.substring(1, childTitle.length - 1).split(',')
} else {
return [childTitle];
}
}


function updateNavigationObject(childPages) {
if (childPages.length > 0) {
navigationObject.push(childPages.map(function (childPage) {
Expand All @@ -49,11 +54,11 @@
}
};

function processChildren(childPages) {
function processChildren(childPages, siteTitle, generator) {
$.each(childPages, function (index, childPage) {
var path = fileName ? filePath + '/' + fileName : filePath;
var outline = new Outline(childPage.node, siteTitle, generator, childPage.title, childPage.fileName, path, navigationObject);
htmlPages = htmlPages.concat(outline.process());
var outline = new Outline(childPage.node, childPage.title, childPage.fileName, path, navigationObject);
htmlPages = htmlPages.concat(outline.process(siteTitle, generator));
});
};
};
};
27 changes: 13 additions & 14 deletions test/outline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@ describe('outline', function() {
'<outline text="~Ignore" />' +
'</body>' +
'</opml>';
var generator = {
generate: function(node, siteTitle, title, navigationObject, navLevel) {
return arguments;
}
};

outline = new Outline(
$($.parseXML(opml)).find('body'),
'Site Title',
generator,
'Page Title',
'pageTitle',
'/path/to',
'Page Title',
'pageTitle',
'/path/to',
[[
{
displayText: 'Home',
Expand All @@ -46,9 +40,14 @@ describe('outline', function() {
});

describe('process', function() {
var generator = {
generate: function(node, siteTitle, title, navigationObject, navLevel) {
return arguments;
}
};
var result;
beforeEach(function() {
result = outline.process();
result = outline.process('Site Title', generator);
});

it('returns a list of html pages with structured file paths', function() {
Expand All @@ -65,18 +64,18 @@ describe('outline', function() {
expect(titleForPage(2)).toEqual('Footer - tag');
expect(titleForPage(3)).toEqual('Print');
});

it('calls the generator with the navigation object for the page', function() {
expect(navObjectForPage(0).length).toEqual(2);
expect(navObjectForPage(3)[2][0].path).toEqual('../footertag/print.html');
});

it('sets the selected state of parent pages in the navigation object', function() {
expect(navObjectForPage(3)[0][0].selected).toEqual(true);
expect(navObjectForPage(3)[1][1].selected).toEqual(true);
expect(navObjectForPage(3)[2][0].selected).toEqual(true);
});

it('calls the generator with the navigation level of the page', function() {
expect(navLevelForPage(0)).toEqual(1);
expect(navLevelForPage(1)).toEqual(2);
Expand Down