From 0ff9bf1adda51d942c256556fe9722d58e932619 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Fri, 4 Feb 2022 10:44:19 -0500 Subject: [PATCH] Fixing LePicture importing from Markdeep. --- .../Grafoscopio-Utils/LePage.extension.st | 10 ++++- .../LePictureSnippet.extension.st | 34 +++++++++-------- .../LeTextSnippet.extension.st | 17 --------- .../LeTextualSnippet.extension.st | 16 ++++++++ .../Grafoscopio-Utils/MarkdeepTest.class.st | 38 +++++++++++++++++++ 5 files changed, 81 insertions(+), 34 deletions(-) create mode 100644 repository/Grafoscopio-Utils/MarkdeepTest.class.st diff --git a/repository/Grafoscopio-Utils/LePage.extension.st b/repository/Grafoscopio-Utils/LePage.extension.st index f97b517..e9d4792 100644 --- a/repository/Grafoscopio-Utils/LePage.extension.st +++ b/repository/Grafoscopio-Utils/LePage.extension.st @@ -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' ] +] diff --git a/repository/Grafoscopio-Utils/LePictureSnippet.extension.st b/repository/Grafoscopio-Utils/LePictureSnippet.extension.st index 1ac6079..c3f1823 100644 --- a/repository/Grafoscopio-Utils/LePictureSnippet.extension.st +++ b/repository/Grafoscopio-Utils/LePictureSnippet.extension.st @@ -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 ] diff --git a/repository/Grafoscopio-Utils/LeTextSnippet.extension.st b/repository/Grafoscopio-Utils/LeTextSnippet.extension.st index 1626de2..538fe3f 100644 --- a/repository/Grafoscopio-Utils/LeTextSnippet.extension.st +++ b/repository/Grafoscopio-Utils/LeTextSnippet.extension.st @@ -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 -] diff --git a/repository/Grafoscopio-Utils/LeTextualSnippet.extension.st b/repository/Grafoscopio-Utils/LeTextualSnippet.extension.st index 13c5e0f..4ca908d 100644 --- a/repository/Grafoscopio-Utils/LeTextualSnippet.extension.st +++ b/repository/Grafoscopio-Utils/LeTextualSnippet.extension.st @@ -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 +] diff --git a/repository/Grafoscopio-Utils/MarkdeepTest.class.st b/repository/Grafoscopio-Utils/MarkdeepTest.class.st new file mode 100644 index 0000000..21a731f --- /dev/null +++ b/repository/Grafoscopio-Utils/MarkdeepTest.class.st @@ -0,0 +1,38 @@ +Class { + #name : #MarkdeepTest, + #superclass : #TestCase, + #category : #'Grafoscopio-Utils-Tests' +} + +{ #category : #tests } +MarkdeepTest >> markdeepTestingPictureSnippet [ + ^ (XMLHTMLParser on: '
+
+
+ +
*Network view of the Malleable Systems TiddlyWiki* +
+
+
+
') 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) + +]