Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RenatoSiqueira committed Oct 8, 2018
1 parent 0f55e72 commit 487ef99
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 107 deletions.
79 changes: 39 additions & 40 deletions classes/comment.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@

class Comment {
constructor (data = {}) {
this.applyData(data)
}
constructor(data = {}) {
this.applyData(data)
}

applyData (data) {
this.mdBody = data.body
this.htmlBody = window.markdown.toHTML(data.body)
this.title = this.mdBody.match(/^[\*_][\*_]\[(.+)\].+[\*_][\*_][\n\r]/)
this.title = this.title ? this.title[1] : ''
this.link = this.mdBody.match(/^[\*_][\*_].+\((.+)\)[\*_][\*_][\n\r]/)
this.link = this.link ? this.link[1] : ''
this.outline = `<a href="${this.link}">${this.title}</a>:<br/>${this.link}<br/>`
this.created_at = data.created_at
this.id = data.id
this.url = data.url
this.author = {
id: data.user.id,
login: data.user.login,
avatar: data.user.avatar_url,
url: data.user.html_url
}
this.applyCategory()
applyData(data) {
this.mdBody = data.body
this.htmlBody = window.markdown.toHTML(data.body)
this.title = this.mdBody.match(/^[\*_][\*_]\[(.+)\].+[\*_][\*_][\n\r]/)
this.title = this.title ? this.title[1] : ''
this.link = this.mdBody.match(/^[\*_][\*_].+\((.+)\)[\*_][\*_][\n\r]/)
this.link = this.link ? this.link[1] : ''
this.outline = `<a href="${this.link}">${this.title}</a>:<br/>${this.link}<br/>`
this.created_at = data.created_at
this.id = data.id
this.url = data.url
this.author = {
id: data.user.id,
login: data.user.login,
avatar: data.user.avatar_url,
url: data.user.html_url
}
this.applyCategory()
}

applyCategory () {
let cat = this.mdBody.match(/[\n\r][\*_](.+)[\*_]$/m)
let testCat = cat[1].toLowerCase()
applyCategory() {
let cat = this.mdBody.match(/[\n\r][\*_](.+)[\*_]$/m)
let testCat = cat[1].toLowerCase()

if (testCat.match(/(new|not.cia|novidade|an.nci|announc)/)) {
cat = "Notícias"
} else if (testCat.match(/(event|confer.ncia|summit|workshop|congresso)/)) {
cat = "Eventos"
} else if (testCat.match(/(artigo|article|text|post)/)) {
cat = "Artigos"
} else if (testCat.match(/(talk|palestr|aula|curso|v.deo)/)) {
cat = "Vídeos"
} else if (testCat.match(/(tool|demo|experiment|ferrament)/)) {
cat = "Demos e Ferramentas"
} else {
cat = 'Outros'
}

this.category = cat
if (testCat.match(/(new|not.cia|novidade|an.nci|announc)/)) {
cat = 'Notícias'
} else if (testCat.match(/(event|confer.ncia|summit|workshop|congresso)/)) {
cat = 'Eventos'
} else if (testCat.match(/(artigo|article|text|post)/)) {
cat = 'Artigos'
} else if (testCat.match(/(talk|palestr|aula|curso|v.deo)/)) {
cat = 'Vídeos'
} else if (testCat.match(/(tool|demo|experiment|ferrament)/)) {
cat = 'Demos e Ferramentas'
} else {
cat = 'Outros'
}

this.category = cat
}
}
3 changes: 1 addition & 2 deletions classes/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ const UI = {
<em>Indicado por&nbsp;
<a
href="${item.author.url}" target="_blank"
style="${style}">@${item.author.login}
</a>
style="${style}">@${item.author.login}</a>
</em>`
: ''
}
Expand Down
122 changes: 57 additions & 65 deletions classes/weekly.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,63 @@

class Weekly {
constructor (data) {
this.applyData(data)
this.state = "partial"
this.loadComments().then(UI.update)
this.contributors = {}
this.categories = {}
}
static isValid (data) {
if (
data.title.startsWith('Edição ') &&
data.repository_url === "https://api.github.com/repos/braziljs/weekly"
) {
if (data.labels.find(item => item.name === "campaign")) {
return true
}
}
return false
}
applyData (data) {
this.id = data.id
this.title = data.title
this.number = data.number
this.edition = this.title.match(' ([0-9]+) ')[1] || 0,
this.created_at = data.created_at
this.closed_at = data.closed_at
this.state = data.state
constructor(data) {
this.applyData(data)
this.state = 'partial'
this.loadComments().then(UI.update)
this.contributors = {}
this.categories = {}
}
static isValid(data) {
if (data.title.startsWith('Edição ') && data.repository_url === 'https://api.github.com/repos/braziljs/weekly') {
if (data.labels.find(item => item.name === 'campaign')) {
return true
}
}
filterData (data) {
const { id, number, created_at, closed_at, title, state } = data
return {
id,
number,
edition: this.title.match(' ([0-9]+) ')[1] || 0,
created_at,
closed_at,
title,
state
}
return false
}
applyData(data) {
this.id = data.id
this.title = data.title
this.number = data.number
;(this.edition = this.title.match(' ([0-9]+) ')[1] || 0), (this.created_at = data.created_at)
this.closed_at = data.closed_at
this.state = data.state
}
filterData(data) {
const { id, number, created_at, closed_at, title, state } = data
return {
id,
number,
edition: this.title.match(' ([0-9]+) ')[1] || 0,
created_at,
closed_at,
title,
state
}
loadComments () {
return new Promise((resolve, reject) => {
if (this.comments) {
return resolve(this.comments)
}
Github.get('comments', { issue: this.number })
.then(comments => {
comments.forEach(data => {

if(data.body.charAt(0) !== '*')
data.body = this.applyMarkdown(data.body)
}
loadComments() {
return new Promise((resolve, reject) => {
if (this.comments) {
return resolve(this.comments)
}
Github.get('comments', { issue: this.number }).then(comments => {
comments.forEach(data => {
if (data.body.charAt(0) !== '*') data.body = this.applyMarkdown(data.body)

this.addComment(new Comment(data))
})
resolve(this)
})
this.addComment(new Comment(data))
})
}
addComment (comment) {
this.contributors[comment.author.id] = comment.author
this.categories[comment.category] = this.categories[comment.category] || []
this.categories[comment.category].push(comment)
}
applyMarkdown (item){
item = item.replace(/^\[/, '**[')
item = item.replace(/\)/, ')**')
item = item.trim().replace(/(.+\w)$/, '*$1*')
return item
}
resolve(this)
})
})
}
addComment(comment) {
this.contributors[comment.author.id] = comment.author
this.categories[comment.category] = this.categories[comment.category] || []
this.categories[comment.category].push(comment)
}
applyMarkdown(item) {
item = item.replace(/^\[/, '**[')
item = item.replace(/\)/, ')**')
item = item.trim().replace(/(.+\w)$/, '*$1*')
return item
}
}

0 comments on commit 487ef99

Please sign in to comment.