Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grunt W3C Validation #470

Merged
merged 25 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2a66569
Add W3C Validation Dependency to package.json
nvasileiadis Jan 24, 2017
ebbad57
Add Error Keeping Directory & Error Output Template
nvasileiadis Jan 24, 2017
2836afd
Update gitignore for Validation related files
nvasileiadis Jan 24, 2017
c559ea6
Update Gruntfile to run with W3C Validation
nvasileiadis Jan 24, 2017
d1b69d4
Relocate File to /tests/validation
nvasileiadis Jan 26, 2017
40f354a
Update gitignore to bypass tests/validation
nvasileiadis Jan 26, 2017
ec65bb1
Add directories to gitattributes
nvasileiadis Jan 26, 2017
cf1e835
Update Gruntfile for W3C Validation
nvasileiadis Jan 26, 2017
b426b6e
Update ignore to include only newly generated folders
nvasileiadis Jan 26, 2017
cf08416
Remove Email Related Folders from Validate Task
nvasileiadis Jan 26, 2017
a735d0a
Merge branch 'develop' into grunt-w3c-validation
nvasileiadis Mar 27, 2017
9fc1d78
Add Casper JS File
nvasileiadis Mar 29, 2017
6ab3c56
Add CasperJS Dependency to the Project
nvasileiadis Mar 29, 2017
713c2a3
Add New Folder Structure to gitignore
nvasileiadis Mar 31, 2017
9e8b909
Add CasperJS to Gruntfile
nvasileiadis Mar 31, 2017
d094ad7
Add CasperJS Browsing Steps
nvasileiadis Mar 31, 2017
56583e9
Fix For Loop to Iterate Every Link in Primary Nav
nvasileiadis Apr 11, 2017
0658792
Resolve Duplicate HTML Outputs Issue
nvasileiadis Apr 12, 2017
07e3581
Add Filter of URL Names for Use in Output Files
nvasileiadis May 12, 2017
1719aa0
Fix Output File Names to Match the URLs
nvasileiadis May 12, 2017
9357087
Merge branch 'develop' into grunt-w3c-validation
nvasileiadis May 12, 2017
9b1f768
Improve Report File Name Title Readability
nvasileiadis May 12, 2017
c38c0fd
Merge branch 'grunt-w3c-validation' of https://github.com/jadu/pulsar…
nvasileiadis May 12, 2017
81e8e44
Refactoring Based on Peer Review and Hound
nvasileiadis May 16, 2017
eb9e212
Improve Index Output Naming
nvasileiadis May 16, 2017
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
/phpunit.xml.dist export-ignore
/pulsar.sublime-project export-ignore
/Vagrantfile export-ignore
/tests/validation/w3cError* export-ignore
/validation-status.json export-ignore
/validation-report.json export-ignore

##
## /images/
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ pulsar.zip
/fonts/_config.fonts.scss

/.csscomb.json
/validation-status.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files will also need adding to the .gitattributes file as export-ignore rules so that Continuum products can ignore them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

