Starting implementation of Mardeep document importation.
This commit is contained in:
parent
576a408fb5
commit
f89851f993
@ -1,5 +1,13 @@
|
|||||||
Extension { #name : #LeDatabase }
|
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' }
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
||||||
LeDatabase >> detectLocalPageForRemote: markdeepDocUrl [
|
LeDatabase >> detectLocalPageForRemote: markdeepDocUrl [
|
||||||
| markdeepHelper id remoteMetadata docTree |
|
| markdeepHelper id remoteMetadata docTree |
|
||||||
@ -9,3 +17,26 @@ LeDatabase >> detectLocalPageForRemote: markdeepDocUrl [
|
|||||||
id := remoteMetadata at: 'id' ifAbsent: [ ^ false ].
|
id := remoteMetadata at: 'id' ifAbsent: [ ^ false ].
|
||||||
^ self pageWithID: id ifAbsent: [ nil ].
|
^ 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.' ]
|
||||||
|
]
|
||||||
|
@ -40,11 +40,18 @@ LePage >> fileName [
|
|||||||
|
|
||||||
{ #category : #'*Grafoscopio-Utils-Core' }
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
||||||
LePage >> fromMarkdeepUrl: aString [
|
LePage >> fromMarkdeepUrl: aString [
|
||||||
|
| docTree pageMetadata |
|
||||||
| markdeepHelper id remoteMetadata |
|
docTree := GrafoscopioUtils xmlFromUrl: aString.
|
||||||
markdeepHelper := Markdeep new.
|
pageMetadata := Markdeep new metadataFromXML: docTree.
|
||||||
remoteMetadata := markdeepHelper metadataFromXML: (self xmlFromUrl: aString).
|
self
|
||||||
id := remoteMetadata at: 'id' ifAbsent: [ ^ false ].
|
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
|
^ options
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
||||||
|
LePage >> populateChildrenFrom: docTreeDivs [
|
||||||
|
docTreeDivs doWithIndex: [:div :i |
|
||||||
|
self children
|
||||||
|
addSnippet: (LeSnippet fromMetaMarkdeep:div) beforeIndex: i
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #'*Grafoscopio-Utils-Core' }
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
||||||
LePage >> preorderTraversal [
|
LePage >> preorderTraversal [
|
||||||
| output |
|
| output |
|
||||||
|
@ -1,11 +1,31 @@
|
|||||||
Extension { #name : #LePharoSnippet }
|
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' }
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
||||||
LePharoSnippet >> markdeepCustomCloser [
|
LePharoSnippet >> markdeepCustomCloser [
|
||||||
^ '~~~', String lf.
|
^ String streamContents: [:stream |
|
||||||
|
stream
|
||||||
|
nextPutAll: '~~~'; lf;
|
||||||
|
nextPutAll: '</script>'; lf.
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'*Grafoscopio-Utils-Core' }
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
||||||
LePharoSnippet >> markdeepCustomOpener [
|
LePharoSnippet >> markdeepCustomOpener [
|
||||||
^ '~~~ Smalltalk', String lf.
|
^ String streamContents: [:stream |
|
||||||
|
stream
|
||||||
|
nextPutAll: '<script type="preformatted">'; lf;
|
||||||
|
nextPutAll: '~~~ Smalltalk'; lf
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
@ -2,7 +2,7 @@ Extension { #name : #LePictureSnippet }
|
|||||||
|
|
||||||
{ #category : #'*Grafoscopio-Utils-Core' }
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
||||||
LePictureSnippet >> asMarkdeep [
|
LePictureSnippet >> asMarkdeep [
|
||||||
| output |
|
| output extraData |
|
||||||
output := '' writeStream.
|
output := '' writeStream.
|
||||||
output
|
output
|
||||||
nextPutAll: self metadataDiv;
|
nextPutAll: self metadataDiv;
|
||||||
@ -24,3 +24,14 @@ LePictureSnippet >> centeredFigure [
|
|||||||
</figure>
|
</figure>
|
||||||
</center>'
|
</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.
|
||||||
|
]
|
||||||
|
12
repository/Grafoscopio-Utils/LeSnippet.extension.st
Normal file
12
repository/Grafoscopio-Utils/LeSnippet.extension.st
Normal 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.
|
||||||
|
]
|
10
repository/Grafoscopio-Utils/LeTextSnippet.extension.st
Normal file
10
repository/Grafoscopio-Utils/LeTextSnippet.extension.st
Normal 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.
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user