Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TP2 - POO et Modules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Delattre
TP2 - POO et Modules
Commits
f6a4468c
Commit
f6a4468c
authored
3 years ago
by
Thomas Delattre
Browse files
Options
Downloads
Patches
Plain Diff
debut part D
parent
1c93a310
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/Component.js
+17
-2
17 additions, 2 deletions
src/components/Component.js
src/main.js
+5
-1
5 additions, 1 deletion
src/main.js
with
22 additions
and
3 deletions
src/components/Component.js
+
17
−
2
View file @
f6a4468c
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
}
>`
;
}
}
}
This diff is collapsed.
Click to expand it.
src/main.js
+
5
−
1
View file @
f6a4468c
...
...
@@ -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
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment