2016-02-25 12:31:21 -08:00
|
|
|
import AuthenticationPage from './AuthenticationPage';
|
|
|
|
|
2016-02-25 20:40:35 -08:00
|
|
|
function getSlug(path) {
|
2016-05-30 16:55:32 -07:00
|
|
|
const m = path.match(/([^\/]+?)(\.[^\/\.]+)?$/);
|
2016-02-25 20:40:35 -08:00
|
|
|
return m && m[1];
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:31:21 -08:00
|
|
|
export default class TestRepo {
|
|
|
|
constructor(config) {
|
|
|
|
this.config = config;
|
2016-02-25 20:40:35 -08:00
|
|
|
if (window.repoFiles == null) {
|
|
|
|
throw 'The TestRepo backend needs a "window.repoFiles" object.';
|
|
|
|
}
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
authComponent() {
|
|
|
|
return AuthenticationPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticate(state) {
|
|
|
|
return Promise.resolve({email: state.email});
|
|
|
|
}
|
2016-02-25 20:40:35 -08:00
|
|
|
|
|
|
|
entries(collection) {
|
|
|
|
const entries = [];
|
|
|
|
const folder = collection.get('folder');
|
|
|
|
if (folder) {
|
|
|
|
for (var path in window.repoFiles[folder]) {
|
|
|
|
entries.push({
|
|
|
|
path: folder + '/' + path,
|
|
|
|
slug: getSlug(path),
|
|
|
|
raw: window.repoFiles[folder][path].content
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve(entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
entry(collection, slug) {
|
2016-05-30 16:55:32 -07:00
|
|
|
return this.entries(collection).then((entries) => (
|
|
|
|
entries.filter((entry) => entry.slug === slug)[0]
|
|
|
|
));
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|