aboutsummaryrefslogtreecommitdiff
path: root/exampleData/ruleSets
diff options
context:
space:
mode:
authorGravatar Benjamin Jones <bjones@galois.com>2012-12-07 16:41:21 -0800
committerGravatar Benjamin Jones <bjones@galois.com>2012-12-07 16:41:21 -0800
commitb161edf0898d5e73a0643da89444d18da208580e (patch)
tree1550b38719778da1542139063355b6f4e171f961 /exampleData/ruleSets
parent27a3535dc5e6c15bdcdbead2954ce4b2655e842e (diff)
added combinedRules script, added other example rule sets
Diffstat (limited to 'exampleData/ruleSets')
-rw-r--r--exampleData/ruleSets/README15
-rwxr-xr-xexampleData/ruleSets/buildCombinedRules.sh32
-rw-r--r--exampleData/ruleSets/colorRules.json170
-rw-r--r--exampleData/ruleSets/colorRulesRF.json20
-rw-r--r--exampleData/ruleSets/combinedFooter1
-rw-r--r--exampleData/ruleSets/combinedHeader3
-rw-r--r--exampleData/ruleSets/combinedRules.json236
-rw-r--r--exampleData/ruleSets/fontRules.json56
-rw-r--r--exampleData/ruleSets/imageRules.json100
-rw-r--r--exampleData/ruleSets/miscRules.json40
-rw-r--r--exampleData/ruleSets/textRules.json57
11 files changed, 552 insertions, 178 deletions
diff --git a/exampleData/ruleSets/README b/exampleData/ruleSets/README
new file mode 100644
index 0000000..48d55ff
--- /dev/null
+++ b/exampleData/ruleSets/README
@@ -0,0 +1,15 @@
+# Example FiveUI Guidelines
+
+This directory contains various FiveUI rule sets aimed at general websites.
+
+## Files
+
+colorRules.json : rules for checking color
+fontRules.json : rules checking font family/weight/size
+imageRules.json : rules checking image sizes and borders
+miscRules.json : rules checking misc constraints
+textRules.json : rules checking text style
+
+buildCombinedRules.sh : shell script which merges all the .json files in
+ the current directory into the file combinedRules.json
+combinedRules.json : collection of all the above rules in one file
diff --git a/exampleData/ruleSets/buildCombinedRules.sh b/exampleData/ruleSets/buildCombinedRules.sh
new file mode 100755
index 0000000..df4782d
--- /dev/null
+++ b/exampleData/ruleSets/buildCombinedRules.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+#
+# This script builds a collection of FiveUI rulesets (contained in various .json files)
+# into a combined rule sets file: combinedRules.json.
+#
+
+FILES=`ls *.json | grep -v combinedRules`
+OUTFILE="combinedRules.json"
+TMPFILE=`mktemp -t $0`
+HEADER="combinedHeader" # file containing header
+FOOTER="combinedFooter" # file containing footer
+
+function cutstart {
+ echo `cat $1 | grep -n '//---' | awk -F ':' {'print $1'} | head -1`
+}
+function cutend {
+ echo `cat $1 | grep -n '//---' | awk -F ':' {'print $1'} | tail -1`
+}
+
+cat $HEADER > $OUTFILE
+for file in $FILES; do
+ CUTSTART=`cutstart $file`
+ CUTEND=`cutend $file`
+ echo "combining: $file"
+ cat $file | head -$(($CUTEND-1)) | tail +$CUTSTART \
+ | sed 's/\/\/,/,/' >> $OUTFILE
+done
+LEN=`wc -l $OUTFILE | awk '{print $1}'`
+cat $OUTFILE | head -$((LEN-1)) > $TMPFILE
+echo "}" >> $TMPFILE
+mv $TMPFILE $OUTFILE
+cat $FOOTER >> $OUTFILE
diff --git a/exampleData/ruleSets/colorRules.json b/exampleData/ruleSets/colorRules.json
index c2862e4..1cea5a0 100644
--- a/exampleData/ruleSets/colorRules.json
+++ b/exampleData/ruleSets/colorRules.json
@@ -1,99 +1,87 @@
/* colorRules.json
- * Author: Benjamin Jones <bjones@galois.com>
*
* Simple rules for checking that the colors of specific elements are in a specific set.
* Test using exampleData/basic/testColorRules.html
*/
-{ 'name': "Colors are in a specified set"
-, 'description': "All background and foreground colors used on a page should be in a specificed set"
+{ 'name': "Color Guidelines"
+, 'description': "Foreground/background color guidelines"
, 'rules': [
- { 'name': "Foregrounds"
- , 'description': "Foreground colors should be in the set:"+
- "'#0, #FFFFFF, #3D3D3D, #B4B4B4, #4E4E4E, #C2C2C2, #F7F7F7"
- , 'rule':
- function() { //----------------------------------------------
- var allowableColors = { '#0': 1, '#FFFFFF': 1, '#3D3D3D': 1,
- '#B4B4B4': 1, '#4E4E4E': 1, '#C2C2C2': 1,
- '#F7F7F7': 1 };
- fiveui.query(':visible').each(
- function(i, elt) {
- var color = $(elt).css('color');
- if (!(fiveui.color.color.colorToHex(color) in allowableColors)) {
- report('Disallowed FOREground color ' +
- fiveui.color.colorToHex(color) +
- ' appears', $(elt));
- }
- });
- } //---------------------------------------------------------
- },//==============================================================
- { 'name': "Backgrounds"
- , 'description': "Backgrounds colors are in the set:" +
- "#000000, #FFFFFF, #3D3D3D, #B4B4B4, #4E4E4E, #C2C2C2"
- , 'rule':
- function() { //----------------------------------------------
- var allowableColors = { '#0': 1, '#FFFFFF': 1,
- '#3D3D3D': 1, '#B4B4B4': 1, '#4E4E4E': 1,
- '#C2C2C2': 1 };
- fiveui.query(':visible').each(
- function(i, elt) {
- var color = $(elt).css('background-color');
- if (!(fiveui.color.colorToHex(color) in allowableColors)) {
- report('Disallowed BACKground color ' +
- fiveui.color.colorToHex(color) +
- ' appears', $(elt));
- }
- });
- } //---------------------------------------------------------
- },//==============================================================
- { 'name': "Content Area Color"
- , 'description': "Content Area Color should be #F7"
- , 'rule':
- //----------
- function() {
- var allowableColors = { '#F7F7F7': 1 };
- fiveui.query("#content").each(
- function(i, elt) {
- var color = $(elt).css('color');
- if (!(fiveui.color.colorToHex(color) in allowableColors)) {
- report('Invalid color '+fiveui.color.colorToHex(color) +
- ' in content area', $(elt));
- }
- });
- } //---------------------------------------------------------
- },//==============================================================
- { 'name': "Left Nav Color"
- , 'description': "Left Nav Color should be #C2 (#4E if active)"
- , 'rule':
- //----------
- function() {
- var allowableColors = { '#C2C2C2': 1 };
- fiveui.query("#nav-left").each(
- function(i, elt) {
- var color = $(elt).css('color');
- // if active then .. 4E
- if (!(fiveui.color.colorToHex(color) in allowableColors)) {
- report('Invalid color '+fiveui.color.colorToHex(color) +
- ' in left nav area', $(elt));
- }
- });
- } //---------------------------------------------------------
- },//==============================================================
- { 'name': "Header Color"
- , 'description': "Header Color should be #3D"
- , 'rule':
- //----------
- function() {
- var allowableColors = { '#3D3D3D': 1 };
- fiveui.query(":header").each(
- function(i, elt) {
- var color = $(elt).css('color');
- if (!(fiveui.color.colorToHex(color) in allowableColors)) {
- report('Invalid color '+fiveui.color.colorToHex(color) +
- ' in header', $(elt));
- }
- });
- } //---------------------------------------------------------
- } //==============================================================
- ]
+ //----------------------------------------------------------------
+ { 'name': "Foreground check"
+ , 'description': "Foreground colors should be in the set:"+
+ "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738"
+ , 'rule':
+ function () {
+ var allow = "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738".split(" ");
+ $5(":visible")
+ .cssIsNot("color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("color"));
+ report("foreground color: " + color, elt);
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Background check"
+ , 'description': "Backgrounds colors should be in the set:" +
+ "#00 #FF #3D #F7 #C2 #B4 #4E"
+ , 'rule':
+ function () {
+ var allow = "#00 #FF #3D #F7 #C2 #B4 #4E".split(" ");
+ $5(":visible")
+ .cssIsNot("background-color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("background-color"));
+ report("non-standard background color: " + color, elt);
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Content area color"
+ , 'description': "Background color should be: " +
+ "#F7"
+ , 'rule':
+ function () {
+ var allow = "#F7";
+ $5("#content")
+ .cssIsNot("background-color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("background-color"));
+ report("non-standard content background color: " + color, elt);
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Left navigation color"
+ , 'description': "Left navigation color should be: " +
+ "#C2"
+ , 'rule':
+ function () {
+ var allow = "#C2";
+ $5("#leftNav")
+ .cssIsNot("color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("color"));
+ report("non-standard left navigation color: " + color, elt);
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Header color check"
+ , 'description': "Header color should be: " +
+ "#3D"
+ , 'rule':
+ function () {
+ var allow = "#3D";
+ $5(":header")
+ .cssIsNot("color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("color"));
+ report("non-standard header color: " + color, elt);
+ });
+ }
+ }//,
+ //----------------------------------------------------------------
+]
}
diff --git a/exampleData/ruleSets/colorRulesRF.json b/exampleData/ruleSets/colorRulesRF.json
deleted file mode 100644
index 36ef0af..0000000
--- a/exampleData/ruleSets/colorRulesRF.json
+++ /dev/null
@@ -1,20 +0,0 @@
-/* colorRules.json
- * Author: Benjamin Jones <bjones@galois.com>
- *
- * Simple rules for checking that the colors of specific elements are in a specific set.
- * Test using exampleData/basic/testColorRules.html
- */
-
-{ 'name': "Colors are in a specified set"
-, 'description': "All background and foreground colors used on a page should be in a specificed set"
-, 'rules': [
- { 'name': "Foregrounds"
- , 'description': "Foreground colors should be in the set:"+
- "'#0, #FFFFFF, #3D3D3D, #B4B4B4, #4E4E4E, #C2C2C2, #F7F7F7"
- , 'rule': function () {
- (fiveui.color.colorCheck(':visible', [ '#0', '#000000', '#FFFFFF', '#3D3D3D', '#B4B4B4', '#4E4E4E', '#C2C2C2', '#F7F7F7' ]))();
- },
- 'id': 1
- }
- ]
-}
diff --git a/exampleData/ruleSets/combinedFooter b/exampleData/ruleSets/combinedFooter
new file mode 100644
index 0000000..81ba4b6
--- /dev/null
+++ b/exampleData/ruleSets/combinedFooter
@@ -0,0 +1 @@
+]}
diff --git a/exampleData/ruleSets/combinedHeader b/exampleData/ruleSets/combinedHeader
new file mode 100644
index 0000000..4843e16
--- /dev/null
+++ b/exampleData/ruleSets/combinedHeader
@@ -0,0 +1,3 @@
+{ 'name': "Combined color, font, image, and text rules"
+, 'description': "Site colors, fonts, images, and text should conform to these general guidelines"
+, 'rules': [
diff --git a/exampleData/ruleSets/combinedRules.json b/exampleData/ruleSets/combinedRules.json
new file mode 100644
index 0000000..bddfd5a
--- /dev/null
+++ b/exampleData/ruleSets/combinedRules.json
@@ -0,0 +1,236 @@
+{ 'name': "Combined color, font, image, and text rules"
+, 'description': "Site colors, fonts, images, and text should conform to these general guidelines"
+, 'rules': [
+ //----------------------------------------------------------------
+ { 'name': "Foreground check"
+ , 'description': "Foreground colors should be in the set:"+
+ "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738"
+ , 'rule':
+ function () {
+ var allow = "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738".split(" ");
+ $5(":visible")
+ .cssIsNot("color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("color"));
+ report("foreground color: " + color, elt);
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Background check"
+ , 'description': "Backgrounds colors should be in the set:" +
+ "#00 #FF #3D #F7 #C2 #B4 #4E"
+ , 'rule':
+ function () {
+ var allow = "#00 #FF #3D #F7 #C2 #B4 #4E".split(" ");
+ $5(":visible")
+ .cssIsNot("background-color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("background-color"));
+ report("non-standard background color: " + color, elt);
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Content area color"
+ , 'description': "Background color should be: " +
+ "#F7"
+ , 'rule':
+ function () {
+ var allow = "#F7";
+ $5("#content")
+ .cssIsNot("background-color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("background-color"));
+ report("non-standard content background color: " + color, elt);
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Left navigation color"
+ , 'description': "Left navigation color should be: " +
+ "#C2"
+ , 'rule':
+ function () {
+ var allow = "#C2";
+ $5("#leftNav")
+ .cssIsNot("color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("color"));
+ report("non-standard left navigation color: " + color, elt);
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Header color check"
+ , 'description': "Header color should be: " +
+ "#3D"
+ , 'rule':
+ function () {
+ var allow = "#3D";
+ $5(":header")
+ .cssIsNot("color", allow, fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ var color = fiveui.color.colorToHex($(elt).css("color"));
+ report("non-standard header color: " + color, elt);
+ });
+ }
+ },
+ //---------------------------------------------------------
+ { 'name': "Font properties check"
+ , 'description': "Verify that fonts (family, size, weight) are \"standard\""
+ , 'rule':
+ function() {
+ var allow = {
+ "Verdana": { "bold": [25, 22, 12, 10]
+ , "normal": [12, 11, 10] }};
+ fiveui.query('body p,:header').each(
+ function(i, elt) {
+ var font = fiveui.font.getFont($(elt));
+ if (!fiveui.font.validate(allow, font)) {
+ report('non-standard font: ' +
+ font.family + ", " +
+ font.size + ", " +
+ font.weight, $(elt));
+ }
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Banner check"
+ , 'description': "Banner image banner.gif must appear and link to somewhere"
+ , 'severity': 1
+ , 'rule':
+ function() {
+ var elt = $5("div[id=header]"); // get the div with id=header
+ var b = elt.css("background"); // get its background CSS property
+ var l = $5("a[href]", elt).prop("href"); // get the <a href=...> string inside the div
+ if (/banner\.gif/.test(b)) {
+ report("banner.gif missing", elt);
+ }
+ if (l.length == 0) { // this list will be empty if there is no link
+ report("banner.gif link is missing", elt);
+ }
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Image Size check"
+ , 'description': "All site images should have height and width in a given set of choices"
+ , 'severity': 2
+ , 'rule':
+ function() {
+ var allowedDimensions = { 446: { 300: {}} // allow any image with these height:width pairs
+ , 342: { 228: {}}
+ , 150: { 100: {}} };
+ var specialWidths = { 640: {} // allow any image with these special widths
+ , 100: {} };
+ $5("img").not("div.filmstrip *") // skip filmstrip images
+ .each(function (i, elt) {
+ var borderStr = /^[0-9]+/.exec($(elt).css("border")); // compensate for image border
+ var border = borderStr ? parseInt(borderStr[0]) : 0;
+ var w = $(elt).width() + 2*border;
+ var h = $(elt).height() + 2*border;
+ if (!((w in specialWidths) ||
+ (h in allowedDimensions && w in allowedDimensions[h]))) {
+ report("non-standard dimensions "+h+"x"+w, elt);
+ }
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Image Border check"
+ , 'description': "All site images should have 1px solid #3D border"
+ , 'severity': 1
+ , 'rule':
+ function() {
+ var norm = function (s) { return /^\w+\s+\w+/.exec(s)[0]; } // select out first two words of the input
+ var imgs = $5("img").not("div.filmstrip *"); // select images not in the filmstrip
+ imgs.cssIsNot("border", "1px solid", norm)
+ .each(function (i, elt) {
+ report("non-standard border style", elt);
+ });
+ imgs.cssIsNot("border-color", "#3D3D3D", fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ report("non-standard border color", elt);
+ });
+ }
+ },
+ //---------------------------------------------------------
+ { 'name': "Footer check"
+ , 'description': "Footer should appear on the page"
+ , 'rule':
+ function() {
+ if ($5("div.footer").length === 0) {
+ report('Footer does not appear', elt);
+ }
+ }
+ },
+ //---------------------------------------------------------
+ { 'name': "Main content width check"
+ , 'description': "Main content div should be between 520px and 1200px wide"
+ , 'rule':
+ function() {
+ var width;
+ var elt = $5("#content");
+ if (elt) {
+ width = elt.width();
+ if (width > 1200) {
+ report('Main content is too wide: ' + width, elt);
+ } else if (width < 520) {
+ report('Main content is too narrow: ' + width, elt);
+ }
+ }
+ }
+ },
+ //---------------------------------------------------------------
+ { "id": 13
+ , "name": "Sentence case"
+ , "description": "Titles should be written in sentence case"
+ , "rule":
+ function() {
+ var posLength = function(ar) {
+ return 1 <= ar.length;
+ };
+
+ /**
+ * Test str to see if it is in sentence case.
+ */
+ var assertSentenceCase = function(inStr, elt) {
+ var str = fiveui.string.trim(inStr);
+
+ if ( !fiveui.word.capitalized(str[0]) ) {
+ report('The heading: "'+str+'" is not in sentence case.', elt);
+ return;
+ }
+
+ var tokens = str.split(' ').filter(posLength);
+
+ for (var i=1; i < tokens.length; ++i) {
+ if (fiveui.word.capitalized(tokens[i])) {
+ report('The heading: "'+str+'" is not in sentence case.', elt);
+ return;
+ }
+ }
+ };
+
+ fiveui.query(':header').each(function(idx, elt) {
+ assertSentenceCase($(elt).text(), elt);
+ });
+ }
+ },
+ //---------------------------------------------------------------
+ { "id":14
+ , "name": "Capitalization check"
+ , "description": "Capitalize \"Galois\" and \"Galwegian\" when referring to the company"
+ , "rule":
+ function() {
+ fiveui.query('*').hasText('galois').each(function (i, elt) {
+ report('"Galois" should be capitalized', elt);
+ })
+
+ fiveui.query('*').hasText('galwegian').each(function (i, elt) {
+ report('"Galwegian" should be capitalized', elt);
+ })
+ }
+}
+]}
diff --git a/exampleData/ruleSets/fontRules.json b/exampleData/ruleSets/fontRules.json
index 4f6a2d3..6a725d1 100644
--- a/exampleData/ruleSets/fontRules.json
+++ b/exampleData/ruleSets/fontRules.json
@@ -1,42 +1,34 @@
/*
* fontRules.json
- * Author: Benjamin Jones <bjones@galois.com>
*
* Simple rules for checking that fonts (family/weight/size) of specific elements are
* in a specific set.
*
- * Test using exampleData/basic/testFontRules.html
*/
-{ 'name': "Fonts (family/size/style) are in a specified set"
-, 'description': "All fonts used on a page should be in a specificed set"
+{ 'name': "Fonts"
+, 'description': "Guidelines regarding site fonts"
, 'rules': [
- { 'id': 1, 'name': "Font set"
- , 'description': "Font (family/weight/size) should be in the set ..."
- , 'rule':
- function() { //----------------------------------------------
- var allowableFonts = {
- "Verdana": { "bold": ["25", "22", "12", "10"]
- , "normal": ["12", "11", "10"] } ,
- "Arial": { "bold": ["25", "22", "12", "10"]
- , "normal": ["12", "11", "10"] } ,
- "Tahoma": { "bold": ["25", "22", "12", "10"]
- , "normal": ["12", "11", "10"] } }
- fiveui.query('body *').each(
- function(i, elt) {
- var family = $(elt).css('font-family');
- var sizeTxt = $(elt).css('font-size');
- var size = /([1-9][0-9])/.exec(sizeTxt)[0];
- var weight = $(elt).css('font-weight');
- console.log('Found font: ' + family + size + weight);
- if (!(family in allowableFonts) ||
- !(weight in allowableFonts[family]) ||
- !(size in allowableFonts[family][weight])) {
- report('Disallowed font: ' +
- family + size + weight, $(elt));
- }
- });
- } //---------------------------------------------------------
- }//==============================================================
- ]
+ //---------------------------------------------------------
+ { 'name': "Font properties check"
+ , 'description': "Verify that fonts (family, size, weight) are \"standard\""
+ , 'rule':
+ function() {
+ var allow = {
+ "Verdana": { "bold": [25, 22, 12, 10]
+ , "normal": [12, 11, 10] }};
+ fiveui.query('body p,:header').each(
+ function(i, elt) {
+ var font = fiveui.font.getFont($(elt));
+ if (!fiveui.font.validate(allow, font)) {
+ report('non-standard font: ' +
+ font.family + ", " +
+ font.size + ", " +
+ font.weight, $(elt));
+ }
+ });
+ }
+ }//,
+ //---------------------------------------------------------
+]
}
diff --git a/exampleData/ruleSets/imageRules.json b/exampleData/ruleSets/imageRules.json
index 19b0657..05814f9 100644
--- a/exampleData/ruleSets/imageRules.json
+++ b/exampleData/ruleSets/imageRules.json
@@ -1,44 +1,74 @@
/*
* imageRules.json
- * Author: Benjamin Jones <bjones@galois.com>
*
- * Simple rules for checking that specific images appear on a page and that specific images
- * link back to specific URLs.
+ * Simple rules for checking that specific images appear on a page, that specific images
+ * link back to specific URLs, and that image sizes fall into a proscribed set.
*
* Test using exampleData/basic/testImageRules.html
*/
-{ 'name': "Image exists and links back to URL"
-, 'description': "A specific image file should be included in the page and link back to a specific URL"
+{ 'name': "Image Rules"
+, 'description': "General guidelines regarding site images"
, 'rules': [
- { 'id': 1, 'name': "Image appears on page"
- , 'description': "A specific image should appear somewhere on the page."
- , 'rule':
- function() {
- var flag = false;
- fiveui.query("img[src$='star.jpeg']").each(function(i, elt) { flag = true; });
- if (!flag) {
- report('Image star.gif does not appear');
- }
- }
- },
- { 'id': 2, 'name': "Image links back"
- , 'description': "Each instance of a specific image must link back to a specific URL"
- , 'rule':
- function() {
- fiveui.query('a').has('img').each(
- function(i, elt) {
- fiveui.query('img', elt).each(
- function(j, elt2) {
- if (/star.jpeg$/.test(elt2['src']) && !/star/.test(elt['href'])) {
- report('Image star.jpeg does not link back to google');
- }
- }
- );
- }
- );
- }
- }
- ]
+ //----------------------------------------------------------------
+ { 'name': "Banner check"
+ , 'description': "Banner image banner.gif must appear and link to somewhere"
+ , 'severity': 1
+ , 'rule':
+ function() {
+ var elt = $5("div[id=header]"); // get the div with id=header
+ var b = elt.css("background"); // get its background CSS property
+ var l = $5("a[href]", elt).prop("href"); // get the <a href=...> string inside the div
+ if (/banner\.gif/.test(b)) {
+ report("banner.gif missing", elt);
+ }
+ if (l.length == 0) { // this list will be empty if there is no link
+ report("banner.gif link is missing", elt);
+ }
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Image Size check"
+ , 'description': "All site images should have height and width in a given set of choices"
+ , 'severity': 2
+ , 'rule':
+ function() {
+ var allowedDimensions = { 446: { 300: {}} // allow any image with these height:width pairs
+ , 342: { 228: {}}
+ , 150: { 100: {}} };
+ var specialWidths = { 640: {} // allow any image with these special widths
+ , 100: {} };
+ $5("img").not("div.filmstrip *") // skip filmstrip images
+ .each(function (i, elt) {
+ var borderStr = /^[0-9]+/.exec($(elt).css("border")); // compensate for image border
+ var border = borderStr ? parseInt(borderStr[0]) : 0;
+ var w = $(elt).width() + 2*border;
+ var h = $(elt).height() + 2*border;
+ if (!((w in specialWidths) ||
+ (h in allowedDimensions && w in allowedDimensions[h]))) {
+ report("non-standard dimensions "+h+"x"+w, elt);
+ }
+ });
+ }
+ },
+ //----------------------------------------------------------------
+ { 'name': "Image Border check"
+ , 'description': "All site images should have 1px solid #3D border"
+ , 'severity': 1
+ , 'rule':
+ function() {
+ var norm = function (s) { return /^\w+\s+\w+/.exec(s)[0]; } // select out first two words of the input
+ var imgs = $5("img").not("div.filmstrip *"); // select images not in the filmstrip
+ imgs.cssIsNot("border", "1px solid", norm)
+ .each(function (i, elt) {
+ report("non-standard border style", elt);
+ });
+ imgs.cssIsNot("border-color", "#3D3D3D", fiveui.color.colorToHex)
+ .each(function (i, elt) {
+ report("non-standard border color", elt);
+ });
+ }
+ }//,
+ //----------------------------------------------------------------
+]
}
-
diff --git a/exampleData/ruleSets/miscRules.json b/exampleData/ruleSets/miscRules.json
new file mode 100644
index 0000000..7ec4c33
--- /dev/null
+++ b/exampleData/ruleSets/miscRules.json
@@ -0,0 +1,40 @@
+/*
+ * miscRules.json
+ *
+ * Simple rules for checking miscellaneous things.
+ *
+ */
+
+{ 'name': "Misc"
+, 'description': "Miscellaneous rules"
+, 'rules': [
+ //---------------------------------------------------------
+ { 'name': "Footer check"
+ , 'description': "Footer should appear on the page"
+ , 'rule':
+ function() {
+ if ($5("div.footer").length === 0) {
+ report('Footer does not appear', elt);
+ }
+ }
+ },
+ //---------------------------------------------------------
+ { 'name': "Main content width check"
+ , 'description': "Main content div should be between 520px and 1200px wide"
+ , 'rule':
+ function() {
+ var width;
+ var elt = $5("#content");
+ if (elt) {
+ width = elt.width();
+ if (width > 1200) {
+ report('Main content is too wide: ' + width, elt);
+ } else if (width < 520) {
+ report('Main content is too narrow: ' + width, elt);
+ }
+ }
+ }
+ }//,
+ //---------------------------------------------------------
+]
+}
diff --git a/exampleData/ruleSets/textRules.json b/exampleData/ruleSets/textRules.json
new file mode 100644
index 0000000..337bbc4
--- /dev/null
+++ b/exampleData/ruleSets/textRules.json
@@ -0,0 +1,57 @@
+{ "name": "Text capitalization guidelines"
+, "description": "Guidelines regarding capitalization of text withing the page"
+, "rules": [
+ //---------------------------------------------------------------
+ { "id": 13
+ , "name": "Sentence case"
+ , "description": "Titles should be written in sentence case"
+ , "rule":
+ function() {
+ var posLength = function(ar) {
+ return 1 <= ar.length;
+ };
+
+ /**
+ * Test str to see if it is in sentence case.
+ */
+ var assertSentenceCase = function(inStr, elt) {
+ var str = fiveui.string.trim(inStr);
+
+ if ( !fiveui.word.capitalized(str[0]) ) {
+ report('The heading: "'+str+'" is not in sentence case.', elt);
+ return;
+ }
+
+ var tokens = str.split(' ').filter(posLength);
+
+ for (var i=1; i < tokens.length; ++i) {
+ if (fiveui.word.capitalized(tokens[i])) {
+ report('The heading: "'+str+'" is not in sentence case.', elt);
+ return;
+ }
+ }
+ };
+
+ fiveui.query(':header').each(function(idx, elt) {
+ assertSentenceCase($(elt).text(), elt);
+ });
+ }
+ },
+ //---------------------------------------------------------------
+ { "id":14
+ , "name": "Capitalization check"
+ , "description": "Capitalize \"Galois\" and \"Galwegian\" when referring to the company"
+ , "rule":
+ function() {
+ fiveui.query('*').hasText('galois').each(function (i, elt) {
+ report('"Galois" should be capitalized', elt);
+ })
+
+ fiveui.query('*').hasText('galwegian').each(function (i, elt) {
+ report('"Galwegian" should be capitalized', elt);
+ })
+ }
+ }//,
+ //---------------------------------------------------------------
+ ]
+}