Skip to content

Instantly share code, notes, and snippets.

@el0911
Created September 24, 2019 18:12
Show Gist options
  • Save el0911/89d116e5b7fc8725e34b82ea9ed6880e to your computer and use it in GitHub Desktop.
Save el0911/89d116e5b7fc8725e34b82ea9ed6880e to your computer and use it in GitHub Desktop.
const ionicTemplates = require('./typeTemplate');
const iterate =(pageConstents) => {
let imports = [];
let templates = [];
for (let j = 0; j < pageConstents.length; j++) {
const pageContent = pageConstents[j];
const type = pageContent.type;
const { import_, template_ } = ionicTemplates[type];
imports = imports.concat(import_.split(','));
templates.push({template_,parent:pageContent.dropzoneID});
if (pageContent.initialElements && pageContent.initialElements.length>0) {
///means this guy has childeren elements
let page = iterate(pageContent.initialElements);
imports = imports.concat(page.imports); //easy
for (let i = 0; i < page.templates.length; i++) {
const element = page.templates[i];
const content = element
///extract the position from the parent variable
const [ _,x,y] = content.parent.split('-')
///convert this to the location am looking to replace int the template
const id = `${ionicTemplates.PICKER}-${x}-${y}`
templates[j].template_ = templates[j].template_.replace(id,content.template_)
}
}
}
// console.log(templates);
return {
imports,
templates
};
}
module.exports = {
iterateThroughTree: iterate
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment