From b0ca67d17fb84e081ec8339d7a986f3ab5ac49aa Mon Sep 17 00:00:00 2001 From: ruidajo Date: Thu, 17 Feb 2022 20:16:11 -0500 Subject: [PATCH] Improving tiddler testing and exporting. --- repository/TiddlyWiki/Tiddler.class.st | 30 ++++++++++++++++ repository/TiddlyWiki/TiddlyWiki.class.st | 44 +++++++++++++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 30238ef..9b9f26d 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -223,18 +223,36 @@ Tiddler >> importFedWikiPage: pageViewUrlString [ ^ STONJSON fromString: pageData retrieveContents ] +{ #category : #testing } +Tiddler >> isImage [ + + ^ self type = 'image/' +] + { #category : #testing } Tiddler >> isJavascript [ ^ self type = 'application/javascript' ] +{ #category : #testing } +Tiddler >> isMarkdown [ + + ^ self type = 'text/x-markdown' +] + { #category : #testing } Tiddler >> isNilType [ ^ self type = nil ] +{ #category : #testing } +Tiddler >> isPDF [ + + ^ self type = 'application/pdf' +] + { #category : #testing } Tiddler >> isShadow [ @@ -247,6 +265,18 @@ Tiddler >> isTW5Type [ ^ self type = 'text/vnd.tiddlywiki' ] +{ #category : #testing } +Tiddler >> isTextPlain [ + + ^ self type = 'text/plain' +] + +{ #category : #testing } +Tiddler >> isXTiddlerDictionary [ + + ^ self type = 'application/x-tiddler-dictionary' +] + { #category : #utilities } Tiddler >> itemContentsStringFor: item into: stream [ stream diff --git a/repository/TiddlyWiki/TiddlyWiki.class.st b/repository/TiddlyWiki/TiddlyWiki.class.st index 669a076..003df92 100644 --- a/repository/TiddlyWiki/TiddlyWiki.class.st +++ b/repository/TiddlyWiki/TiddlyWiki.class.st @@ -80,6 +80,22 @@ TiddlyWiki >> contentTiddlers [ ^ self tiddlers copyWithoutAll: self shadow ] +{ #category : #accessing } +TiddlyWiki >> exportContentTiddlers [ + + | content | + content := OrderedCollection new. +content + addAll: (self contentTiddlers + select: [ :each | each isTW5Type or: [ each isNilType ]]); + addAll: (self contentTiddlers select: [ :each | each isJavascript ]); + addAll: (self contentTiddlers select: [ :each | each isXTiddlerDictionary ]); + addAll: (self contentTiddlers select: [ :each | each isTextPlain ]); + addAll: (self contentTiddlers select: [ :each | each isMarkdown ]). + ^ content do: [ :each | + each exportSTONFileInto: 'tiddlers' ]. +] + { #category : #accessing } TiddlyWiki >> exportContentType: aMimeType [ @@ -321,15 +337,31 @@ TiddlyWiki >> printOn: aStream [ nextPutAll: '( ', self name ,' )' ] +{ #category : #accessing } +TiddlyWiki >> rebuildTiddlers [ + + | stonTiddlers contentTiddlersFiles shadowTiddlersFile | + + shadowTiddlersFile := self largeTiddlersFolder asFileReference children + select: [ :each | each basename beginsWith: '_shadow.ston' ]. + contentTiddlersFiles := self tiddlersFolder files + select: [ :each | each basename endsWith: 'ston' ]. + + stonTiddlers := OrderedCollection new. + stonTiddlers + addAll: (((self largeTiddlersFolder files) + reject: [ :each | each basename beginsWith: '_shadow.ston' ]) + collect: [ :each | STONJSON fromString: each contents ]); + addAll: (STON fromString:shadowTiddlersFile first contents); + addAll: (contentTiddlersFiles collect:[ :each | STONJSON fromString: each contents ]). + ^ stonTiddlers +] + { #category : #accessing } TiddlyWiki >> rebuildTiddlersJSON [ - | stonTiddlers stonTiddlerFiles | - stonTiddlerFiles := self tiddlersFolder asFileReference children - select: [ :each | each fullName endsWith: 'ston' ]. - stonTiddlers := stonTiddlerFiles collect: [ :each | STON fromString: each contents ]. - self tiddlers: stonTiddlers. - ^ self exportJSONSubtiddlers: self tiddlers as: 'rebuildedTiddlers'. + self tiddlers: self rebuildTiddlers. + ^ self exportJSONSubtiddlers: (self rebuildTiddlers asArray) as: 'rebuildedTiddlers'. ] { #category : #accessing }