Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outline #27

Merged
merged 4 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 39 additions & 38 deletions classes/comment.js
Original file line number Diff line number Diff line change
@@ -1,45 +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)
cat = cat ? cat[1] : 'Outros'
let testCat = cat.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"
}
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
}
}
1 change: 0 additions & 1 deletion classes/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ class Github {
})
}
}

62 changes: 31 additions & 31 deletions classes/markdown.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
window.markdown = {
toHTML (str) {
str = markdown.applyLinks(str)
str = markdown.applyBold(str)
str = markdown.applyItalic(str)
str = markdown.applyNewLines(str)
return str
},
applyNewLines (str) {
return str.trim().replace(/(\n\r?)|(\<br\/?\>)/g, '&nbsp;&nbsp;<br />')
},
applyBold (str) {
const boldRX = /[\*_][\*_](.+)[\*_][\*_]/
while(link = str.match(boldRX)) {
str = str.replace(boldRX, '<strong>$1</strong>')
}
return str
},
applyItalic (str) {
const italicRX = /[\*_](.+)[\*_]/
while(link = str.match(italicRX)) {
str = str.replace(italicRX, '<em>$1</em>')
}
return str
},
applyLinks (str) {
const linkRX = /\[([^\]]+)\]\(([^\)]+)\)/
while(link = str.match(linkRX)) {
str = str.replace(linkRX, '<a href="$2"target="_blank">$1</a>')
}
return str
toHTML(str) {
str = markdown.applyLinks(str)
str = markdown.applyBold(str)
str = markdown.applyItalic(str)
str = markdown.applyNewLines(str)
return str
},
applyNewLines(str) {
return str.trim().replace(/(\n\r?)|(\<br\/?\>)/g, '&nbsp;&nbsp;<br />')
},
applyBold(str) {
const boldRX = /[\*_][\*_](.+)[\*_][\*_]/
while ((link = str.match(boldRX))) {
str = str.replace(boldRX, '<strong>$1</strong>')
}
}
return str
},
applyItalic(str) {
const italicRX = /[\*_](.+)[\*_]/
while ((link = str.match(italicRX))) {
str = str.replace(italicRX, '<em>$1</em>')
}
return str
},
applyLinks(str) {
const linkRX = /\[([^\]]+)\]\(([^\)]+)\)/
while ((link = str.match(linkRX))) {
str = str.replace(linkRX, '<a href="$2"target="_blank">$1</a>')
}
return str
}
}
173 changes: 84 additions & 89 deletions classes/ui.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
const style = "mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;color: #2BAADF;font-weight: normal;text-decoration: underline;"
const style =
'mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;color: #2BAADF;font-weight: normal;text-decoration: underline;'

