Starting implementation of Mardeep document importation.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-02-02 18:35:39 -05:00
parent 576a408fb5
commit f89851f993
6 changed files with 108 additions and 9 deletions

View File

@ -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.' ]
]

View File

@ -40,11 +40,18 @@ 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 ].
| 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 |

View File

@ -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: '</script>'; lf.
]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePharoSnippet >> markdeepCustomOpener [
^ '~~~ Smalltalk', String lf.
^ String streamContents: [:stream |
stream
nextPutAll: '<script type="preformatted">'; lf;
nextPutAll: '~~~ Smalltalk'; lf
]
]

View File

@ -2,7 +2,7 @@ Extension { #name : #LePictureSnippet }
{ #category : #'*Grafoscopio-Utils-Core' }
LePictureSnippet >> asMarkdeep [
| output |
| output extraData |
output := '' writeStream.
output
nextPutAll: self metadataDiv;
@ -24,3 +24,14 @@ LePictureSnippet >> centeredFigure [
</figure>
</center>'
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePictureSnippet >> contentFrom: markdeepDiv [
| caption width |
caption := markdeepDiv contentString.
width := (markdeepDiv // 'img' @ 'width') stringValue.
self
optionAt: 'caption' put: caption;
optionAt: 'width' put: width.
^ self urlString: (markdeepDiv // 'img' @ 'src') stringValue.
]

View File

@ -0,0 +1,12 @@
Extension { #name : #LeSnippet }
{ #category : #'*Grafoscopio-Utils-Core' }
LeSnippet class >> fromMetaMarkdeep: div [
| className metadata snippet |
className := (div xpath: '@st-class') stringValue.
metadata := STON fromString:(div xpath: '@st-data') stringValue.
snippet := className asClass new.
snippet injectMetadataFrom: metadata.
snippet contentFrom: div.
^ snippet.
]

View File

@ -0,0 +1,10 @@
Extension { #name : #LeTextSnippet }
{ #category : #'*Grafoscopio-Utils-Core' }
LeTextSnippet >> contentFrom: markdeepDiv [
| sanitized |
sanitized := markdeepDiv contentString.
sanitized := sanitized allButFirst.
sanitized := sanitized allButLast.
self string: sanitized.
]