Skip to content

Commit

Permalink
added functionality to convert and display response data to html list
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantPawar committed Mar 17, 2017
1 parent 6f15385 commit 7ba6705
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
],
"globals": {
"chrome": true,
"document": true,
"DOMParser": true,
"fetch": true,
"URL": true,
"WebSocket": true
Expand Down
19 changes: 19 additions & 0 deletions app/scripts.babel/lib/HtmlUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const jobList = html => `<ul>${html}</ul>`;
const listItem = job => `<li><a href="${job.link}">${job.title}</a></li>`;

const textToXml = text => new DOMParser().parseFromString(text, 'text/xml');
const xmlToHtml = (xml) => {
const allJobs = [...xml.getElementsByTagName('entry')];

const html = allJobs.map((job) => {
const title = job.getElementsByTagName('title')[0].childNodes[0].nodeValue;
const link = job.getElementsByTagName('link')[0].getAttribute('href');

return listItem({ link, title });
});

return jobList(html.join(''));
};
const appendData = (html) => { document.querySelector('.page-content').innerHTML = html; };

export { textToXml, xmlToHtml, appendData };
5 changes: 4 additions & 1 deletion app/scripts.babel/popup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tabUrl from './lib/ActiveTabUrl';
import jobFeedUrl from './lib/HasjobFeedUrl';
import { makeRequest, checkStatus, responseText, handleError } from './lib/RequestUtils';
import { textToXml, xmlToHtml, appendData } from './lib/HtmlUtils';

const processTabUrl = new Promise(tabUrl);

Expand All @@ -9,5 +10,7 @@ processTabUrl
.then(makeRequest)
.then(checkStatus)
.then(responseText)
.then((data) => { console.log(data); }) // eslint-disable-line
.then(textToXml)
.then(xmlToHtml)
.then(appendData)
.catch(handleError);

0 comments on commit 7ba6705

Please sign in to comment.