From 814b6ff489bc1f0bfd03db6409d49185e8c7b93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 25 Apr 2016 11:05:06 +0200 Subject: [PATCH] Complete json format --- lib/json/encodeBook.js | 4 +--- lib/json/encodeConfig.js | 12 ------------ lib/json/encodeFile.js | 7 ++++++- lib/json/encodeSummaryArticle.js | 3 +++ lib/json/index.js | 3 +-- lib/models/summaryArticle.js | 15 ++++++++++++++- lib/plugins/validateConfig.js | 4 ++-- 7 files changed, 27 insertions(+), 21 deletions(-) delete mode 100644 lib/json/encodeConfig.js diff --git a/lib/json/encodeBook.js b/lib/json/encodeBook.js index eed5e5f3b..6c1b023b1 100644 --- a/lib/json/encodeBook.js +++ b/lib/json/encodeBook.js @@ -1,7 +1,6 @@ var encodeSummary = require('./encodeSummary'); var encodeGlossary = require('./encodeGlossary'); var encodeReadme = require('./encodeReadme'); -var encodeConfig = require('./encodeConfig'); /** Encode a book to JSON @@ -13,8 +12,7 @@ function encodeBookToJson(book) { return { summary: encodeSummary(book.getSummary()), glossary: encodeGlossary(book.getGlossary()), - readme: encodeReadme(book.getReadme()), - config: encodeConfig(book.getConfig()) + readme: encodeReadme(book.getReadme()) }; } diff --git a/lib/json/encodeConfig.js b/lib/json/encodeConfig.js deleted file mode 100644 index 195d43bac..000000000 --- a/lib/json/encodeConfig.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - Encode configuration to JSON - - @param {Config} - @return {Object} -*/ -function encodeConfig(config) { - var values = config.getValues(); - return values.toJS(); -} - -module.exports = encodeConfig; diff --git a/lib/json/encodeFile.js b/lib/json/encodeFile.js index 03b34505c..d2c9e8a7d 100644 --- a/lib/json/encodeFile.js +++ b/lib/json/encodeFile.js @@ -6,8 +6,13 @@ @return {Object} */ function encodeFileToJson(file) { + var filePath = file.getPath(); + if (!filePath) { + return undefined; + } + return { - path: file.getPath(), + path: filePath, mtime: file.getMTime(), type: file.getType() }; diff --git a/lib/json/encodeSummaryArticle.js b/lib/json/encodeSummaryArticle.js index 485d20990..b3f977afe 100644 --- a/lib/json/encodeSummaryArticle.js +++ b/lib/json/encodeSummaryArticle.js @@ -10,6 +10,9 @@ function encodeSummaryArticle(article) { title: article.getTitle(), level: article.getLevel(), depth: article.getDepth(), + anchor: article.getAnchor(), + url: article.getUrl(), + path: article.getPath(), articles: article.getArticles() .map(encodeSummaryArticle).toJS() }; diff --git a/lib/json/index.js b/lib/json/index.js index a026a7fc6..92b105a34 100644 --- a/lib/json/index.js +++ b/lib/json/index.js @@ -5,6 +5,5 @@ module.exports = { encodeFile: require('./encodeFile'), encodePage: require('./encodePage'), encodeSummary: require('./encodeSummary'), - encodeReadme: require('./encodeReadme'), - encodeConfig: require('./encodeConfig') + encodeReadme: require('./encodeReadme') }; diff --git a/lib/models/summaryArticle.js b/lib/models/summaryArticle.js index e3d85ef50..945a16caa 100644 --- a/lib/models/summaryArticle.js +++ b/lib/models/summaryArticle.js @@ -54,6 +54,10 @@ SummaryArticle.prototype.getByLevel = function(level) { @return {String} */ SummaryArticle.prototype.getPath = function() { + if (this.isExternal()) { + return undefined; + } + var ref = this.getRef(); var parts = ref.split('#'); @@ -63,6 +67,15 @@ SummaryArticle.prototype.getPath = function() { return location.normalize(pathname); }; +/** + Return url if article is external + + @return {String} +*/ +SummaryArticle.prototype.getUrl = function() { + return this.isExternal()? this.getRef() : undefined; +}; + /** Get anchor for this article (or undefined) @@ -72,7 +85,7 @@ SummaryArticle.prototype.getAnchor = function() { var ref = this.getRef(); var parts = ref.split('#'); - var anchor = (parts.length > 1? '#' + parts[parts.length - 1] : null); + var anchor = (parts.length > 1? '#' + parts[parts.length - 1] : undefined); return anchor; }; diff --git a/lib/plugins/validateConfig.js b/lib/plugins/validateConfig.js index fc32344fb..cb6c38a3a 100644 --- a/lib/plugins/validateConfig.js +++ b/lib/plugins/validateConfig.js @@ -32,7 +32,7 @@ function validatePluginConfig(book, plugin) { // Validate and throw if invalid var v = new jsonschema.Validator(); - var result = v.validate(config, schema, { + var result = v.validate(pluginConfig, schema, { propertyName: configKey }); @@ -43,7 +43,7 @@ function validatePluginConfig(book, plugin) { // Insert default values var defaults = jsonSchemaDefaults(schema); - pluginConfig = mergeDefaults(config, defaults); + pluginConfig = mergeDefaults(pluginConfig, defaults); // Update configuration