From f89851f993f8fcdaa8154a068e76eaae6d5582ae Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Wed, 2 Feb 2022 18:35:39 -0500 Subject: [PATCH] Starting implementation of Mardeep document importation. --- .../Grafoscopio-Utils/LeDatabase.extension.st | 31 +++++++++++++++++++ .../Grafoscopio-Utils/LePage.extension.st | 27 ++++++++++++---- .../LePharoSnippet.extension.st | 24 ++++++++++++-- .../LePictureSnippet.extension.st | 13 +++++++- .../Grafoscopio-Utils/LeSnippet.extension.st | 12 +++++++ .../LeTextSnippet.extension.st | 10 ++++++ 6 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 repository/Grafoscopio-Utils/LeSnippet.extension.st create mode 100644 repository/Grafoscopio-Utils/LeTextSnippet.extension.st diff --git a/repository/Grafoscopio-Utils/LeDatabase.extension.st b/repository/Grafoscopio-Utils/LeDatabase.extension.st index a4be762..10c6ffd 100644 --- a/repository/Grafoscopio-Utils/LeDatabase.extension.st +++ b/repository/Grafoscopio-Utils/LeDatabase.extension.st @@ -1,5 +1,13 @@ Extension { #name : #LeDatabase } +{ #category : #'*Grafoscopio-Utils-Core' } +LeDatabase >> addPageFromMarkdeepUrl: aString [ + + | page | + page := self detectLocalPageForRemote: aString. + page ifNotNil: [ :arg | ^ self importErrorMessage: page ] +] + { #category : #'*Grafoscopio-Utils-Core' } LeDatabase >> detectLocalPageForRemote: markdeepDocUrl [ | markdeepHelper id remoteMetadata docTree | @@ -9,3 +17,26 @@ LeDatabase >> detectLocalPageForRemote: markdeepDocUrl [ id := remoteMetadata at: 'id' ifAbsent: [ ^ false ]. ^ self pageWithID: id ifAbsent: [ nil ]. ] + +{ #category : #'*Grafoscopio-Utils-Core' } +LeDatabase >> importErrorMessage: page [ + + ^ String streamContents: [ :stream | + stream + nextPutAll: 'IMPORTATION ERROR: a page with'; + nextPut: Character lf; + nextPut: Character lf; + nextPutAll: ' id: ' , page uidString; + nextPut: Character lf; + nextPutAll: ' title: ' , page contentAsString; + nextPut: Character lf; + nextPut: Character lf; + nextPutAll: 'already exists in this database.'; + nextPut: Character lf; + nextPut: Character lf; + nextPutAll: + 'Please do one of those before retrying this procedure: + + 1) Move the existing page files (.lepiter and .bak) to another (sub)folder. + 2) Import the page url to another database.' ] +] diff --git a/repository/Grafoscopio-Utils/LePage.extension.st b/repository/Grafoscopio-Utils/LePage.extension.st index baf3319..2e5b3ce 100644 --- a/repository/Grafoscopio-Utils/LePage.extension.st +++ b/repository/Grafoscopio-Utils/LePage.extension.st @@ -39,12 +39,19 @@ LePage >> fileName [ ] { #category : #'*Grafoscopio-Utils-Core' } -LePage >> fromMarkdeepUrl: aString [ - - | markdeepHelper id remoteMetadata | - markdeepHelper := Markdeep new. - remoteMetadata := markdeepHelper metadataFromXML: (self xmlFromUrl: aString). - id := remoteMetadata at: 'id' ifAbsent: [ ^ false ]. +LePage >> fromMarkdeepUrl: aString [ + | docTree pageMetadata | + docTree := GrafoscopioUtils xmlFromUrl: aString. + pageMetadata := Markdeep new metadataFromXML: docTree. + self + basicUid: (pageMetadata at: 'id'); + title: (pageMetadata at: 'title'); + createTime: (pageMetadata at: 'created'); + editTime: (pageMetadata at: 'modified'); + createEmail: (pageMetadata at: 'creator'); + editEmail: (pageMetadata at: 'modifier'); + optionAt: 'metadata' put: pageMetadata. + self populateChildrenFrom: (docTree xpath: '//div') ] @@ -85,6 +92,14 @@ LePage >> options [ ^ options ] +{ #category : #'*Grafoscopio-Utils-Core' } +LePage >> populateChildrenFrom: docTreeDivs [ + docTreeDivs doWithIndex: [:div :i | + self children + addSnippet: (LeSnippet fromMetaMarkdeep:div) beforeIndex: i + ] +] + { #category : #'*Grafoscopio-Utils-Core' } LePage >> preorderTraversal [ | output | diff --git a/repository/Grafoscopio-Utils/LePharoSnippet.extension.st b/repository/Grafoscopio-Utils/LePharoSnippet.extension.st index 8a172cf..0870b64 100644 --- a/repository/Grafoscopio-Utils/LePharoSnippet.extension.st +++ b/repository/Grafoscopio-Utils/LePharoSnippet.extension.st @@ -1,11 +1,31 @@ Extension { #name : #LePharoSnippet } +{ #category : #'*Grafoscopio-Utils-Core' } +LePharoSnippet >> contentFrom: markdeepDiv [ + | sanitized divContents | + divContents := markdeepDiv contentString. + sanitized := String streamContents: [:stream | + (divContents lines copyFrom: 4 to: divContents lines size - 2) do: [:line | + stream nextPutAll: line; lf + ] + ]. + self code: sanitized contents allButLast. +] + { #category : #'*Grafoscopio-Utils-Core' } LePharoSnippet >> markdeepCustomCloser [ - ^ '~~~', String lf. + ^ String streamContents: [:stream | + stream + nextPutAll: '~~~'; lf; + nextPutAll: ''; lf. + ] ] { #category : #'*Grafoscopio-Utils-Core' } LePharoSnippet >> markdeepCustomOpener [ - ^ '~~~ Smalltalk', String lf. + ^ String streamContents: [:stream | + stream + nextPutAll: '