Skip to content

Commit

Permalink
Add back property "output" to page/template context
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Jul 4, 2016
1 parent ea3afbe commit e105983
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 29 deletions.
12 changes: 6 additions & 6 deletions lib/json/encodeBookWithPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ var encodePage = require('./encodePage');
var encodeFile = require('./encodeFile');

/**
Return a JSON representation of a book with a specific file
@param {Book} output
@param {Page} page
@return {Object}
*/
* Return a JSON representation of a book with a specific file
*
* @param {Book} output
* @param {Page} page
* @return {Object}
*/
function encodeBookWithPage(book, page) {
var file = page.getFile();

Expand Down
10 changes: 5 additions & 5 deletions lib/json/encodeOutput.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var encodeBook = require('./encodeBook');

/**
Encode an output to JSON
@param {Output}
@return {Object}
*/
* Encode an output to JSON
*
* @param {Output}
* @return {Object}
*/
function encodeOutputToJson(output) {
var book = output.getBook();
var generator = output.getGenerator();
Expand Down
23 changes: 23 additions & 0 deletions lib/json/encodeOutputWithPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var encodeOutput = require('./encodeOutput');
var encodePage = require('./encodePage');
var encodeFile = require('./encodeFile');

/**
* Return a JSON representation of a book with a specific file
*
* @param {Book} output
* @param {Page} page
* @return {Object}
*/
function encodeOutputWithPage(output, page) {
var file = page.getFile();
var book = output.getBook();

var result = encodeOutput(output);
result.page = encodePage(page, book.getSummary());
result.file = encodeFile(file);

return result;
}

module.exports = encodeOutputWithPage;
1 change: 1 addition & 0 deletions lib/json/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
encodeOutput: require('./encodeOutput'),
encodeBookWithPage: require('./encodeBookWithPage'),
encodeOutputWithPage: require('./encodeOutputWithPage'),
encodeBook: require('./encodeBook'),
encodeFile: require('./encodeFile'),
encodePage: require('./encodePage'),
Expand Down
14 changes: 7 additions & 7 deletions lib/output/generatePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ var createTemplateEngine = require('./createTemplateEngine');
var callPageHook = require('./callPageHook');

/**
Prepare and generate HTML for a page
@param {Output} output
@param {Page} page
@return {Promise<Page>}
*/
* Prepare and generate HTML for a page
*
* @param {Output} output
* @param {Page} page
* @return {Promise<Page>}
*/
function generatePage(output, page) {
var book = output.getBook();
var engine = createTemplateEngine(output);
Expand All @@ -27,7 +27,7 @@ function generatePage(output, page) {
var file = resultPage.getFile();
var filePath = file.getPath();
var parser = file.getParser();
var context = JSONUtils.encodeBookWithPage(book, resultPage);
var context = JSONUtils.encodeOutputWithPage(output, resultPage);

if (!parser) {
return Promise.reject(error.FileNotParsableError({
Expand Down
10 changes: 5 additions & 5 deletions lib/output/json/onPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ var getModifiers = require('../getModifiers');
var JSON_VERSION = '3';

/**
Write a page as a json file
@param {Output} output
@param {Page} page
*/
* Write a page as a json file
*
* @param {Output} output
* @param {Page} page
*/
function onPage(output, page) {
var file = page.getFile();
var readme = output.getBook().getReadme().getFile();
Expand Down
12 changes: 6 additions & 6 deletions lib/output/website/onPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ var createTemplateEngine = require('./createTemplateEngine');
var fileToOutput = require('../helper/fileToOutput');

/**
Write a page as a json file
@param {Output} output
@param {Page} page
*/
* Write a page as a json file
*
* @param {Output} output
* @param {Page} page
*/
function onPage(output, page) {
var options = output.getOptions();
var prefix = options.get('prefix');
Expand All @@ -40,7 +40,7 @@ function onPage(output, page) {
return Modifiers.modifyHTML(page, getModifiers(output, page))
.then(function(resultPage) {
// Generate the context
var context = JSONUtils.encodeBookWithPage(output.getBook(), resultPage);
var context = JSONUtils.encodeOutputWithPage(output, resultPage);
context.plugins = {
resources: Plugins.listResources(plugins, resources).toJS()
};
Expand Down

0 comments on commit e105983

Please sign in to comment.