More modular code from Lepiter snippets conversion to/from ordered dictionaries.
This commit is contained in:
parent
01a68d562c
commit
a84ead51e1
@ -20,17 +20,13 @@ LeDatabase >> addPageCopy: aLePage [
|
|||||||
|
|
||||||
{ #category : #'*MiniDocs' }
|
{ #category : #'*MiniDocs' }
|
||||||
LeDatabase >> addPageFromMarkdeep: markdeepDocTree withRemote: externalDocLocation [
|
LeDatabase >> addPageFromMarkdeep: markdeepDocTree withRemote: externalDocLocation [
|
||||||
| remoteMetadata divSnippets snippets page |
|
| remoteMetadata divSnippets dataSnippets snippets page |
|
||||||
divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection
|
divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection
|
||||||
collect: [ :xmlElement | xmlElement postCopy ].
|
collect: [ :xmlElement | xmlElement postCopy ].
|
||||||
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
|
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
|
||||||
divSnippets := self sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata.
|
remoteMetadata at: 'origin' put: externalDocLocation.
|
||||||
snippets := divSnippets
|
dataSnippets := self sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata.
|
||||||
collect: [ :xmlElement |
|
snippets := dataSnippets collect: [ :each | each asLepiterSnippet ].
|
||||||
(xmlElement attributes at: 'st-class') = 'LeTextSnippet'
|
|
||||||
ifTrue: [ LeTextSnippet new contentFrom: xmlElement ]
|
|
||||||
ifFalse: [ (xmlElement attributes at: 'st-class') = 'LePharoSnippet'
|
|
||||||
ifTrue: [ LePharoSnippet new contentFrom: xmlElement ] ] ].
|
|
||||||
page := LePage new
|
page := LePage new
|
||||||
title: (remoteMetadata at: 'title');
|
title: (remoteMetadata at: 'title');
|
||||||
basicUid: (UUID fromString36: (remoteMetadata at: 'id'));
|
basicUid: (UUID fromString36: (remoteMetadata at: 'id'));
|
||||||
@ -187,24 +183,33 @@ LeDatabase >> previewSanitizedPageFromMarkdeep: markdeepDocTree withRemote: exte
|
|||||||
| remoteMetadata divSnippets divSnippetsSanitized |
|
| remoteMetadata divSnippets divSnippetsSanitized |
|
||||||
divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection
|
divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection
|
||||||
collect: [ :xmlElement | xmlElement postCopy ].
|
collect: [ :xmlElement | xmlElement postCopy ].
|
||||||
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
|
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
|
||||||
|
remoteMetadata at: 'origin' put: externalDocLocation.
|
||||||
divSnippetsSanitized := self sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata.
|
divSnippetsSanitized := self sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata.
|
||||||
^ { divSnippets . divSnippetsSanitized . remoteMetadata }
|
^ { divSnippets . divSnippetsSanitized . remoteMetadata }
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'*MiniDocs' }
|
{ #category : #'*MiniDocs' }
|
||||||
LeDatabase >> sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata [
|
LeDatabase >> sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata [
|
||||||
^ divSnippets collectWithIndex: [:markdeepDiv :i | | snippetData creationTime modificationTime |
|
^ divSnippets collectWithIndex: [:markdeepDiv :i | | snippetData creationTime modificationTime timestampWarning |
|
||||||
snippetData := markdeepDiv asSnippetDictionary.
|
snippetData := markdeepDiv asSnippetDictionary.
|
||||||
creationTime := snippetData at: 'created'.
|
creationTime := snippetData at: 'created'.
|
||||||
modificationTime := snippetData at: 'modified'.
|
modificationTime := snippetData at: 'modified'.
|
||||||
|
timestampWarning := [:timestamp | 'Modified timestamps: ', timestamp ,' date and time was replaced instead of nil value. See "origin" key for more traceability info.'].
|
||||||
(creationTime = 'nil' and: [ modificationTime ~= 'nil' ])
|
(creationTime = 'nil' and: [ modificationTime ~= 'nil' ])
|
||||||
ifTrue: [ snippetData redefineTimestampsBefore: modificationTime ].
|
ifTrue: [
|
||||||
|
snippetData redefineTimestampsBefore: modificationTime.
|
||||||
|
snippetData addErrata: (timestampWarning value: 'creation').
|
||||||
|
snippetData at: 'origin' put: (remoteMetadata at: 'origin').
|
||||||
|
].
|
||||||
(creationTime = 'nil' and: [ modificationTime = 'nil' ])
|
(creationTime = 'nil' and: [ modificationTime = 'nil' ])
|
||||||
ifTrue: [ | timeDiff |
|
ifTrue: [ | timeDiff |
|
||||||
timeDiff := divSnippets size - i. "Suggesting that last snippets were modified after the first ones."
|
timeDiff := divSnippets size - i. "Suggesting that last snippets were modified after the first ones."
|
||||||
modificationTime := (remoteMetadata at: 'created') asDateAndTime - timeDiff seconds.
|
modificationTime := (remoteMetadata at: 'created') asDateAndTime - timeDiff seconds.
|
||||||
snippetData redefineTimestampsBefore: modificationTime.
|
snippetData redefineTimestampsBefore: modificationTime.
|
||||||
|
snippetData addErrata: (timestampWarning value: 'creation').
|
||||||
|
snippetData addErrata: (timestampWarning value: 'modification').
|
||||||
|
snippetData at: 'origin' put: (remoteMetadata at: 'origin').
|
||||||
].
|
].
|
||||||
snippetData.
|
snippetData.
|
||||||
]
|
]
|
||||||
|
@ -11,19 +11,7 @@ LePharoSnippet >> contentAsStringCustomized [
|
|||||||
{ #category : #'*MiniDocs' }
|
{ #category : #'*MiniDocs' }
|
||||||
LePharoSnippet >> contentFrom: markdeepDiv [
|
LePharoSnippet >> contentFrom: markdeepDiv [
|
||||||
|
|
||||||
| sanitizedStringText metadata joinedText |
|
^ markdeepDiv asSnippetDictionary asLepiterSnippet
|
||||||
metadata := STON fromString: (markdeepDiv attributes at: 'st-data').
|
|
||||||
sanitizedStringText := markdeepDiv contentString lines.
|
|
||||||
sanitizedStringText := sanitizedStringText copyFrom: 4 to: sanitizedStringText size -2.
|
|
||||||
joinedText := '' writeStream.
|
|
||||||
sanitizedStringText do: [ :line | joinedText nextPutAll: line; nextPut: Character lf ].
|
|
||||||
self code: joinedText contents allButLast;
|
|
||||||
uid: (LeUID new uidString: (metadata at: 'id'));
|
|
||||||
parent: (metadata at: 'parent');
|
|
||||||
createTime: (LeTime new time: ((metadata at: 'created')asDateAndTime));
|
|
||||||
editTime: (LeTime new time: ((metadata at: 'modified') asDateAndTime));
|
|
||||||
editEmail: (metadata at: 'modifier');
|
|
||||||
createEmail: (metadata at: 'creator')
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'*MiniDocs' }
|
{ #category : #'*MiniDocs' }
|
||||||
|
@ -16,24 +16,7 @@ LeTextSnippet >> asLePage [
|
|||||||
{ #category : #'*MiniDocs' }
|
{ #category : #'*MiniDocs' }
|
||||||
LeTextSnippet >> contentFrom: markdeepDiv [
|
LeTextSnippet >> contentFrom: markdeepDiv [
|
||||||
|
|
||||||
| sanitizedStringText metadata creationTime modificationTime |
|
^ markdeepDiv asSnippetDictionary asLepiterSnippet
|
||||||
metadata := STON fromString: (markdeepDiv attributes at: 'st-data').
|
|
||||||
self uid: (LeUID new uidString: (metadata at: 'id')).
|
|
||||||
"creationTime is needed to deal with empty values from Grafoscopio migrated notebooks."
|
|
||||||
creationTime := metadata at: 'created'.
|
|
||||||
modificationTime := (metadata at: 'modified') asDateAndTime.
|
|
||||||
(creationTime isNil or: [ creationTime = 'nil']) ifTrue: [
|
|
||||||
creationTime := modificationTime - 1 second.
|
|
||||||
self addErrata: 'Older: created before it appears.'].
|
|
||||||
sanitizedStringText := markdeepDiv contentString.
|
|
||||||
sanitizedStringText := sanitizedStringText allButFirst.
|
|
||||||
sanitizedStringText := sanitizedStringText allButLast.
|
|
||||||
self string: sanitizedStringText;
|
|
||||||
parent: (metadata at: 'parent');
|
|
||||||
createTime: (LeTime new time: creationTime asDateAndTime);
|
|
||||||
editTime: (LeTime new time: modificationTime);
|
|
||||||
editEmail: (metadata at: 'modifier');
|
|
||||||
createEmail: (metadata at: 'creator')
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'*MiniDocs' }
|
{ #category : #'*MiniDocs' }
|
||||||
|
@ -1,13 +1,41 @@
|
|||||||
Extension { #name : #OrderedDictionary }
|
Extension { #name : #OrderedDictionary }
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
OrderedDictionary >> addErrata: noteString [
|
||||||
|
self errata add: noteString
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
OrderedDictionary >> asLepiterSnippet [
|
||||||
|
| response |
|
||||||
|
self at: 'className' ifAbsent: [ ^ nil ].
|
||||||
|
(self at: 'className') = 'LeTextSnippet'
|
||||||
|
ifTrue: [
|
||||||
|
response := LeTextSnippet new.
|
||||||
|
response string: (self at: 'content')
|
||||||
|
].
|
||||||
|
(self at: 'className') = 'LePharoSnippet'
|
||||||
|
ifTrue: [
|
||||||
|
response := LePharoSnippet new.
|
||||||
|
response code: (self at: 'content')
|
||||||
|
].
|
||||||
|
response
|
||||||
|
uid: (LeUID new uidString: (self at: 'id'));
|
||||||
|
parent: (self at: 'parent');
|
||||||
|
createTime: (LeTime new time: ((self at: 'created')asDateAndTime));
|
||||||
|
editTime: (LeTime new time: ((self at: 'modified') asDateAndTime));
|
||||||
|
editEmail: (self at: 'modifier');
|
||||||
|
createEmail: (self at: 'creator').
|
||||||
|
^ response
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
OrderedDictionary >> errata [
|
||||||
|
^ self at: 'errata' ifAbsentPut: [ OrderedCollection new]
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #'*MiniDocs' }
|
{ #category : #'*MiniDocs' }
|
||||||
OrderedDictionary >> redefineTimestampsBefore: dateAndTime [
|
OrderedDictionary >> redefineTimestampsBefore: dateAndTime [
|
||||||
self at: 'modified' put: dateAndTime asDateAndTime.
|
self at: 'modified' put: dateAndTime asDateAndTime.
|
||||||
self at: 'created' put: dateAndTime asDateAndTime - 1 second.
|
self at: 'created' put: dateAndTime asDateAndTime - 1 second.
|
||||||
self at: 'errata' ifAbsentPut: [ | initErrata |
|
|
||||||
initErrata := OrderedCollection new.
|
|
||||||
initErrata add: 'Modified timestamps: created/modified date and time were replaced instead of nil values. See "origin" key for more traceability info.'.
|
|
||||||
initErrata
|
|
||||||
].
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user