Skip to content
Snippets Groups Projects
Commit f6a4468c authored by Thomas Delattre's avatar Thomas Delattre
Browse files

debut part D

parent 1c93a310
No related branches found
No related tags found
No related merge requests found
export default class Component {
tagName;
attribute
attribute;
children;
constructor(tagName, attribute, children) {
this.tagName = tagName;
this.attribute = attribute;
this.children = children;
}
render(){
if (this.children) {
return `<${this.tagName}> ${this.children} </${this.tagName}>`;
return this.renderChildren;
}
else {
return this.renderAttribute();
}
}
renderAttribute(){
return `<${this.tagName} ${this.attribute.name} = "${this.attribute.value}" />`;
}
renderChildren(){
let str = '';
if(this.children instanceof Component) {
this.children.forEach(element => {
str += element
});
return `<${this.tagName}> ${this.str} </${this.tagName}>`;
}
else {
return `<${this.tagName}> ${this.children} </${this.tagName}>`;
}
}
}
......@@ -2,9 +2,13 @@ import data from './Data.js';
import Component from './components/Component.js';
import Img from './components/Img.js';
console.log(data[0].image);
const title = new Component( 'h1', null, 'La carte' );
// const title = new Component( 'h1', null, 'La carte' );
// document.querySelector('.pageTitle').innerHTML = title.render();
const title = new Component( 'h1', null, ['La', ' ', 'carte'] );
document.querySelector('.pageTitle').innerHTML = title.render();
const img = new Img(data[0].image);
document.querySelector( '.pageContent' ).innerHTML = img.render();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment