test: check replaced iff translatable comment
All translatable comments should be replaced, but nothing else.
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
d2ecd03013
commit
793fa8fb52
29
curriculum/test/utils/plugins/get-css-comments.js
Normal file
29
curriculum/test/utils/plugins/get-css-comments.js
Normal file
@ -0,0 +1,29 @@
|
||||
const { isEmpty } = require('lodash');
|
||||
const visit = require('unist-util-visit');
|
||||
var css = require('css');
|
||||
var visitCss = require('rework-visit');
|
||||
const { commentToData } = require('../comment-to-data');
|
||||
|
||||
function plugin() {
|
||||
return transformer;
|
||||
|
||||
function transformer(tree, file) {
|
||||
if (isEmpty(file.data)) file.data = {};
|
||||
visit(tree, { type: 'element', tagName: 'style' }, styleVisitor);
|
||||
|
||||
function styleVisitor(node) {
|
||||
visit(node, 'text', cssVisitor);
|
||||
}
|
||||
function cssVisitor(node) {
|
||||
const ast = css.parse(node.value);
|
||||
visitCss(ast.stylesheet, dec => {
|
||||
let comments = dec
|
||||
.filter(({ type }) => type === 'comment')
|
||||
.map(({ comment }) => comment.trim());
|
||||
comments.forEach(comment => commentToData(file, comment));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = plugin;
|
20
curriculum/test/utils/plugins/get-html-comments.js
Normal file
20
curriculum/test/utils/plugins/get-html-comments.js
Normal file
@ -0,0 +1,20 @@
|
||||
const { isEmpty } = require('lodash');
|
||||
const visit = require('unist-util-visit');
|
||||
const { commentToData } = require('../comment-to-data');
|
||||
|
||||
function plugin() {
|
||||
return transformer;
|
||||
|
||||
function transformer(tree, file) {
|
||||
if (isEmpty(file.data)) {
|
||||
file.data = {};
|
||||
}
|
||||
visit(tree, 'comment', visitor);
|
||||
|
||||
function visitor(node) {
|
||||
commentToData(file, node.value.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = plugin;
|
Reference in New Issue
Block a user