Fixed example instance container (#221)

* fixed example inance container

* added a space
This commit is contained in:
Yining Shi 2016-12-09 12:19:02 -05:00 committed by Cassie Tarakajian
parent 51336baee6
commit 412d330f74

View file

@ -120,12 +120,19 @@ function getSketchesInCategories(categories) {
const examples = JSON.parse(res); const examples = JSON.parse(res);
examples.forEach(example => { examples.forEach(example => {
let projectName; let projectName;
if (example.name.split('_')[1]) { if (example.name === '02_Instance_Container.js') {
projectName = category.name + ': '+ example.name.split('_').slice(1).join(' ').replace('.js', ''); for (let i = 1; i < 5; i++) {
const instanceProjectName = category.name + ': ' + 'Instance Container ' + i;
projectsInOneCategory.push({sketchUrl: example.download_url, projectName: instanceProjectName});
}
} else { } else {
projectName = category.name + ': '+ example.name.replace('.js', ''); if (example.name.split('_')[1]) {
projectName = category.name + ': '+ example.name.split('_').slice(1).join(' ').replace('.js', '');
} else {
projectName = category.name + ': '+ example.name.replace('.js', '');
}
projectsInOneCategory.push({sketchUrl: example.download_url, projectName: projectName});
} }
projectsInOneCategory.push({sketchUrl: example.download_url, projectName: projectName});
}); });
return projectsInOneCategory; return projectsInOneCategory;
}).catch(err => { }).catch(err => {
@ -145,7 +152,15 @@ function getSketchContent(projectsInAllCategories) {
}; };
return rp(options).then(res => { return rp(options).then(res => {
project.sketchContent = res; const noNumberprojectName = project.projectName.replace(/(\d+)/g, '');
if (noNumberprojectName === 'Instance Mode : Instance Container ') {
for (let i = 0; i < 4; i++) {
let splitedRes = res.split('*/')[1].split('</html>')[i] + '</html>\n';
project.sketchContent = splitedRes.replace('p5.js', 'https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.4/p5.min.js');
}
} else {
project.sketchContent = res;
}
return project; return project;
}).catch(err => { }).catch(err => {
throw err; throw err;
@ -171,45 +186,89 @@ function createProjectsInP5user(projectsInAllCategories) {
async.eachSeries(projectsInAllCategories, (projectsInOneCategory, categoryCallback) => { async.eachSeries(projectsInAllCategories, (projectsInOneCategory, categoryCallback) => {
async.eachSeries(projectsInOneCategory, (project, projectCallback) => { async.eachSeries(projectsInOneCategory, (project, projectCallback) => {
let newProject = new Project({ let newProject;
name: project.projectName, const noNumberprojectName = project.projectName.replace(/(\d+)/g, '');
user: user._id, if (noNumberprojectName === 'Instance Mode : Instance Container ') {
files: [ newProject = new Project({
{ name: project.projectName,
name: 'root', user: user._id,
id: r, files: [
_id: r, {
children: [a, b, c], name: 'root',
fileType: 'folder' id: r,
}, _id: r,
{ children: [a, b, c],
name: 'sketch.js', fileType: 'folder'
content: project.sketchContent, },
id: a, {
_id: a, name: 'sketch.js',
isSelectedFile: true, content: '// Instance Mode : Instance Container, please check its index.html file',
fileType: 'file', id: a,
children: [] _id: a,
}, isSelectedFile: true,
{ fileType: 'file',
name: 'index.html', children: []
content: defaultHTML, },
id: b, {
_id: b, name: 'index.html',
fileType: 'file', content: project.sketchContent,
children: [] id: b,
}, _id: b,
{ fileType: 'file',
name: 'style.css', children: []
content: defaultCSS, },
id: c, {
_id: c, name: 'style.css',
fileType: 'file', content: defaultCSS,
children: [] id: c,
} _id: c,
], fileType: 'file',
_id: shortid.generate() children: []
}); }
],
_id: shortid.generate()
});
} else {
newProject = new Project({
name: project.projectName,
user: user._id,
files: [
{
name: 'root',
id: r,
_id: r,
children: [a, b, c],
fileType: 'folder'
},
{
name: 'sketch.js',
content: project.sketchContent,
id: a,
_id: a,
isSelectedFile: true,
fileType: 'file',
children: []
},
{
name: 'index.html',
content: defaultHTML,
id: b,
_id: b,
fileType: 'file',
children: []
},
{
name: 'style.css',
content: defaultCSS,
id: c,
_id: c,
fileType: 'file',
children: []
}
],
_id: shortid.generate()
});
}
let assetsInProject = project.sketchContent.match(/assets\/[\w-]+\.[\w]*/g) || project.sketchContent.match(/assets\/[\w-]*/g) || []; let assetsInProject = project.sketchContent.match(/assets\/[\w-]+\.[\w]*/g) || project.sketchContent.match(/assets\/[\w-]*/g) || [];