const UI = {
currentIssue: null,
currentWeekly: null,
main: document.getElementById('container'),
HTML: {
main: document.getElementById('html-container'),
title: document.getElementById('TAG_title'),
contributors: document.getElementById('TAG_CONTRIBUTORS'),
news: document.getElementById('TAG_NEWS_LIST'),
categories: document.getElementById('TAG_CATEGORIES'),
},

update (weekly, type = 'html') {
if (typeof weekly === 'string' && UI.currentWeekly) {
type = weekly
weekly = UI.currentWeekly
}
UI.applyHeader(weekly, type)
UI.HTML.news.innerHTML = '<strong>Tags:</strong> ' + UI.applyCategory(weekly, 'Notícias', type).join(' - ')
//UI.applyCartoon(weekly, type)

$(".comment-item").sortable({
handle: ".drag-handler",
placeholder: "placeholder"
})
$(".category-item").disableSelection();
$(".delete-handler").click(event => {
if (window.confirm('Are you sure you want to remove this item?')) {
let target = event.target.parentNode
target.parentNode.removeChild(target)
}
})
new Clipboard('.copy-btn')
UI.currentWeekly = weekly
},
applyHeader (weekly) {
UI.HTML.title.innerHTML = `${weekly.title}`
UI.HTML.contributors.innerHTML = `
currentIssue: null,
currentWeekly: null,
main: document.getElementById('container'),
HTML: {
main: document.getElementById('html-container'),
title: document.getElementById('TAG_title'),
contributors: document.getElementById('TAG_CONTRIBUTORS'),
news: document.getElementById('TAG_NEWS_LIST'),
categories: document.getElementById('TAG_CATEGORIES')
},

update(weekly, type = 'html') {
if (typeof weekly === 'string' && UI.currentWeekly) {
type = weekly
weekly = UI.currentWeekly
}
UI.applyHeader(weekly, type)
UI.HTML.news.innerHTML = '<strong>Tags:</strong> ' + UI.applyCategory(weekly, 'Notícias', type).join(' - ')
//UI.applyCartoon(weekly, type)

$('.comment-item').sortable({
handle: '.drag-handler',
placeholder: 'placeholder'
})
$('.category-item').disableSelection()
$('.delete-handler').click(event => {
if (window.confirm('Are you sure you want to remove this item?')) {
let target = event.target.parentNode
target.parentNode.removeChild(target)
}
})
new Clipboard('.copy-btn')
UI.currentWeekly = weekly
},
applyHeader(weekly) {
UI.HTML.title.innerHTML = `${weekly.title}`
UI.HTML.contributors.innerHTML = `
Um agradecimento especial aos
<strong>${Object.keys(weekly.contributors).length}</strong>
<a href="${urlGithub}/${weekly.number}"
target="_blank" style=${style}>colaboradores</a> da edição nº
<strong>${weekly.edition}</strong>!
<br><br>
${
Object.keys(weekly.contributors).map(key => {
let contrib = weekly.contributors[key]
return `
${Object.keys(weekly.contributors)
.map(key => {
let contrib = weekly.contributors[key]
return `
<a href="${contrib.url}" style=${style}>
<img
alt="${contrib.login}"
Expand All @@ -57,30 +58,30 @@ const UI = {
style="border: 0;height: auto !important;outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;"
></a>&nbsp;
`
}).join(' ')
}
})
.join(' ')}
`
},
applyCategory (weekly, filterName, type) {
let outputStr = ''

const categoriesName = Object.keys(weekly.categories).sort()
const notNews = categoriesName.filter( item => item !== filterName)
const onlyNews = categoriesName.filter( item => item === filterName)

onlyNews.forEach( item => {
outputStr += UI.applyDesignCategory(weekly, item, type)
})

notNews.forEach( item => {
outputStr += UI.applyDesignCategory(weekly, item, type)
})
UI.HTML.categories.innerHTML = outputStr
return categoriesName
},
applyDesignCategory (weekly, cat, type) {
let categoryHTML = `
},
applyCategory(weekly, filterName, type) {
let outputStr = ''

const categoriesName = Object.keys(weekly.categories).sort()
const notNews = categoriesName.filter(item => item !== filterName)
const onlyNews = categoriesName.filter(item => item === filterName)

onlyNews.forEach(item => {
outputStr += UI.applyDesignCategory(weekly, item, type)
})

notNews.forEach(item => {
outputStr += UI.applyDesignCategory(weekly, item, type)
})

UI.HTML.categories.innerHTML = outputStr
return categoriesName
},
applyDesignCategory(weekly, cat, type) {
let categoryHTML = `
<table class="mcnBoxedTextBlock" style="min-width: 100%;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;" width="100%" cellspacing="0" cellpadding="0" border="0">

<!--[if gte mso 9]>
Expand Down Expand Up @@ -129,7 +130,7 @@ const UI = {
</table>
`

let listHTML = `
let listHTML = `
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnTextBlock" style="min-width: 100%;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">
<tbody class="mcnTextBlockOuter">
<tr>
Expand All @@ -149,34 +150,33 @@ const UI = {
<tr>
<td valign="top" class="mcnTextContent" style="padding-top: 0;padding-right: 18px;padding-bottom: 9px;padding-left: 18px;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;word-break: break-word;color: #202020;font-family: Helvetica;font-size: 16px;line-height: 150%;text-align: left;">
<div id="${cat}" class="comment-item" style="margin: 0px 0px 2px;padding: 5px;position: relative;color: #000000;font-family: &quot;Times New Roman&quot;;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;white-space: normal;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;">
${
weekly.categories[cat].map(item => {
return `
${weekly.categories[cat]
.map(item => {
return `
<div class="category-item" style="padding: 1rem 0;">
${
type === 'html'
? item.htmlBody
: type === 'md'
? item.mdBody
: item.outline
type === 'html'
? item.htmlBody
: type === 'md'
? item.mdBody
: item.outline
}
${
type !== 'outline'
? `
type !== 'outline'
? `
<br>
<em>Indicado por&nbsp;
<a
href="${item.author.url}" target="_blank"
style="${style}">@${item.author.login}
</a>
style="${style}">@${item.author.login}</a>
</em>`
: ''
: ''
}
<br>
</div>
`
}).join('')
}
})
.join('')}
</div>
</td>
</tr>
Expand All @@ -198,14 +198,9 @@ const UI = {
</table>
`
return categoryHTML + listHTML
},
applyCartoon (weekly) {
},
applyCartoon(weekly) {
// if (!weekly.categories.cartoon) {

// }
}
}
}




Loading