Permalink
Browse files

Download and print HTML with promises

  • Loading branch information...
NickTikhonov committed Aug 18, 2016
1 parent 8599204 commit 896d160dca711f4a53ff5b182018b39cf78d2774
Showing with 15 additions and 5 deletions.
  1. +15 −5 lib/sourcefetch.js
View
@@ -23,15 +23,25 @@ export default {
let editor
if (editor = atom.workspace.getActiveTextEditor()) {
let selection = editor.getSelectedText()
this.download(selection)
this.download(selection).then((html) => {
editor.insertText(html)
}).catch((error) => {
atom.notifications.addWarning(error.reason)
})
}
},
download(url) {
request(url, (error, response, body) => {
if (!error && response.statusCode == 200) {
console.log(body)
}
return new Promise((resolve, reject) => {
request(url, (error, response, body) => {
if (!error && response.statusCode == 200) {
resolve(body)
} else {
reject({
reason: 'Unable to download page'
})
}
})
})
}
};

0 comments on commit 896d160

Please sign in to comment.