Skip to content

Commit

Permalink
Criado filter para formata número de boleto bancário em views (HTML)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Loureiro committed May 6, 2015
1 parent 51f05ee commit 2ba7080
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ <h1>Boleto bancário</h1>
</span>
</div>

<div class="form-group">
<label>Boleto usando a máscara de boleto</label>
<p>{{$parent.boleto | boleto}}</p>
</div>

</ng-form>
</div><!-- /.container -->

Expand Down
23 changes: 23 additions & 0 deletions app/scripts/angular-boleto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

angular.module('angular.boleto', ['ui.mask'])

.filter('boleto', ['$filter', function ($filter) {
return function (boleto) {
if (typeof boleto !== 'undefined') {
var boleto = boleto.replace(/[^0-9-]/g,'');

if (boleto === '') {
return '';
}

var boletoFormatado = boleto.slice(0, 5) + '.';
boletoFormatado = boletoFormatado + boleto.slice(5, 10) + ' ';
boletoFormatado = boletoFormatado + boleto.slice(10, 15) + '.';
boletoFormatado = boletoFormatado + boleto.slice(15, 21) + ' ';
boletoFormatado = boletoFormatado + boleto.slice(21, 26) + '.';
boletoFormatado = boletoFormatado + boleto.slice(26, 32) + ' ';
boletoFormatado = boletoFormatado + boleto.slice(32, 33) + ' ';
boletoFormatado = boletoFormatado + boleto.slice(33, 47);

return boletoFormatado;
}
};
}])

.filter('utc', ['$filter', function ($filter) {
return function (date, format) {
var dateOk, dateResult;
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/angular-boleto.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-boleto",
"version": "0.1.2",
"version": "0.1.3",
"homepage": "https://github.com/bernardolm/angular-boleto",
"authors": [
"Bernardo Loureiro <bernardo.lou@gmail.com> (http://bernardoloureiro.com.br)"
Expand Down
20 changes: 20 additions & 0 deletions test/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,24 @@ describe('Testando Filters:', function() {
expect(dateUTC).toBe('01/09/2014');
});
});

describe('boleto:', function() {
it('0-boleto deve estar definido', function() {
expect($filter('boleto')).toBeDefined();
});

it('1-boleto', function() {
var boleto = '21890010070014560208200371313180159470127456789';
var boletoFormatado = $filter('boleto')(boleto);

expect(boletoFormatado).toBe('21890.01007 00145.602082 00371.313180 1 59470127456789');
});

it('2-boleto', function() {
var boleto = '';
var boletoFormatado = $filter('boleto')(boleto);

expect(boletoFormatado).toBe('');
});
});
});

0 comments on commit 2ba7080

Please sign in to comment.