Skip to content

Commit

Permalink
Merge pull request #12 from pagarme/fix/optimize-rendering
Browse files Browse the repository at this point in the history
Fix/optimize rendering
  • Loading branch information
osmanpontes authored Feb 8, 2017
2 parents fb000b9 + 64b7129 commit 320bf17
Show file tree
Hide file tree
Showing 3 changed files with 1,002 additions and 23 deletions.
41 changes: 20 additions & 21 deletions lib/boleto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var fs = require('fs')
var ejs = require('ejs')
var formatters = require('./formatters')
var barcode = require('./barcode')
Expand Down Expand Up @@ -65,31 +64,31 @@ Boleto.prototype._calculate = function () {
Boleto.prototype.renderHTML = function (callback) {
var self = this

fs.readFile(path.join(__dirname, '/../assets/layout.ejs'), function (err, content) {
if (err) {
throw err
}

var renderOptions = self.bank.options
renderOptions.boleto = self
var renderOptions = self.bank.options
renderOptions.boleto = self

// Copy renderHelper's methods to renderOptions
for (var key in formatters) {
renderOptions[key] = formatters[key]
}
// Copy renderHelper's methods to renderOptions
for (var key in formatters) {
renderOptions[key] = formatters[key]
}

renderOptions['barcode_render_engine'] = Boleto.barcodeRenderEngine
renderOptions['barcode_height'] = '50'
renderOptions['barcode_render_engine'] = Boleto.barcodeRenderEngine
renderOptions['barcode_height'] = '50'

if (Boleto.barcodeRenderEngine == 'bmp') {
renderOptions['barcode_data'] = barcode.bmpLineForBarcodeData(self['barcode_data'])
} else if (Boleto.barcodeRenderEngine == 'img') {
renderOptions['barcode_data'] = barcode.binaryRepresentationForBarcodeData(self['barcode_data'])
}
if (Boleto.barcodeRenderEngine == 'bmp') {
renderOptions['barcode_data'] = barcode.bmpLineForBarcodeData(self['barcode_data'])
} else if (Boleto.barcodeRenderEngine == 'img') {
renderOptions['barcode_data'] = barcode.binaryRepresentationForBarcodeData(self['barcode_data'])
}

renderOptions['boleto']['linha_digitavel_hash'] = hashString(renderOptions['boleto']['linha_digitavel']).toString()
renderOptions['boleto']['linha_digitavel_hash'] = hashString(renderOptions['boleto']['linha_digitavel']).toString()

var html = ejs.render(content.toString(), renderOptions)
ejs.renderFile(path.join(__dirname, '/../assets/layout.ejs'), renderOptions, {
cache: true
}, function (err, html) {
if (err) {
throw new Error(err)
}

callback(html)
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-boleto",
"version": "2.0.1",
"version": "2.0.2",
"description": "Boleto generator in Node.js",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"url": "https://github.com/pagarme/node-boleto"
},
"dependencies": {
"ejs": "1.0.0"
"ejs": "2.5.5"
},
"devDependencies": {
"chai": "^3.5.0",
Expand Down
Loading

0 comments on commit 320bf17

Please sign in to comment.