Skip to content

Commit

Permalink
feat: Allow cutting the same initial part of the path from tested HTM…
Browse files Browse the repository at this point in the history
…L files
  • Loading branch information
prantlf committed May 14, 2018
1 parent fd56c61 commit c3ad14f
Show file tree
Hide file tree
Showing 9 changed files with 1,139 additions and 24 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A custom reporter for [grunt-html] - the HTML validation task - which formats th

You can use the reporter programmatically. In that case you do not need [Grunt] as stated below. You can also use the reporter directly with the [grunt-html] task. The reporter is usually installed and used together with other development tasks.

You need [node >= 4][node], [npm] and [grunt >= 0.4][Grunt] installed and your project build managed by a [Gruntfile] with the necessary modules listed in [package.json], including [grunt-html]. If you haven't used Grunt before, be sure to check out the [Getting Started] guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
You need [node >= 6][node], [npm] and [grunt >= 0.4][Grunt] installed and your project build managed by a [Gruntfile] with the necessary modules listed in [package.json], including [grunt-html]. If you haven't used Grunt before, be sure to check out the [Getting Started] guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

```sh
$ npm install grunt-html-html-reporter --save-dev
Expand All @@ -36,7 +36,13 @@ fs.writeFileSync('report.html', output, 'utf-8')
Type: `Boolean`
Default value: `false`

Cuts the directory from tested HTML files, when creating page titles from in the report. If you use unique names for files alone, you will not get too long page titles, if you flip this flag tp `true`.
Cuts the directory from tested HTML files, when creating page titles of them in the report. If you use unique names for files alone, you will not get too long page titles, if you flip this flag tp `true`.

#### showCommonPathOnly
Type: `Boolean`
Default value: `true`

Cuts the same initial part of the path from tested HTML files, when the paths are used for page titles in the report. If you use sub-directories to organize your files, this option will make the file paths in the report short, but still unique. The default is flipped to `true` already.

## Usage with grunt-html

Expand All @@ -61,6 +67,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.

## Release History

* 2018-05-14 v3.1.0 Allow cutting the same initial part of the path from tested HTML files for displaying purposes
* 2018-04-27 v3.0.0 Dropped support of Node.js 4
* 2018-03-05 v2.2.0 Allow generating page titles from file names without directory
* 2018-03-04 v2.1.0 Add filtering and accessibility to the reports
Expand Down
35 changes: 20 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use strict'

const fs = require('fs')
const path = require('path')
const {getCommonPathLength} = require('common-path-start')
const {readFileSync} = require('fs')
const {basename, join, normalize} = require('path')

const objectValues = require('object.values')
if (!Object.values) {
objectValues.shim()
}

function formatIssues (issues, panelColor) {
return issues.map(function (issue) {
return issues.map(issue => {
const extract = issue.extract.split('<').join('&lt;')
const message = issue.message.split('<').join('&lt;').split('"').join('&quot;')
const line = issue.line
Expand Down Expand Up @@ -54,22 +55,26 @@ function formatFile (file) {
return content
}

module.exports = function (results, options) {
module.exports = (results, options) => {
const showFileNameOnly = options && options.showFileNameOnly
const showCommonPathOnly = !(options && options.showCommonPathOnly === false)
const commonPathLength = showCommonPathOnly &&
getCommonPathLength(results.map(result => normalize(result.file)))
const files = {}
var errorCount = 0
var warningCount = 0
var noticeCount = 0
let errorCount = 0
let warningCount = 0
let noticeCount = 0

results.forEach(function (result) {
const name = path.normalize(result.file)
results.forEach(result => {
const name = normalize(result.file)
const severity = result.type
var file = files[name]
var fileName, issues
let file = files[name]
let fileName, issues
if (!file) {
if (showFileNameOnly) {
fileName = path.parse(name)
fileName = fileName.name + fileName.ext
fileName = basename(name)
} else if (commonPathLength) {
fileName = name.substr(commonPathLength)
} else {
fileName = name
}
Expand Down Expand Up @@ -102,8 +107,8 @@ module.exports = function (results, options) {
})
})

const template = fs.readFileSync(
path.join(__dirname, 'template.html'), 'utf8')
const template = readFileSync(
join(__dirname, 'template.html'), 'utf8')

const buttonMarkup =
'<button class="btn btn-sm btn-danger">Errors <span class="badge">' + errorCount + '</span></button>' +
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
"travis-deploy-once": "travis-deploy-once"
},
"dependencies": {
"common-path-start": "^0.0.1",
"object.values": "^1.0.4"
},
"devDependencies": {
"semantic-release": "^15.1.7",
"semantic-release": "^15.4.1",
"standard": "^11.0.1",
"tap": "^11.1.4",
"travis-deploy-once": "^4.4.1"
"tap": "^11.1.5",
"travis-deploy-once": "^5.0.0"
},
"keywords": [
"grunt-tasks",
Expand Down
Loading

0 comments on commit c3ad14f

Please sign in to comment.