Skip to content

Commit

Permalink
Make --files-from work like in gettext
Browse files Browse the repository at this point in the history
Fixes gmarty#74
  • Loading branch information
sareyko committed Oct 1, 2018
1 parent 47e29b9 commit 323abca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ function xgettext(input, options, cb) {
if (options['files-from']) {
input = fs.readFileSync(options['files-from'], options['from-code'])
.split('\n')
.map(function (line) {
return line.split('').reduceRight(function(acc, c) {
if (' \t\r'.indexOf(c) === -1 || acc.length > 0) {
return c + acc;
}
return acc;
}, '');
})
.filter(function (line) {
return line.trim().length > 0;
});
Expand Down
20 changes: 20 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ describe('CLI', function () {
});
});

it('should read input from a CR LF delimited file', function (done) {
run(['--output=-', '--files-from=fixtures/list-crlf.txt'], function (err) {
throw new Error(err);
}, function (code, data) {
assert.equal(0, code);
assert(data.match('This is a fixed sentence'));
done();
});
});

it('should read input from a HT delimited file', function (done) {
run(['--output=-', '--files-from=fixtures/list-ht.txt'], function (err) {
throw new Error(err);
}, function (code, data) {
assert.equal(0, code);
assert(data.match('This is a fixed sentence'));
done();
});
});

it('should handle stdin input', function (done) {
var child = run(['--output=-', '--language=Handlebars', '--from-code=utf8', '-'], function (err) {
throw new Error(err);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/list-crlf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixtures/template.hbs
1 change: 1 addition & 0 deletions test/fixtures/list-ht.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixtures/template.hbs

0 comments on commit 323abca

Please sign in to comment.