Skip to content

Commit

Permalink
fix(report): epub url is given as relative by default
Browse files Browse the repository at this point in the history
This is configurable in the config file, under "report".

Fixes #64
  • Loading branch information
marisademeglio committed Dec 24, 2017
1 parent ad66779 commit c7bfe03
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/ace-core/src/core/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function ace(epubPath, options) {
epub.extract()
.then(() => epub.parse())
// initialize the report
.then(() => new Report(epub))
.then(() => new Report(epub, options.outdir))
// Check each Content Doc
.then(report => checker.check(epub, report))
// Process the Results
Expand Down
5 changes: 5 additions & 0 deletions packages/ace-report/src/defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"report": {
"use-relative-paths": true
}
}
15 changes: 14 additions & 1 deletion packages/ace-report/src/report-builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

const pkg = require('../package');

const { config, paths } = require('@daisy/ace-config');
const defaults = require('./defaults');
const reportConfig = config.get('report', defaults.report);
const path = require('path');

// static
const ACE_DESCRIPTION = {
'@type': 'earl:software',
Expand Down Expand Up @@ -105,6 +110,10 @@ class ReportBuilder {
build() {
return this._json;
}
setOutdir(outdir) {
this.outdir = outdir;
return this;
}
withA11yMeta(metadata) {
if (!metadata) return this;
this._json['a11y-metadata'] = metadata;
Expand Down Expand Up @@ -151,7 +160,11 @@ class ReportBuilder {
return this;
}
withTestSubject(url, title, identifier, metadata, links) {
withTestSubject(this._json, url, title, identifier, metadata, links);
var url_ = url;
if (this.outdir != "" && reportConfig["use-relative-paths"]) {
url_ = path.relative(this.outdir, url);
}
withTestSubject(this._json, url_, title, identifier, metadata, links);
return this;
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ace-report/src/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ function aggregateHTMLOutlines(outlines) {
}

module.exports = class Report {
constructor(epub) {
constructor(epub, outdir) {
this._builder = new builders.ReportBuilder()
.setOutdir(outdir)
.withTestSubject(epub.path, '', '', epub.metadata, epub.links)
.withA11yMeta(a11yMetaChecker.analyze(epub.metadata))
}
Expand Down

0 comments on commit c7bfe03

Please sign in to comment.