-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GS051 rules for custom heading and body fonts (#561)
ref DES-852
- Loading branch information
1 parent
95edb8f
commit 1e8364a
Showing
8 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const _ = require('lodash'); | ||
const spec = require('../specs'); | ||
const versions = require('../utils').versions; | ||
|
||
const checkCustomFontsCssProperties = function checkCustomFontsCssProperties(theme, options) { | ||
const checkVersion = _.get(options, 'checkVersion', versions.default); | ||
let ruleSet = spec.get([checkVersion]); | ||
|
||
// CASE: 051-custom-fonts-css-properties checks only needs `rules` that start with `GS051-` | ||
const ruleRegex = /GS051-.*/g; | ||
|
||
ruleSet = _.pickBy(ruleSet.rules, function (rule, ruleCode) { | ||
if (ruleCode.match(ruleRegex)) { | ||
return rule; | ||
} | ||
}); | ||
|
||
_.each(ruleSet, function (check, ruleCode) { | ||
if (theme.files) { | ||
// Check CSS files and HBS files for presence of the classes | ||
_.each(theme.files, function (themeFile) { | ||
if (!['.css', '.hbs'].includes(themeFile.ext)) { | ||
return; | ||
} | ||
|
||
try { | ||
let cssPresent = themeFile.content.match(check.regex); | ||
|
||
if (cssPresent && theme.results.pass.indexOf(ruleCode) === -1) { | ||
theme.results.pass.push(ruleCode); | ||
} | ||
} catch (err) { | ||
// ignore for now | ||
} | ||
}); | ||
} | ||
|
||
if (!theme.files || (theme.results.pass.indexOf(ruleCode) === -1 && !Object.prototype.hasOwnProperty.call(theme.results.fail, ruleCode))) { | ||
theme.results.fail[ruleCode] = {}; | ||
theme.results.fail[ruleCode].failures = [ | ||
{ | ||
ref: 'styles' | ||
} | ||
]; | ||
} | ||
}); | ||
|
||
return theme; | ||
}; | ||
|
||
module.exports = checkCustomFontsCssProperties; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const should = require('should'); // eslint-disable-line no-unused-vars | ||
const utils = require('./utils'); | ||
const thisCheck = require('../lib/checks/051-custom-fonts-css-properties'); | ||
|
||
describe('051 custom fonts CSS properties', function () { | ||
const options = {checkVersion: 'v5'}; | ||
|
||
it('should show warnings for missing custom heading and body font CSS properties when they are not in any .hbs or .css file', function (done) { | ||
utils.testCheck(thisCheck, '051-custom-fonts-css-properties/missing', options).then((output) => { | ||
output.should.be.a.ValidThemeObject(); | ||
|
||
output.results.pass.should.be.an.Array().which.is.empty(); | ||
|
||
output.results.fail.should.be.an.Object().with.keys('GS051-CUSTOM-FONTS'); | ||
|
||
output.results.fail['GS051-CUSTOM-FONTS'].should.be.a.ValidFailObject(); | ||
|
||
done(); | ||
}).catch(done); | ||
}); | ||
|
||
it('should output nothing when custom heading and body font CSS properties are present', function (done) { | ||
utils.testCheck(thisCheck, '051-custom-fonts-css-properties/valid', options).then((output) => { | ||
output.should.be.a.ValidThemeObject(); | ||
|
||
output.results.pass.should.be.an.Array().with.lengthOf(1); | ||
output.results.pass.should.containEql('GS051-CUSTOM-FONTS'); | ||
|
||
output.results.fail.should.be.an.Object().which.is.empty(); | ||
|
||
done(); | ||
}).catch(done); | ||
}); | ||
}); |
Empty file.
10 changes: 10 additions & 0 deletions
10
test/fixtures/themes/051-custom-fonts-css-properties/missing/default.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<head> | ||
<title>Test Theme</title> | ||
</head> | ||
<body> | ||
|
||
<h1>{{@blog.title}}</h1> | ||
|
||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
test/fixtures/themes/051-custom-fonts-css-properties/valid/assets/my.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
:root { | ||
--gh-font-heading: ""; | ||
--gh-font-body: ""; | ||
} |
12 changes: 12 additions & 0 deletions
12
test/fixtures/themes/051-custom-fonts-css-properties/valid/default.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<html> | ||
<head> | ||
<title>Test Theme</title> | ||
<link rel="stylesheet" type="text/css" href="/assets/css/style.css"> | ||
{{ghost_head}} | ||
</head> | ||
<body> | ||
|
||
<h1>{{@blog.title}}</h1> | ||
{{ghost_foot}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters