From a0dc4b656e932eaf55921a346ae84e760cbc95f4 Mon Sep 17 00:00:00 2001
From: "martin.mille.etu@univ-lille.fr" <martin.mille.etu@univ-lille.fr>
Date: Wed, 10 Feb 2021 16:13:04 +0100
Subject: [PATCH]  tp2

---
 src/components/Component.js | 22 +++++++++++++++++++---
 src/main.js                 | 17 +++++++++++------
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/src/components/Component.js b/src/components/Component.js
index 746b0a3..0c22b23 100644
--- a/src/components/Component.js
+++ b/src/components/Component.js
@@ -9,18 +9,34 @@ class Component {
 	}
 
 	render() {
+		let res;
 		if (this.attribute != null) {
-			return `<${this.tagName} ${this.renderAttribute()} /> `;
+			res = `< ${this.renderAttribute()} />  `;
 		}
 		if (this.children != null || this.children != undefined) {
-			return `<${this.tagName}> ${this.children} </${this.tagName}>`;
+			res += `<${this.tagName}> ${this.renderChildren()}  </${this.tagName}>`;
 		} else {
 			return '<' + this.tagName + '/>';
 		}
+		return res;
 	}
 
 	renderAttribute() {
-		return `${this.attribute.name}="${this.attribute.value}"`;
+		return `img src="${this.attribute.value}"`;
+	}
+
+	renderChildren() {
+		let path = '';
+		if (this.children instanceof Component) {
+			return this.children.render();
+		} else if (this.children instanceof Array) {
+			for (let i = 0; i < this.children.length; i++) {
+				path += this.children[i];
+			}
+		} else {
+			path = `${this.children} `;
+		}
+		return path;
 	}
 }
 export default Component;
diff --git a/src/main.js b/src/main.js
index aa9633d..53069d3 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,9 +1,14 @@
 import Component from './components/Component.js';
 import Img from './components/Img.js';
-const title = new Component('h1', null, 'La carte');
-document.querySelector('.pageTitle').innerHTML = title.render();
 
-const img = new Img(
-	'https://images.unsplash.com/photo-1532246420286-127bcd803104?fit=crop&w=500&h=300'
-);
-document.querySelector('.pageContent').innerHTML = img.render();
+//const title = new Component('h1', null, ['La', ' gucci ', 'carte']);
+//document.querySelector('.pageTitle').innerHTML = title.render();
+
+const c = new Component('article', { name: 'class', value: 'pizzaThumbnail' }, [
+	new Img(
+		'https://images.unsplash.com/photo-1532246420286-127bcd803104?fit=crop&w=500&h=300'
+	),
+	'Regina',
+]);
+console.log(c.render());
+document.querySelector('.pageContent').innerHTML = c.render();
-- 
GitLab