Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
pointbar committed May 10, 2016
2 parents a0aaa95 + d7378ad commit 5cfe920
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 127 deletions.
98 changes: 44 additions & 54 deletions dist/dk.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ var Markdown = (function () {
var labelList = '';
this.content.match(/---([\s\S]*?)---/)[1].split('\n').map(function (elt) {
if (!!elt.match(/^\w+:$/)) {
console.log('elt ul', elt);
console.log('labelList ul', labelList);

var _elt$match = elt.match(/^(\w+):$/);

var _elt$match2 = _slicedToArray(_elt$match, 2);
Expand All @@ -258,9 +255,6 @@ var Markdown = (function () {
labelList = label;
}
if (elt.match(/^ - [\s\S]*?$/)) {
console.log('elt', elt);
console.log('labelList', labelList);

var _elt$match3 = elt.match(/^ - ([\s\S]*?)$/);

var _elt$match32 = _slicedToArray(_elt$match3, 2);
Expand Down Expand Up @@ -542,37 +536,19 @@ var Template = (function () {

var GH_SECRET = 'M2NmYjI1YmNlOWE4MGFjN2E2NzIxZTg5YzkwMGVhZjM5NzEwN2Y2MA==';
var GH_ID = 'NGEzOWM4YzE4NjA3NDkxNWU1NDY=';

var CREWS = { crews: [{ title: 'Bienvenue sur multiBàO',
label: 'Accueil Multibao',
owner: 'multibao'
}, {
title: 'Réseau Transition BE',
label: 'Réseau Transition BE',
owner: 'reseautransitionwb'
}, {
title: 'Réseau Coop-tic',
label: 'Coop-TIC',
owner: 'supagroflorac'
}, {
title: 'Traducteurs agiles',
label: 'Traducteurs agiles',
owner: 'les-traducteurs-agiles'
}, {
title: 'Onpassealacte',
label: 'Onpassealacte',
owner: 'onpassealacte'
}] };
'use strict';

window.addEventListener('hashchange', function () {
return window.location.reload(true);
var ghUrl = window.location.toString().split('#')[1];
router.go(ghUrl);
});

window.addEventListener('load', function () {
var ghUrl = window.location.toString().split('#')[1];
router.go(ghUrl);
if (router.isNoRoute()) {
window.location = './404.html';
window.location.reload(true);
}
});
var template = new Template();
Expand All @@ -591,7 +567,7 @@ var layout = new Layout();

{
layout.create('home');
layout.home.html('\n <header class="clearfix">\n <h1>multi<span>BàO</span></h1>\n </header>\n <main>\n <section class="home-intro">\n <h2>Partager en équipe et au monde <span>ses apprentissages sur le faire ensemble</span></h2>\n <a href="#multibao/contributions/blob/master/pages/commencer_ici.md">Commencer ici</a>\n <a href="#multibao/documentation/blob/master/README.md">Guide d\'utilisation</a>\n </section>\n <section id="gh-crew-list" data-template="crews">\n </section>\n </main>');
layout.home.html('\n <header class="clearfix">\n <h1>multi<span>BàO</span></h1>\n </header>\n <main>\n <section class="home-intro">\n <h2>Partager en équipe et au monde <span>ses apprentissages sur le faire ensemble</span></h2>\n <a href="#multibao/contributions/blob/master/pages/commencer_ici.md">Commencer ici</a>\n <a href="#multibao/documentation/blob/master/README.md">Guide d\'utilisation</a>\n </section>\n <section id="gh-crew-list">\n <ul data-template="crews">\n </ul>\n </section>\n </main>');
}
/**
* Layout for manage and display Github repositories.
Expand Down Expand Up @@ -737,30 +713,45 @@ router.route(':owner', function () {
*/
'use strict';

var crewsWithSelectedClass = function crewsWithSelectedClass(owner, crews) {
return crews.map(function (elt) {
if (elt.owner === owner) {
elt.classAttr = 'selected';
}
return elt;
});
};
template.create('crews');
template.crews.data = function () {
var ownerRoute = router.params.owner;
var _crews = { crews: crewsWithSelectedClass(ownerRoute, CREWS.crews) };
var crews = _crews.crews;

template.crews.html('<ul>' + crews.map(function (_ref) {
var title = _ref.title;
var repo = _ref.repo;
var label = _ref.label;
var link = _ref.link;
var owner = _ref.owner;
var classAttr = _ref.classAttr;
return '<li><a title="' + title + '" class="' + classAttr + '" href="#' + owner + '"' + (' data-owner="' + owner + '"><h3>' + label + '</h3><p>' + title + '</p></a></li>');
}).join('\n') + '</ul>');
};
{
(function () {
var htmlWithMetas = function htmlWithMetas(_ref) {
var title = _ref.title;
var label = _ref.label;
var owner = _ref.owner;
var classAttr = _ref.classAttr;
return '<li><a title="' + title + '" href="#' + owner + '" data-owner="' + owner + '">\n <h3>' + label + '</h3><p>' + title + '</p></a>\n </li>';
};

template.create('crews');
template.crews.data = function () {
var ghApi = new GithubUrl({ owner: 'multibao', repo: 'organisations' });
var html = [];
ghApi.getJsonFolders().then(function (jsonResponse) {
jsonResponse.map(function (elt) {
if (elt.name === 'README.md') {
return;
}
var readmeUrl = { owner: 'multibao', repo: 'organisations', branch: 'master', path: elt.name };
var ghApiBlob = new GithubUrl(readmeUrl);
ghApiBlob.getMdBlob().then(function (mdResponse) {
var contribution = new Markdown(mdResponse);
if (contribution.isMetas()) {
var metas = {
label: contribution.metas.label,
title: contribution.metas.title,
owner: contribution.metas.owner
};
html.push(htmlWithMetas(metas));
}
template.crews.html(html.join('\n'));
template.crews.renderAsync(template.crews._htmlTpl);
});
});
});
};
})();
}
'use strict';

{
Expand Down Expand Up @@ -920,7 +911,6 @@ template.crews.data = function () {
folders: contribution.metas.folders,
files: contribution.metas.files
};
console.log('metas', contribution.metas);
html.push(htmlWithMetas(metas));
} else {
var noMetas = {
Expand Down
6 changes: 1 addition & 5 deletions dist/dk.min.js

Large diffs are not rendered by default.

24 changes: 0 additions & 24 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@
const GH_SECRET = 'M2NmYjI1YmNlOWE4MGFjN2E2NzIxZTg5YzkwMGVhZjM5NzEwN2Y2MA=='
const GH_ID = 'NGEzOWM4YzE4NjA3NDkxNWU1NDY='

const CREWS = {crews:
[
{ title: 'Bienvenue sur multiBàO',
label: 'Accueil Multibao',
owner: 'multibao'
}, {
title: 'Réseau Transition BE',
label: 'Réseau Transition BE',
owner: 'reseautransitionwb'
}, {
title: 'Réseau Coop-tic',
label: 'Coop-TIC',
owner: 'supagroflorac'
}, {
title: 'Traducteurs agiles',
label: 'Traducteurs agiles',
owner: 'les-traducteurs-agiles'
}, {
title: 'Onpassealacte',
label: 'Onpassealacte',
owner: 'onpassealacte'
}
]}
7 changes: 6 additions & 1 deletion src/init.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
window.addEventListener('hashchange', () => window.location.reload(true))
window.addEventListener('hashchange', () => {
const ghUrl = window.location.toString().split('#')[1]
router.go(ghUrl)
})

window.addEventListener('load', () => {
const ghUrl = window.location.toString().split('#')[1]
router.go(ghUrl)
if (router.isNoRoute()) {
window.location = './404.html'
window.location.reload(true)
}
})
const template = new Template()
Expand Down
4 changes: 3 additions & 1 deletion src/layout-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<a href="#multibao/contributions/blob/master/pages/commencer_ici.md">Commencer ici</a>
<a href="#multibao/documentation/blob/master/README.md">Guide d'utilisation</a>
</section>
<section id="gh-crew-list" data-template="crews">
<section id="gh-crew-list">
<ul data-template="crews">
</ul>
</section>
</main>`)
}
4 changes: 0 additions & 4 deletions src/lib/dk-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ class Markdown {
this.content.match(/---([\s\S]*?)---/)[1].split('\n')
.map(elt => {
if (!! elt.match(/^\w+:$/)) {
console.log('elt ul', elt)
console.log('labelList ul', labelList)
const [, label] = elt.match(/^(\w+):$/)
this.metas[label] = []
labelList = label
}
if (elt.match(/^ - [\s\S]*?$/)) {
console.log('elt', elt)
console.log('labelList', labelList)
const [, content] = elt.match(/^ - ([\s\S]*?)$/)
this.metas[labelList].push(content)
}
Expand Down
54 changes: 35 additions & 19 deletions src/tpl-crews.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,39 @@
* @param {String} An HTML string representing a github Url contribution.
* @result {Array} A array with each crew Object.
*/
const crewsWithSelectedClass = (owner, crews) => {
return crews.map(elt => {
if (elt.owner === owner) {
elt.classAttr = 'selected'
}
return elt
})
}
template.create('crews')
template.crews.data = () => {
const ownerRoute = router.params.owner
const {crews} = {crews: crewsWithSelectedClass(ownerRoute, CREWS.crews)}
template.crews.html(
`<ul>` +
crews.map(({title, repo, label, link, owner, classAttr}) =>
`<li><a title="${title}" class="${classAttr}" href="#${owner}"` +
` data-owner="${owner}"><h3>${label}</h3><p>${title}</p></a></li>`
).join('\n') +
`</ul>`)
{
const htmlWithMetas = ({title, label, owner, classAttr}) =>
`<li><a title="${title}" href="#${owner}" data-owner="${owner}">
<h3>${label}</h3><p>${title}</p></a>
</li>`

template.create('crews')
template.crews.data = () => {
const ghApi = new GithubUrl({owner: 'multibao', repo: 'organisations' })
const html = []
ghApi.getJsonFolders()
.then(jsonResponse => {
jsonResponse.map((elt) => {
if (elt.name === 'README.md') {
return
}
const readmeUrl = {owner: 'multibao', repo: 'organisations', branch: 'master', path: elt.name}
const ghApiBlob = new GithubUrl(readmeUrl)
ghApiBlob.getMdBlob()
.then(mdResponse => {
const contribution = new Markdown(mdResponse)
if (contribution.isMetas()) {
const metas = {
label: contribution.metas.label,
title: contribution.metas.title,
owner: contribution.metas.owner
}
html.push(htmlWithMetas(metas))
}
template.crews.html(html.join('\n'))
template.crews.renderAsync(template.crews._htmlTpl)
})
})
})
}
}
1 change: 0 additions & 1 deletion src/tpl-repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
folders: contribution.metas.folders,
files: contribution.metas.files
}
console.log('metas', contribution.metas)
html.push(htmlWithMetas(metas))
} else {
const noMetas = {
Expand Down
2 changes: 0 additions & 2 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
<script src="test.dk-markdown.js"></script>
<script src="test.tpl-contribution.js"></script>
<script src="../src/tpl-contribution.js"></script>
<script src="../src/tpl-crews.js"></script>
<script src="test.tpl-crews.js"></script>
<script src="../src/tpl-search.js"></script>
<script src="test.tpl-search.js"></script>
<script src="../src/tpl-breadcrumb.js"></script>
Expand Down
16 changes: 0 additions & 16 deletions tests/test.tpl-crews.js

This file was deleted.

0 comments on commit 5cfe920

Please sign in to comment.