Skip to content

Commit

Permalink
Merge pull request #24 from OpenSmock/better_materialization
Browse files Browse the repository at this point in the history
Better materialization
  • Loading branch information
Nyan11 authored Aug 1, 2024
2 parents e8d2b54 + 2454f0b commit 0effcdc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/Bloc-Serialization-Stash/BlSvgPath.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Extension { #name : #BlSvgPath }

{ #category : #'*Bloc-Serialization-Stash' }
BlSvgPath >> stashAccessors [

<stashAccessors>
| accessors |
accessors := OrderedCollection new.
fillRule = EvenOdd ifTrue: [
accessors add: (#useEvenOddFillRule -> self) onlySetOnStash ].
accessors add:
([ :e | 'pathString: (<1p>)' expandMacrosWith: pathString ] -> self)
onlySetOnStash.
^ accessors
]
6 changes: 6 additions & 0 deletions src/Bloc-Serialization/BlElement.extension.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Extension { #name : #BlElement }

{ #category : #'*Bloc-Serialization' }
BlElement >> materializeAsBlElement [

^ self
]

{ #category : #'*Bloc-Serialization' }
BlElement >> serialize [

Expand Down
35 changes: 27 additions & 8 deletions src/Bloc-Serialization/BlSerializer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,35 @@ Serailizer class for Bloc
Class {
#name : #BlSerializer,
#superclass : #Object,
#traits : 'TBlSerializer',
#classTraits : 'TBlSerializer classTrait',
#classInstVars : [
'serializer'
],
#category : #'Bloc-Serialization-Core'
}

{ #category : #'as yet unclassified' }
BlSerializer class >> allSerializer [

^ TBlSerializer users
]

{ #category : #serialization }
BlSerializer class >> materialize: aString [
"Materialize a String into a BlElement and return it. Default materializer is STON."
BlSerializer class >> materialize: anObject [

| serializerClassName serializerClass |
aString ifEmpty: [ ^ BlocMaterializationError new signal ].
aString first = $" ifFalse: [
^ BlStonSerializer materialize: aString ].
serializerClassName := aString lines first allButFirst allButLast.
(anObject isKindOf: BlElement) ifTrue: [ ^ anObject ].
anObject ifEmpty: [ ^ BlocMaterializationError new signal ].

anObject first = $" ifFalse: [
^ self unknownMaterializerFor: anObject ].
serializerClassName := anObject lines first allButFirst allButLast.
serializerClass := Smalltalk environment classNamed:
serializerClassName.
^ serializerClass materialize: ('' join: aString lines allButFirst)
serializerClass ifNil: [ ^ self unknownMaterializerFor: anObject ].
^ serializerClass materialize: ('' join: anObject lines allButFirst)
]
{ #category : #initialization }
Expand Down Expand Up @@ -57,6 +66,16 @@ BlSerializer class >> serializer [
^ serializer
]
{ #category : #serialization }
BlSerializer class >> unknownMaterializerFor: aString [
self allSerializer do: [ :each |
[ ^ each materialize: aString ]
on: BlocMaterializationError
do: [ ] ].
BlocMaterializationError signal: 'Could not find a Serializer.'
]
{ #category : #'see class side' }
BlSerializer >> seeClassSide [
]
2 changes: 1 addition & 1 deletion src/Bloc-Serialization/BlocMaterializationError.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Class {
#name : #BlocMaterializationError,
#superclass : #BlocSerializerError,
#category : #'Bloc-Serialization-Exception'
#category : #'Bloc-Serialization-Core'
}
2 changes: 1 addition & 1 deletion src/Bloc-Serialization/BlocSerializationError.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Class {
#name : #BlocSerializationError,
#superclass : #BlocSerializerError,
#category : #'Bloc-Serialization-Exception'
#category : #'Bloc-Serialization-Core'
}
2 changes: 1 addition & 1 deletion src/Bloc-Serialization/BlocSerializerError.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Class {
#name : #BlocSerializerError,
#superclass : #Error,
#category : #'Bloc-Serialization-Exception'
#category : #'Bloc-Serialization-Core'
}

0 comments on commit 0effcdc

Please sign in to comment.