New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-angular-gettext-annotate

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-angular-gettext-annotate - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test/expected/testBindingsAndWhitespaces.html

46

index.js

@@ -12,3 +12,3 @@ 'use strict';

options = _.extend({
inlineTags: ['br', 'b', 'i', 'u', 'strong'],
inlineTags: ['br', 'b', 'i', 'u', 'strong', 'a'],
attributesToAnnotate: ['placeholder', 'title', 'alt']

@@ -36,2 +36,13 @@ }, options);

// We don't annotate anything in <head>
var parents = node.parents();
if (!_.isEmpty(_.where(_.values(parents), {name: 'head'}))) {
return;
}
// We don't annotate <style> and <script>
if (node[0].type == 'style' || node[0].type == 'script') {
return;
}
if (node[0].children.length === 1) {

@@ -45,4 +56,3 @@ // If there is only one child it can be:

var text = node[0].children[0].data.trim();
if (!(text.substr(0, 2) === '{{' && text.indexOf('}}') === text.length - 2) &&
typeof node.parent().attr('translate') === 'undefined') {
if (!containsBindingsOnly(text) && typeof node.parent().attr('translate') === 'undefined') {
annotate = true;

@@ -65,4 +75,20 @@ }

// If all text nodes are whitespaces we annotate child tag node(s).
//
// We're also checking if every child is text node and is either
// whitespace or binding. If so, we don't annotate it. Example:
// <div>
// {{test1}} {{test2}}
// </div>
annotate = annotate && !_.every(node[0].children, function(child) {
return (child.type === 'tag' || (child.type === 'text' && child.data.trim() === ''));
if (child.type === 'tag') {
return true;
}
if (child.type === 'text') {
var text = child.data.trim();
// Empty string or binding
return (text === '' || containsBindingsOnly(text));
}
return true;
});

@@ -96,2 +122,14 @@ }

node.attr(attr, val);
}
/**
* Returns true if string contains bindings ({{test}}) and whitespaces only.
* @param string
* @returns bool
*/
function containsBindingsOnly(string) {
var parts = string.split(/{{.+?}}/);
return _.every(parts, function(part) {
return (part.trim() === '');
})
}

2

package.json
{
"name": "gulp-angular-gettext-annotate",
"version": "0.0.1",
"version": "0.0.2",
"description": "Gulp plugin for adding angular-gettext annotations to templates.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -14,2 +14,8 @@ 'use strict';

describe('gulp-angular-gettext-annotate', function () {
afterEach(function(done){
// Remove annotated files
del.sync('test/annotated');
done();
});
it('should annotate node with binding and text', function (done) {

@@ -31,2 +37,22 @@ test('test/templates/testManyBindingsInTextNode.html', done);

it('should not annotate anything in <head>', function (done) {
test('test/templates/testHead.html', done);
});
it('should not annotate anything in <script> and <style>', function (done) {
test('test/templates/testScriptStyle.html', done);
});
it('should not annotate nodes with bindings and whitespaces only', function (done) {
test('test/templates/testBindingsAndWhitespaces.html', done);
});
it('should not annotate nodes with bindings, tags and whitespaces only', function (done) {
test('test/templates/testBindingsInlineTagsAndWhitespaces.html', done);
});
it('should annotate lowest level nodes only', function (done) {
test('test/templates/testEmptyTextNodes.html', done);
});
it('should annotate stellar-client templates correctly', function (done) {

@@ -54,6 +80,4 @@ test('test/templates/stellar-*.html', done);

// Remove annotated files
del.sync('test/annotated');
done();
});
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc