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

Report download #235

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.js
50 changes: 50 additions & 0 deletions Auditor/HTMLCSAuditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@

#HTMLCS-wrapper .HTMLCS-summary-right {
text-align: right;
color: #000;
font-size: 1.35em;
line-height: 2.1em;
text-overflow: ellipsis;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
white-space: nowrap;
cursor: pointer;
}

#HTMLCS-wrapper .HTMLCS-outer-wrapper {
Expand Down Expand Up @@ -902,6 +909,49 @@
opacity: 0.4;
}



#HTMLCS-wrapper #HTMLCS-settings-download {
background-color: #3A3940;
border: 1px solid #2B2B2B;
border-radius: 0.3em 0.3em 0.3em 0.3em;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 0 rgba(255, 255, 255, 0.15), 0 -1.4em 1.6em rgba(0, 0, 0, 0.4) inset;
color: #FFF;
cursor: pointer;
font-size: 1.9em;
line-height: 3em;
position: relative;
text-shadow: 0 -1px 0 #000;
-moz-transition: opacity 0.3s ease;
-webkit-transition: opacity 0.3s ease;
opacity: 1;
text-align: center;
}

#HTMLCS-wrapper #HTMLCS-settings-download:after {
background: url("Images/HTMLCS-tools.png") no-repeat scroll 0 -108px transparent;
content: "";
height: 14px;
margin-top: -7px;
position: absolute;
right: 1em;
top: 50%;
width: 9px;
}

#HTMLCS-wrapper #HTMLCS-settings-download:hover {
background-color: #2B2B2B;
}

#HTMLCS-wrapper.HTMLCS-processing #HTMLCS-settings-download,
#HTMLCS-wrapper #HTMLCS-settings-download.disabled {
cursor: default;
filter: alpha(opacity=40);
opacity: 0.4;
}



Copy link
Author

Choose a reason for hiding this comment

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

This whole section needs to be deleted.

#HTMLCS-wrapper .HTMLCS-button.disabled {
cursor: default;
filter: alpha(opacity=30);
Expand Down
3 changes: 2 additions & 1 deletion Auditor/HTMLCSAuditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ _global.HTMLCSAuditor = new function()

var rightPane = _doc.createElement('div');
rightPane.className = _prefix + 'summary-right';
rightPane.onclick = _global.downloadHTMLCS;
summary.appendChild(rightPane);

var leftContents = [];
Expand Down Expand Up @@ -290,7 +291,7 @@ _global.HTMLCSAuditor = new function()
lineage.appendChild(lineageTotalsItem);
leftPane.appendChild(lineage);

rightPane.appendChild(_doc.createTextNode(String.fromCharCode(160)));
rightPane.appendChild(_doc.createTextNode('CSV'));

return summary;
};
Expand Down
7 changes: 7 additions & 0 deletions HTMLCS.Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
_global.HTMLCS.util = function() {
var self = {};

/**
* Work around a bug in FileSaver.js
*
* https://github.com/eligrey/FileSaver.js/issues/475
*/
window.module = window.module || {};

/**
* Trim off excess spaces on either side.
*
Expand Down
43 changes: 42 additions & 1 deletion HTMLCS.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,45 @@
*
*/


/**
* Runs the sniffs and downloads the results to a text file
*
*/
_global.downloadHTMLCS = function () {
Copy link
Author

Choose a reason for hiding this comment

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

Should be part of the HTMLCS object.


function q(s) {
return '"' + (s || "").toString().replace(/"/g, '""') + '"';
}

function elementToString(element) {
if(!element) {
return "";
}
var html = element.outerHTML;
if (!html) {
return "";
}
if (html.length > 100) {
return html.substring(0, 100) + "...";
}
return html;
}

HTMLCS.run(function() {

var header = '"Type", Code","Message","Element","Data"';
var body = this.getMessages().map(function (m) {
return [m.type, q(m.code), q(m.msg), q(elementToString(m.element)), q(m.data)].join(",")
}).join("\n");
var csvContents = header + "\n" + body;

var filename = "HTML_Codesniffer" + Math.random() + ".csv";

saveAs(new Blob([csvContents], { type: "text/plain;charset=utf-8" }), filename);
})
}

_global.HTMLCS = new function()
{
var _standards = {};
Expand All @@ -22,8 +61,9 @@ _global.HTMLCS = new function()
var _messages = [];
var _msgOverrides = {};


/*
Message type constants.
Message type constants.
*/
this.ERROR = 1;
this.WARNING = 2;
Expand Down Expand Up @@ -243,6 +283,7 @@ _global.HTMLCS = new function()
* @returns {Array} Array of message objects.
*/
this.getMessages = function() {

return _messages.concat([]);
};

Expand Down
1 change: 1 addition & 0 deletions Translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _global.translation['en'] = {
,"auditor_select_types" : 'Select the types of issues to include in the report'
,"auditor_home" : 'Home'
,"auditor_view_report" : 'View Report'
,"auditor_download_report": 'Download Report'
Copy link
Author

Choose a reason for hiding this comment

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

This can go. I ended up making the label "CSV" which is language-independent.

,"auditor_report" : 'Report'
,"auditor_back_to_report" : 'Back to Report'
,"auditor_previous_issue" : 'Previous Issue'
Expand Down
9 changes: 6 additions & 3 deletions gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = (grunt)->
'HTMLCS.js'
'HTMLCS.Util.js'
'Contrib/PhantomJS/runner.js'
'Auditor/HTMLCSAuditor.js'
'Auditor/HTMLCSAuditor.js',
'node_modules/file-saver/dist/FileSaver.js'
]
dist:
options:
Expand All @@ -40,7 +41,8 @@ module.exports = (grunt)->
'HTMLCS.js'
'HTMLCS.Util.js'
'Contrib/PhantomJS/runner.js'
'Auditor/HTMLCSAuditor.js'
'Auditor/HTMLCSAuditor.js',
'node_modules/file-saver/dist/FileSaver.js'
],
bookmarklet:
options:
Expand All @@ -53,7 +55,8 @@ module.exports = (grunt)->
'HTMLCS.js'
'HTMLCS.Util.js'
'Contrib/PhantomJS/runner.js'
'Auditor/Auditor_with_beacon.js'
'Auditor/Auditor_with_beacon.js',
'node_modules/file-saver/dist/FileSaver.js'
],

copy:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"homepage": "http://squizlabs.github.io/HTML_CodeSniffer/",
"dependencies": {
"file-saver": "^2.0.0-rc.3",
"grunt": "^1.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-jshint": "^1.0.0",
Expand All @@ -28,4 +29,4 @@
"devDependencies": {
"grunt-contrib-uglify": "^2.3.0"
}
}
}