/validation-report.json
/tests/validation/error_reports/*
/tests/validation/html_output/*
33 changes: 32 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,35 @@ module.exports = function(grunt) {
reloadOnRestart: true,
watchTask: true
}
},

casperjs: {
options: {
async: {
parallel: false
},
silent: false
},
files: ['../pulsar/js/casper.js']
},

'gh-pages': {
validation: {
options: {
reset: grunt.option('reset') || false,
stoponerror: false,
maxTry: 3,
relaxerror: ['Bad value X-UA-Compatible for attribute http-equiv on element meta.'], // ignores these errors
generateReport: true,
errorHTMLRootDir: "tests/validation/error_reports",
useTimeStamp: true,
errorTemplate: "tests/validation/w3c_validation_error_Template.html"
},
files: {
src: ['../pulsar/tests/validation/html_output/*.html']
}
},

'gh-pages': {
options: {
base: 'docs/_site',
repo: 'https://github.com/jadu/pulsar.git'
Expand Down Expand Up @@ -575,6 +601,11 @@ module.exports = function(grunt) {
'exec:updateNpm'
]);

grunt.registerTask('validate', [
'casperjs',
'validation'
]);

// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

Expand Down
56 changes: 56 additions & 0 deletions js/casper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var fs = require('fs');
var links;

function getLinks() {
var links = document.querySelectorAll('.nav-link.t-nav-link');
return Array.prototype.map.call(links, function (e) {
return e.getAttribute('href');
});
}

casper.start('http://192.168.13.37/index.php', function() {
"use strict";
fs.write('tests/validation/html_output/_index.html', this.getPageContent(), 'w');
});

casper.then(function () {
var links = this.evaluate(getLinks);
var current = 0;
var end = links.length;
// Get the word before .html.twig, the word before the last '/' and the word in urls like '/lexicon'
var regex = /((\w*)(\/|.html.twig)$)|(\/\w*$)/gm;
var match = [];
var newlinks = [];

// Remove links within the same page
for (var i = 0; i < links.length; i++) {
if (links[i].indexOf('#') === -1) {
newlinks.push(links[i]);
}
}

// Get Page Name from URL
for (i = 0; i < newlinks.length; i++) {
if (newlinks[i].match(regex)) { // Remove null items that didn't pass the regex
var link = newlinks[i].match(regex);
var filtered = link[0]; // Get just the name from the results array
var splited = filtered.split('.'); // Split dots to remove .html.twig part
var replaced = splited[0].replace('/', ''); // Remove '/'
match.push(replaced); // Keep just the names in a separata array
};
};

for (;current < end;) {
(function(cntr) {
casper.thenOpen('http://192.168.13.37' + newlinks[cntr] + '', function() {
fs.write('tests/validation/html_output/_' + match[cntr] + '_.html', this.getPageContent(), 'w');
});
})(current);
current++;
}
});

casper.run(function() {
"use strict";
this.exit();
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"grunt-browser-sync": "^2.2.0",
"grunt-browserify": "^5.0.0",
"grunt-bump": "^0.7.2",
"grunt-casperjs": "^2.2.1",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-compress": "^1.2.0",
"grunt-contrib-copy": "^1.0.0",
Expand All @@ -54,6 +55,7 @@
"grunt-real-favicon": "^0.1.3",
"grunt-sass": "^1.1.0",
"grunt-scss-lint": "0.3.8",
"grunt-w3c-html-validation": "^0.1.8",
"jquery": "1.x",
"jsdom": "^8.4.0",
"matchdep": "^1.0.1",
Expand Down
44 changes: 44 additions & 0 deletions tests/validation/w3c_validation_error_Template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>W3C Error Report for {{filename}}</title>
</head>
<body>
<table border='0' align='center' cellpadding='5' cellspacing='0' style='border-collapse:collapse;background-color:Wheat;color:black;font-family:arial,helvetica,sans-serif; width:100%'>
<tbody>
<tr>
<td colspan='6' style='padding:5px;background-color:SteelBlue;color:Wheat;font-size:200%;border:2px solid SteelBlue;text-align:center;'>W3C Validation Report
</td>
</tr>
<tr>
<td colspan='6' style='padding:5px;background-color:SteelBlue;color:Wheat;font-size:125%;border:2px solid SteelBlue;text-align:center;'>{{filename}} | Error Count : {{error.length}}
</td>
</tr>
<tr>
<td style='text-align:center;font-size:125%;border:2px solid SteelBlue;white-space:nowrap;'>Error Number
</td>
<td style='text-align:center;font-size:125%;border:2px solid SteelBlue;white-space:nowrap;'>Error Type
</td>
<td style='text-align:center;font-size:125%;border:2px solid SteelBlue;white-space:nowrap;'>Line Number
</td>
<td style='text-align:center;font-size:125%;border:2px solid SteelBlue;white-space:nowrap;' >Error Message
</td>
<td style='text-align:center;font-size:125%;border:2px solid SteelBlue;white-space:nowrap;' >Error Source Code Reference
</td>
<td style='text-align:center;font-size:125%;border:2px solid SteelBlue;white-space:nowrap;' >Error Explanation
</td>
</tr>
{{#each error}}
<tr>
<td style='text-align:center;font-size:100%;border:2px solid SteelBlue;'>{{@index}} </td>
<td style='text-align:center;font-size:100%;border:2px solid SteelBlue;'>{{type}} </td>
<td style='text-align:center;font-size:100%;border:2px solid SteelBlue;'>{{lastLine}} </td>
<td style='text-align:center;font-size:100%;border:2px solid SteelBlue;'>{{message}} </td>
<td style='text-align:center;font-size:100%;border:2px solid SteelBlue;'><code>{{errSrcFirstPart}}{{{errSrcToHighlight}}}{{errSrcSecondPart}}</code> </td>
<td style='text-align:center;font-size:100%;border:2px solid SteelBlue;'>{{{explanation}}} </td>
</tr>
{{/each}}
</tbody>
</table>
</body>
</html>