Fixing LePicture importing from Markdeep.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-02-04 10:44:19 -05:00
parent 64b12c4aad
commit 0ff9bf1add
5 changed files with 81 additions and 34 deletions

View File

@ -101,11 +101,12 @@ LePage >> options [
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> populateChildrenFrom: docTreeDivs [
docTreeDivs doWithIndex: [:div :i | | snippet |
docTreeDivs doWithIndex: [:div :i | | snippet parent |
snippet := LeSnippet fromMetaMarkdeep:div.
self children
addSnippet: snippet beforeIndex: i.
"self detectSnippetWithUid: "
parent := self detectSnippetWithUid: (snippet metadata at: 'parent').
snippet parent: parent.
]
]
@ -116,3 +117,8 @@ LePage >> preorderTraversal [
self withDeepCollect: [:each | each allChildrenBreadthFirstDo: [:child | output add: child ] ].
^ output.
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> removeSnippetsMetadata [
self preorderTraversal do: [ :snippet | snippet options removeKey: 'metadata' ]
]

View File

@ -33,23 +33,27 @@ LePictureSnippet >> contentFrom: markdeepDiv [
self
optionAt: 'caption' put: caption;
optionAt: 'width' put: width.
^ self urlString: (markdeepDiv // 'img' @ 'src') stringValue.
self urlString: (markdeepDiv // 'img' @ 'src') stringValue.
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePictureSnippet >> metadata [
^ self optionAt: 'metadata' ifAbsentPut: [ self metadataInit ]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePictureSnippet >> metadataInit [
^ OrderedDictionary new
at: 'id' put: self uidString;
at: 'parent' put: self parent uidString;
at: 'url' put: self contentAsString;
at: 'created' put: self createTime asString;
at: 'modified' put: self latestEditTime asString;
at: 'creator' put: self createEmail asString;
at: 'modifier' put: self editEmail asString;
yourself
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePictureSnippet >> metatada [
self optionAt: 'metadata' ifAbsent: [ self metadataInit ]
| surrogate |
self parent
ifNil: [ surrogate := nil]
ifNotNil: [ surrogate := self parent uidString ].
^ OrderedDictionary new
at: 'id' put: self uidString;
at: 'parent' put: surrogate;
at: 'url' put: self contentAsString;
at: 'created' put: self createTime asString;
at: 'modified' put: self latestEditTime asString;
at: 'creator' put: self createEmail asString;
at: 'modifier' put: self editEmail asString;
yourself
]

View File

@ -8,20 +8,3 @@ LeTextSnippet >> contentFrom: markdeepDiv [
sanitized := sanitized allButLast.
self string: sanitized.
]
{ #category : #'*Grafoscopio-Utils-Core' }
LeTextSnippet >> metadata [
^ self optionAt: 'metadata' ifAbsentPut: [ self metadataInit ]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LeTextSnippet >> metadataInit [
^ OrderedDictionary new
at: 'id' put: self uidString;
at: 'parent' put: self parent uid asString;
at: 'created' put: self createTime asString;
at: 'modified' put: self latestEditTime asString;
at: 'creator' put: self createEmail asString;
at: 'modifier' put: self editEmail asString;
yourself
]

View File

@ -30,3 +30,19 @@ LeTextualSnippet >> markdeepCustomCloser [
LeTextualSnippet >> markdeepCustomOpener [
^ ''
]
{ #category : #'*Grafoscopio-Utils-Core' }
LeTextualSnippet >> metadataInit [
| surrogate |
self parent
ifNil: [ surrogate := nil]
ifNotNil: [ surrogate := self parent uidString ].
^ OrderedDictionary new
at: 'id' put: self uidString;
at: 'parent' put: surrogate;
at: 'created' put: self createTime asString;
at: 'modified' put: self latestEditTime asString;
at: 'creator' put: self createEmail asString;
at: 'modifier' put: self editEmail asString;
yourself
]

View File

@ -0,0 +1,38 @@
Class {
#name : #MarkdeepTest,
#superclass : #TestCase,
#category : #'Grafoscopio-Utils-Tests'
}
{ #category : #tests }
MarkdeepTest >> markdeepTestingPictureSnippet [
^ (XMLHTMLParser on: '<div st-class="LePictureSnippet" st-data="OrderedDictionary{''id'':''77774yaTDQC8sESSDssMzQ=='',''parent'':''RBSKVeCRDQCTTfVoCYJWrg=='',''url'':''https://i.imgur.com/OD9P0vG.png'',''created'':''29 January 2022 11:32:19.996608 pm'',''modified'':''29 January 2022 11:32:23.781937 pm'',''creator'':''&lt;unknown>'',''modifier'':''&lt;unknown>''}">
<center>
<figure>
<img src="https://i.imgur.com/OD9P0vG.png" width="60%"/>
<figcaption>*Network view of the Malleable Systems TiddlyWiki*
</figcaption>
</figure>
</center>
</div>') parseDocument
]
{ #category : #tests }
MarkdeepTest >> testLePictureImport [
| metadata testSnippet |
metadata := STON fromString: (self markdeepTestingPictureSnippet xpath: 'st-class') stringValue.
testSnippet := LePictureSnippet new injectMetadataFrom: metadata.
self assert: (testSnippet metadata at: 'parent') isNotNil.
]
{ #category : #tests }
MarkdeepTest >> testMetadaIncludesParentId [
| aPage aSnippetOne aSnippetTwo |
aPage := LeUIExamples new database pageBuilder title: 'Test Page'; add.
aSnippetOne := aPage snippetBuilder string: 'Parent snippet'; add.
aSnippetTwo := aPage snippetBuilder string: 'Child Snippet'; add.
aSnippetTwo parent: aSnippetOne.
self assert: (aSnippetTwo metadata values includes: aSnippetOne uidString)
]