GrafoscopioUtils/repository/Grafoscopio-Utils/LePage.extension.st

94 lines
2.8 KiB
Smalltalk
Raw Normal View History

Extension { #name : #LePage }
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> asMarkdeepInto: aFileLocator [
self preorderTraversal
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> detectParentSnippetWithUid: uidString [
"Answer a boolean indicating whether the supplied uid is present"
^ self preorderTraversal detect: [ :snippet | snippet uidString = uidString ] ifNone: [ ^ self ]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> fileName [
^ self title asDashedLowercase, '.', ((self uidString copyFrom: 1 to: 5 ) copyWithoutAll: '/'), '.md.html'
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> fromMarkdeepUrl: aString [
| docTree pageMetadata |
docTree := GrafoscopioUtils xmlFromUrl: aString.
pageMetadata := Markdeep new metadataFromXML: docTree.
self
basicUid: (pageMetadata at: 'id');
title: (pageMetadata at: 'title');
2022-03-01 14:15:05 +00:00
createTime: (pageMetadata at: 'created') asDateAndTime;
editTime: (pageMetadata at: 'modified') asDateAndTime;
createEmail: (pageMetadata at: 'creator');
editEmail: (pageMetadata at: 'modifier');
optionAt: 'metadata' put: pageMetadata.
self populateChildrenFrom: (docTree xpath: '//div')
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> metadata [
2022-01-28 22:01:41 +00:00
^ self options at: 'metadata' ifAbsentPut: [ self metadataInit]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> metadataInit [
^ OrderedDictionary new
2022-01-28 22:01:41 +00:00
at: 'id' put: self uidString;
2022-01-29 03:34:33 +00:00
at: 'title' put: self contentAsString;
2022-01-28 22:01:41 +00:00
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' }
LePage >> navTop [
| topNavFile |
topNavFile := ((self optionAt: 'storage') / '_navtop.html').
topNavFile exists
ifFalse: [ ^ '' ]
ifTrue: [ ^ topNavFile contents ]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> options [
^ options
]
2022-01-28 20:33:05 +00:00
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> populateChildrenFrom: docTreeDivs [
docTreeDivs doWithIndex: [:div :i | | snippetTemp parent "surrogate" |
snippetTemp := LeSnippet fromMetaMarkdeep:div.
parent := self detectParentSnippetWithUid: (snippetTemp metadata at: 'parent').
parent snippetBuilder snippet: snippetTemp; add.
]
]
2022-01-28 20:33:05 +00:00
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> preorderTraversal [
| output |
output := OrderedCollection new.
self withDeepCollect: [:each | each allChildrenBreadthFirstDo: [:child | output add: child ] ].
^ output.
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> removeSnippetsMetadata [
2022-02-11 20:56:21 +00:00
self preorderTraversal do: [ :snippet |
(snippet options isNotNil and: [ snippet options includesKey: 'metadata' ])
ifTrue: [ snippet options removeKey: 'metadata' ] ]
]