In the beginning there was darkness.

This commit is contained in:
Daniel Ziltener 2023-11-11 20:01:28 +01:00
commit 579c93f12d
7 changed files with 216 additions and 0 deletions

3
.project Normal file
View File

@ -0,0 +1,3 @@
{
'srcDirectory' : ''
}

3
.properties Normal file
View File

@ -0,0 +1,3 @@
{
#format : #tonel
}

View File

@ -0,0 +1,12 @@
Class {
#name : #BaselineOfHitch,
#superclass : #BaselineOf,
#category : #BaselineOfHitch
}
{ #category : #baselines }
BaselineOfHitch >> baseline: spec [
<baseline>
spec.
]

View File

@ -0,0 +1 @@
Package { #name : #BaselineOfHitch }

View File

@ -0,0 +1,21 @@
Class {
#name : #HTMLAttribute,
#superclass : #Object,
#instVars : [
'name',
'value'
],
#category : #Hitch
}
{ #category : #'instance creation' }
HTMLAttribute class >> name: attrName value: attrValue [
^ self new
name: attrName
value: attrValue.
]
{ #category : #rendering }
HTMLAttribute >> renderValue [
^ value
]

175
Hitch/HTMLElement.class.st Normal file
View File

@ -0,0 +1,175 @@
"
I am the base concept of an HTML element.
For the Responsibility part: Three sentences about my main responsibilities - what I do, what I know.
For the Collaborators Part: State my main collaborators and one line about how I interact with them.
Public API and Key Messages
- message one
- message two
- (for bonus points) how to create instances.
One simple example is simply gorgeous.
Internal Representation and Key Implementation Points.
Instance Variables
name: <Object>
Implementation Points
"
Class {
#name : #HTMLElement,
#superclass : #Object,
#instVars : [
'name',
'attributes',
'children'
],
#category : #Hitch
}
{ #category : #'as yet unclassified' }
HTMLElement class >> getResponsibleElementClassFor: aTag [
^ self subclasses detect: [ :subclass | (subclass handlesTag: aTag) ] ifNone: [ self ]
]
{ #category : #'as yet unclassified' }
HTMLElement class >> handlesTag: aTag [
^ false
]
{ #category : #testing }
HTMLElement class >> isAbstract [
^ self == HTMLElement
]
{ #category : #'instance creation' }
HTMLElement class >> newTag: aTag [
^ (self getResponsibleElementClassFor: aTag) new
name: aTag;
yourself
]
{ #category : #'instance creation' }
HTMLElement class >> newTag: aTag attrs: attributes [
^ (self getResponsibleElementClassFor: aTag)
new
name: aTag;
attributes: attributes;
yourself
]
{ #category : #'instance creation' }
HTMLElement class >> newTag: aTag attrs: attributes children: childElems [
^ (self getResponsibleElementClassFor: aTag) new
name: aTag;
attributes: attributes;
children: childElems;
yourself
]
{ #category : #'instance creation' }
HTMLElement class >> newTag: aTag children: childElems [
^ (self getResponsibleElementClassFor: aTag) new
name: aTag;
children: childElems;
yourself
]
{ #category : #adding }
HTMLElement >> add: aTag [
children add: (self class newTag: aTag)
]
{ #category : #adding }
HTMLElement >> add: aTag attrs: attrs [
children add: (self class newTag: aTag attrs: attrs)
]
{ #category : #adding }
HTMLElement >> add: aTag attrs: attrs children: childElems [
children add: (self class newTag: aTag attrs: attrs children: childElems)
]
{ #category : #adding }
HTMLElement >> add: aTag children: childElems [
children add: (self class newTag: aTag children: childElems)
]
{ #category : #accessing }
HTMLElement >> attributes [
^ attributes
]
{ #category : #accessing }
HTMLElement >> attributes: anObject [
attributes := anObject
]
{ #category : #accessing }
HTMLElement >> children [
^ children
]
{ #category : #accessing }
HTMLElement >> children: anObject [
children := anObject
]
{ #category : #initialization }
HTMLElement >> initialize [
attributes ifNil: [ attributes := Dictionary new ].
children ifNil: [ children := OrderedCollection new ]
]
{ #category : #accessing }
HTMLElement >> name [
^ name
]
{ #category : #accessing }
HTMLElement >> name: anObject [
name := anObject
]
{ #category : #rendering }
HTMLElement >> render [
^ '<' , name , ' ' , self renderAttributes , '>\n'
, (self renderChildren) , '\n</' , name , '>'
]
{ #category : #rendering }
HTMLElement >> renderAttributes [
^ ' ' join: (attributes do: [ :attribute | '=' join: #( attribute name attribute renderValue ) ]).
]
{ #category : #rendering }
HTMLElement >> renderChildren [
^ '\n\t' join: (children collect: [ :child |
child isString
ifTrue: [ child ]
ifFalse: [ child render ] ])
]

1
Hitch/package.st Normal file
View File

@ -0,0 +1 @@
Package { #name : #Hitch }