html_cs_run_parse 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 050e088ce9d0246c941b4fb6f3585b3ad0f46dfe8aec94faf0988182b628707b
4
+ data.tar.gz: 869eed595e061d4e56a278b15bbb6beb5dac01d4b46e235ddff7395253607845
5
+ SHA512:
6
+ metadata.gz: 2e2e35a95fb8fe48d4f52869b29a497d0051d60be296e4ff633e84987c178cfd579e9ed428b0d822bf4876e0fa196134fbf1da615eb29a8dfe38acc6fc1f9550
7
+ data.tar.gz: 1c6ff5bbc325c83e1f94748963d2642284ce53d77dece0d949bde79ad81b58c93914656d70b6c1dc52701dc3312bfecaa605a406af4ac30915c9b4e767dcbc35
data/lib/HTMLCS.js ADDED
@@ -0,0 +1,630 @@
1
+ /**
2
+ * +--------------------------------------------------------------------+
3
+ * | This HTML_CodeSniffer file is Copyright (c) |
4
+ * | Squiz Pty Ltd (ABN 77 084 670 600) |
5
+ * +--------------------------------------------------------------------+
6
+ * | IMPORTANT: Your use of this Software is subject to the terms of |
7
+ * | the Licence provided in the file licence.txt. If you cannot find |
8
+ * | this file please contact Squiz (www.squiz.com.au) so we may |
9
+ * | provide you a copy. |
10
+ * +--------------------------------------------------------------------+
11
+ *
12
+ */
13
+
14
+ _global.HTMLCS = new function()
15
+ {
16
+ var _standards = {};
17
+ var _sniffs = [];
18
+ var _tags = {};
19
+ var _standard = null;
20
+ var _currentSniff = null;
21
+
22
+ var _messages = [];
23
+ var _msgOverrides = {};
24
+
25
+ /*
26
+ Message type constants.
27
+ */
28
+ this.ERROR = 1;
29
+ this.WARNING = 2;
30
+ this.NOTICE = 3;
31
+
32
+ // The current language to use.
33
+ this.lang = 'en';
34
+
35
+ /**
36
+ * Loads the specified standard and run the sniffs.
37
+ *
38
+ * @param {String} standard The name of the standard to load.
39
+ * @param {String|Node} content An HTML string or a DOM node object.
40
+ * @param {Function} callback The function that will be called when the testing is completed.
41
+ * @param {Function} failCallback The fail callback which will be called if the standard load has failed.
42
+ * @param {String} language The language to use for text output.
43
+ */
44
+ this.process = function(
45
+ standard,
46
+ content,
47
+ callback,
48
+ failCallback,
49
+ language
50
+ ) {
51
+ // Clear previous runs.
52
+ _standards = {};
53
+ _sniffs = [];
54
+ _tags = {};
55
+ _standard = null;
56
+
57
+ if (!content) {
58
+ return false;
59
+ }
60
+
61
+ // Set a language to use.
62
+ var languages = Object.keys(_global.translation);
63
+ if (language && languages.indexOf(language) !== -1) {
64
+ this.lang = language;
65
+ }
66
+
67
+ if (_standards[_getStandardPath(standard)]) {
68
+ HTMLCS.run(callback, content);
69
+ } else {
70
+ this.loadStandard(standard, function() {
71
+ HTMLCS.run(callback, content);
72
+ }, failCallback);
73
+ }
74
+ };
75
+
76
+ /**
77
+ * Gets a translation for a text value.
78
+ *
79
+ * @param {String} text The text to get the translation for.
80
+ *
81
+ * @return {String}
82
+ */
83
+ this.getTranslation = function(text) {
84
+ var translations = _global.translation[this.lang];
85
+
86
+ if (!translations) {
87
+ console.error('Missing translations for language ' + this.lang);
88
+ return '';
89
+ }
90
+
91
+ var translation = translations[text];
92
+
93
+ if (!translation) {
94
+ console.error('Translation for "' + text + '" does not exist in current language ' + this.lang);
95
+ return '';
96
+ }
97
+
98
+ return translation;
99
+ };
100
+
101
+ /**
102
+ * Loads the specified standard and its sniffs.
103
+ *
104
+ * @param {String} standard The name of the standard to load.
105
+ * @param {Function} callback The function to call once the standard is loaded.
106
+ */
107
+ this.loadStandard = function(standard, callback, failCallback) {
108
+ if (!standard) {
109
+ return false;
110
+ }
111
+
112
+ _includeStandard(standard, function() {
113
+ _standard = standard;
114
+ callback.call(this);
115
+ }, failCallback);
116
+ };
117
+
118
+ /**
119
+ * Runs the sniffs for the loaded standard.
120
+ *
121
+ * @param {Function} callback The function to call once all sniffs are completed.
122
+ * @param {String|Node} content An HTML string or a DOM node object.
123
+ */
124
+ this.run = function(callback, content) {
125
+ var element = null;
126
+ var loadingFrame = false;
127
+ if (typeof content === 'string') {
128
+ loadingFrame = true;
129
+ var elementFrame = document.createElement('iframe');
130
+ elementFrame.style.display = 'none';
131
+ elementFrame = document.body.insertBefore(elementFrame, null);
132
+
133
+ if (elementFrame.contentDocument) {
134
+ element = elementFrame.contentDocument;
135
+ } else if (element.contentWindow) {
136
+ element = elementFrame.contentWindow.document;
137
+ }
138
+
139
+ elementFrame.load = function() {
140
+ this.onreadystatechange = null;
141
+ this.onload = null;
142
+
143
+ if (HTMLCS.isFullDoc(content) === false) {
144
+ element = element.getElementsByTagName('body')[0];
145
+ var div = element.getElementsByTagName('div')[0];
146
+ if (div && (div.id === '__HTMLCS-source-wrap')) {
147
+ div.id = '';
148
+ element = div;
149
+ }
150
+ }
151
+
152
+ var elements = HTMLCS.util.getAllElements(element);
153
+ elements.unshift(element);
154
+ _run(elements, element, callback);
155
+ };
156
+
157
+ // Satisfy IE which doesn't like onload being set dynamically.
158
+ elementFrame.onreadystatechange = function() {
159
+ if (/^(complete|loaded)$/.test(this.readyState) === true) {
160
+ this.onreadystatechange = null;
161
+ this.load();
162
+ }
163
+ };
164
+
165
+ elementFrame.onload = elementFrame.load;
166
+
167
+ if ((HTMLCS.isFullDoc(content) === false) && (content.indexOf('<body') === -1)) {
168
+ element.write('<div id="__HTMLCS-source-wrap">' + content + '</div>');
169
+ } else {
170
+ element.write(content);
171
+ }
172
+
173
+ element.close();
174
+ } else {
175
+ element = content;
176
+ }
177
+
178
+ if (!element) {
179
+ callback.call(this);
180
+ return;
181
+ }
182
+
183
+ callback = callback || function() {};
184
+ _messages = [];
185
+
186
+ // Get all the elements in the parent element.
187
+ // Add the parent element too, which will trigger "_top" element codes.
188
+ var elements = HTMLCS.util.getAllElements(element);
189
+ elements.unshift(element);
190
+
191
+ // Run the sniffs.
192
+ if (loadingFrame === false) {
193
+ _run(elements, element, callback);
194
+ }
195
+ };
196
+
197
+ /**
198
+ * Returns true if the content passed appears to be from a full document.
199
+ *
200
+ * With string content, we consider a full document as the presence of <html>,
201
+ * or <head> + <body> elements. For an element, only the 'html' element (the
202
+ * document element) is accepted.
203
+ *
204
+ * @param {String|Node} content An HTML string or a DOM node object.
205
+ *
206
+ * @returns {Boolean}
207
+ */
208
+ this.isFullDoc = function(content) {
209
+ var fullDoc = false;
210
+ if (typeof content === 'string') {
211
+ if (content.toLowerCase().indexOf('<html') !== -1) {
212
+ fullDoc = true;
213
+ } else if ((content.toLowerCase().indexOf('<head') !== -1) && (content.toLowerCase().indexOf('<body') !== -1)) {
214
+ fullDoc = true;
215
+ }
216
+ } else {
217
+ // If we are the document, or the document element.
218
+ if ((content.nodeName.toLowerCase() === 'html') || (content.documentElement)) {
219
+ fullDoc = true;
220
+ }
221
+ }
222
+
223
+ return fullDoc;
224
+ };
225
+
226
+ /**
227
+ * Adds a message.
228
+ *
229
+ * @param {Number} type The type of the message.
230
+ * @param {Node} element The element that the message is related to.
231
+ * @param {String} msg The message string.
232
+ * @param {String} code Unique code for the message.
233
+ * @param {Object} [data] Extra data to store for the message.
234
+ */
235
+ this.addMessage = function(type, element, msg, code, data) {
236
+ code = _getMessageCode(code);
237
+
238
+ _messages.push({
239
+ type: type,
240
+ element: element,
241
+ msg: _msgOverrides[code] || msg,
242
+ code: code,
243
+ data: data
244
+ });
245
+ };
246
+
247
+ /**
248
+ * Returns all the messages for the last run.
249
+ *
250
+ * Return a copy of the array so the class variable doesn't get modified by
251
+ * future modification (eg. splicing).
252
+ *
253
+ * @returns {Array} Array of message objects.
254
+ */
255
+ this.getMessages = function() {
256
+ return _messages.concat([]);
257
+ };
258
+
259
+ /**
260
+ * Runs the sniffs in the loaded standard for the specified element.
261
+ *
262
+ * @param {Node} element The element to test.
263
+ * @param {Node} topElement The top element of the processing.
264
+ * @param {Function} [callback] The function to call once all tests are run.
265
+ */
266
+ var _run = function(elements, topElement, callback) {
267
+ var topMsgs = [];
268
+ while (elements.length > 0) {
269
+ var element = elements.shift();
270
+
271
+ if (element === topElement) {
272
+ var tagName = '_top';
273
+ } else {
274
+ var tagName = element.tagName.toLowerCase();
275
+ }
276
+
277
+ // First check whether any "top" messages need to be shifted off for this
278
+ // element. If so, dump off into the main messages.
279
+ for (var i = 0; i < topMsgs.length;) {
280
+ if (element === topMsgs[i].element) {
281
+ _messages.push(topMsgs[i]);
282
+ topMsgs.splice(i, 1);
283
+ } else {
284
+ i++;
285
+ }
286
+ }//end for
287
+
288
+ if (_tags[tagName] && _tags[tagName].length > 0) {
289
+ _processSniffs(element, _tags[tagName].concat([]), topElement);
290
+
291
+ // Save "top" messages, and reset the messages array.
292
+ if (tagName === '_top') {
293
+ topMsgs = _messages;
294
+ _messages = [];
295
+ }
296
+ }
297
+ }//end while
298
+
299
+ _messages = _messages.concat(topMsgs);
300
+
301
+ // Due to filtering of presentation roles for general sniffing these need to be handled
302
+ // separately. The 1.3.1 sniff needs to run to detect any incorrect usage of the presentation
303
+ // role.
304
+ var presentationElems = topElement.querySelectorAll('[role="presentation"]');
305
+ _currentSniff = HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1;
306
+ [].forEach.call(presentationElems, function(element) {
307
+ _currentSniff.testSemanticPresentationRole(element);
308
+ });
309
+
310
+ if (callback instanceof Function === true) {
311
+ callback.call(this);
312
+ }
313
+ };
314
+
315
+ /**
316
+ * Process the sniffs.
317
+ *
318
+ * @param {Node} element The element to test.
319
+ * @param {Array} sniffs Array of sniffs.
320
+ * @param {Node} topElement The top element of the processing.
321
+ * @param {Function} [callback] The function to call once the processing is completed.
322
+ */
323
+ var _processSniffs = function(element, sniffs, topElement, callback) {
324
+ while (sniffs.length > 0) {
325
+ var sniff = sniffs.shift();
326
+ _currentSniff = sniff;
327
+
328
+ if (sniff.useCallback === true) {
329
+ // If the useCallback property is set:
330
+ // - Process the sniff.
331
+ // - Recurse into ourselves with remaining sniffs, with no callback.
332
+ // - Clear out the list of sniffs (so they aren't run again), so the
333
+ // callback (if not already recursed) can run afterwards.
334
+ sniff.process(element, topElement, function() {
335
+ _processSniffs(element, sniffs, topElement);
336
+ sniffs = [];
337
+ });
338
+ } else {
339
+ // Process the sniff.
340
+ sniff.process(element, topElement);
341
+ }
342
+ }//end while
343
+
344
+ if (callback instanceof Function === true) {
345
+ callback.call(this);
346
+ }
347
+ };
348
+
349
+ /**
350
+ * Includes the specified standard file.
351
+ *
352
+ * @param {String} standard The name of the standard.
353
+ * @param {Function} callback The function to call once the standard is included.
354
+ * @param {Object} options The options for the standard (e.g. exclude sniffs).
355
+ */
356
+ var _includeStandard = function(standard, callback, failCallback, options) {
357
+ if (standard.indexOf('http') !== 0) {
358
+ standard = _getStandardPath(standard);
359
+ }//end id
360
+
361
+ // See if the ruleset object is already included (eg. if minified).
362
+ var parts = standard.split('/');
363
+ var ruleSet = _global['HTMLCS_' + parts[(parts.length - 2)]];
364
+ if (ruleSet) {
365
+ // Already included.
366
+ _registerStandard(standard, callback, failCallback, options);
367
+ } else {
368
+ _includeScript(standard, function() {
369
+ // Script is included now register the standard.
370
+ _registerStandard(standard, callback, failCallback, options);
371
+ }, failCallback);
372
+ }//end if
373
+ };
374
+
375
+ /**
376
+ * Registers the specified standard and its sniffs.
377
+ *
378
+ * @param {String} standard The name of the standard.
379
+ * @param {Function} callback The function to call once the standard is registered.
380
+ * @param {Object} options The options for the standard (e.g. exclude sniffs).
381
+ */
382
+ var _registerStandard = function(standard, callback, failCallback, options) {
383
+ // Get the object name.
384
+ var parts = standard.split('/');
385
+
386
+ // Get a copy of the ruleset object.
387
+ var oldRuleSet = _global['HTMLCS_' + parts[(parts.length - 2)]];
388
+ var ruleSet = {};
389
+
390
+ for (var x in oldRuleSet) {
391
+ if (oldRuleSet.hasOwnProperty(x) === true) {
392
+ ruleSet[x] = oldRuleSet[x];
393
+ }
394
+ }
395
+
396
+ if (!ruleSet) {
397
+ return false;
398
+ }
399
+
400
+ _standards[standard] = ruleSet;
401
+
402
+ // Process the options.
403
+ if (options) {
404
+ if (options.include && options.include.length > 0) {
405
+ // Included sniffs.
406
+ ruleSet.sniffs = options.include;
407
+ } else if (options.exclude) {
408
+ // Excluded sniffs.
409
+ for (var i = 0; i < options.exclude.length; i++) {
410
+ var index = ruleSet.sniffs.find(options.exclude[i]);
411
+ if (index >= 0) {
412
+ ruleSet.sniffs.splice(index, 1);
413
+ }
414
+ }
415
+ }
416
+ }//end if
417
+
418
+ // Register the sniffs for this standard.
419
+ var sniffs = ruleSet.sniffs.slice(0, ruleSet.sniffs.length);
420
+ _registerSniffs(standard, sniffs, callback, failCallback);
421
+ };
422
+
423
+ /**
424
+ * Registers the sniffs for the specified standard.
425
+ *
426
+ * @param {String} standard The name of the standard.
427
+ * @param {Array} sniffs List of sniffs to register.
428
+ * @param {Function} callback The function to call once the sniffs are registered.
429
+ */
430
+ var _registerSniffs = function(standard, sniffs, callback, failCallback) {
431
+ if (sniffs.length === 0) {
432
+ callback.call(this);
433
+ return;
434
+ }
435
+
436
+ // Include and register sniffs.
437
+ var sniff = sniffs.shift();
438
+ _loadSniffFile(standard, sniff, function() {
439
+ _registerSniffs(standard, sniffs, callback, failCallback);
440
+ }, failCallback);
441
+ };
442
+
443
+ /**
444
+ * Includes the sniff's JS file and registers it.
445
+ *
446
+ * @param {String} standard The name of the standard.
447
+ * @param {String|Object} sniff The sniff to register, can be a string or
448
+ * and object specifying another standard.
449
+ * @param {Function} callback The function to call once the sniff is included and registered.
450
+ */
451
+ var _loadSniffFile = function(standard, sniff, callback, failCallback) {
452
+ if (typeof sniff === 'string') {
453
+ var sniffObj = _getSniff(standard, sniff);
454
+ var cb = function() {
455
+ _registerSniff(standard, sniff);
456
+ callback.call(this);
457
+ };
458
+
459
+ // Already loaded.
460
+ if (sniffObj) {
461
+ cb();
462
+ } else {
463
+ _includeScript(_getSniffPath(standard, sniff), cb, failCallback);
464
+ }
465
+ } else {
466
+ // Including a whole other standard.
467
+ _includeStandard(sniff.standard, function() {
468
+ if (sniff.messages) {
469
+ // Add message overrides.
470
+ for (var msg in sniff.messages) {
471
+ _msgOverrides[msg] = sniff.messages[msg];
472
+ }
473
+ }
474
+
475
+ callback.call(this);
476
+ }, failCallback, {
477
+ exclude: sniff.exclude,
478
+ include: sniff.include
479
+ });
480
+ }
481
+ };
482
+
483
+ /**
484
+ * Registers the specified sniff.
485
+ *
486
+ * @param {String} standard The name of the standard.
487
+ * @param {String} sniff The name of the sniff.
488
+ */
489
+ var _registerSniff = function(standard, sniff) {
490
+ // Get the sniff object.
491
+ var sniffObj = _getSniff(standard, sniff);
492
+ if (!sniffObj) {
493
+ return false;
494
+ }
495
+
496
+ // Call the register method of the sniff, it should return an array of tags.
497
+ if (sniffObj.register) {
498
+ var watchedTags = sniffObj.register();
499
+
500
+ for (var i = 0; i < watchedTags.length; i++) {
501
+ if (!_tags[watchedTags[i]]) {
502
+ _tags[watchedTags[i]] = [];
503
+ }
504
+
505
+ _tags[watchedTags[i]].push(sniffObj);
506
+ }
507
+ }
508
+
509
+ _sniffs.push(sniffObj);
510
+ };
511
+
512
+ /**
513
+ * Returns the path to the sniff file.
514
+ *
515
+ * @param {String} standard The name of the standard.
516
+ * @param {String} sniff The name of the sniff.
517
+ *
518
+ * @returns {String} The path to the JS file of the sniff.
519
+ */
520
+ var _getSniffPath = function(standard, sniff) {
521
+ var parts = standard.split('/');
522
+ parts.pop();
523
+ var path = parts.join('/') + '/Sniffs/' + sniff.replace(/\./g, '/') + '.js';
524
+ return path;
525
+ };
526
+
527
+ /**
528
+ * Returns the path to a local standard.
529
+ *
530
+ * @param {String} standard The name of the standard.
531
+ *
532
+ * @returns {String} The path to the local standard.
533
+ */
534
+ var _getStandardPath = function(standard)
535
+ {
536
+ // Get the include path of a local standard.
537
+ var scripts = document.getElementsByTagName('script');
538
+ var path = null;
539
+
540
+ // Loop through all the script tags that exist in the document and find the one
541
+ // that has included this file.
542
+ for (var i = 0; i < scripts.length; i++) {
543
+ if (scripts[i].src) {
544
+ if (scripts[i].src.match(/HTMLCS\.js/)) {
545
+ // We have found our appropriate <script> tag that includes
546
+ // this file, we can extract the path.
547
+ path = scripts[i].src.replace(/HTMLCS\.js/,'');
548
+
549
+ // trim any trailing bits
550
+ path = path.substring(0, path.indexOf('?'));
551
+ break;
552
+ }
553
+ }
554
+ }
555
+
556
+ return path + 'Standards/' + standard + '/ruleset.js';
557
+
558
+ };
559
+
560
+ /**
561
+ * Returns the sniff object.
562
+ *
563
+ * @param {String} standard The name of the standard.
564
+ * @param {String} sniff The name of the sniff.
565
+ *
566
+ * @returns {Object} The sniff object.
567
+ */
568
+ var _getSniff = function(standard, sniff) {
569
+ var name = 'HTMLCS_';
570
+ name += _standards[standard].name + '_Sniffs_';
571
+ name += sniff.split('.').join('_');
572
+
573
+ if (!_global[name]) {
574
+ return null;
575
+ }
576
+
577
+ _global[name]._name = sniff;
578
+ return _global[name];
579
+ };
580
+
581
+ /**
582
+ * Returns the full message code.
583
+ *
584
+ * A full message code includes the standard name, the sniff name and the given code.
585
+ *
586
+ * @returns {String} The full message code.
587
+ */
588
+ var _getMessageCode = function(code) {
589
+ code = _standard + '.' + _currentSniff._name + '.' + code;
590
+ return code;
591
+ };
592
+
593
+ /**
594
+ * Includes the specified JS file.
595
+ *
596
+ * @param {String} src The URL to the JS file.
597
+ * @param {Function} callback The function to call once the script is loaded.
598
+ */
599
+ var _includeScript = function(src, callback, failCallback) {
600
+ var script = document.createElement('script');
601
+ script.onload = function() {
602
+ script.onload = null;
603
+ script.onreadystatechange = null;
604
+ callback.call(this);
605
+ };
606
+
607
+ script.onerror = function() {
608
+ script.onload = null;
609
+ script.onreadystatechange = null;
610
+ if (failCallback) {
611
+ failCallback.call(this);
612
+ }
613
+ };
614
+
615
+ script.onreadystatechange = function() {
616
+ if (/^(complete|loaded)$/.test(this.readyState) === true) {
617
+ script.onreadystatechange = null;
618
+ script.onload();
619
+ }
620
+ };
621
+
622
+ script.src = src;
623
+
624
+ if (document.head) {
625
+ document.head.appendChild(script);
626
+ } else {
627
+ document.getElementsByTagName('head')[0].appendChild(script);
628
+ }
629
+ };
630
+ };
@@ -0,0 +1,12 @@
1
+ require '../html_cs/utility/parse_machine.rb'
2
+
3
+ #this gem is specifically for running HTMLCS
4
+ class HTMLCS
5
+ def self.run_html_cs(browser, file_name)
6
+ browser.execute_script(File.read("./HTMLCS.js"))
7
+ browser.execute_script("HTMLCS_RUNNER.run('WCAG2AA')")
8
+ output = browser.driver.manage.logs.get(:browser)
9
+ parse = ParseMachine.new
10
+ parse.htmlcs_parse(output, file_name)
11
+ end
12
+ end
data/lib/licence.txt ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2012, Squiz Pty Ltd (ABN 77 084 670 600)
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of Squiz Pty Ltd nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,39 @@
1
+ class ParseMachine
2
+ require 'csv'
3
+
4
+ def htmlcs_parse(violations, file_name)
5
+ mod_output = iterate_violations(violations)
6
+ write_csv(mod_output, file_name)
7
+ end
8
+
9
+ private
10
+
11
+ def iterate_violations(violations)
12
+ mod_output = []
13
+ violations.each do |violation|
14
+ if violation.message.include?('[HTMLCS]')
15
+ splits = violation.message.split('|')
16
+ error_or_warning = splits[0].split('[HTMLCS] ')[1]
17
+ guideline = splits[1].gsub(',', '-')
18
+ description = splits[4].gsub(',', '-')
19
+ html_path = splits[5].gsub(',', '-')
20
+ content = splits[2].gsub(',', '-')
21
+ if error_or_warning != 'Notice'
22
+ mod_output.push([error_or_warning, guideline, description, html_path, content])
23
+ end
24
+ end
25
+ end
26
+ mod_output
27
+ end
28
+
29
+
30
+ def write_csv(mod_output, file_name)
31
+ CSV.open("#{file_name}.csv", "wb") do |csv|
32
+ csv << ["type", "code", "message", "context", "selector"]
33
+ mod_output.each { |mod_array|
34
+ csv << mod_array
35
+ }
36
+ end
37
+ end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_cs_run_parse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jerren Every
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: jerren1122@hotmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/HTMLCS.js
20
+ - lib/html_cs_run_parse.rb
21
+ - lib/licence.txt
22
+ - lib/utility/parse_machine.rb
23
+ homepage: https://rubygems.org/gems/html_cs_run_parse
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.7.6.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: this allows for parsing and running of HTML Code Sniffer with Watir
47
+ test_files: []