From d7da993cd03b8aa08def64716220f21faca8c1b3 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Wed, 8 Sep 2021 17:52:03 -0500 Subject: [PATCH] Improving data serialization and making it more diff friendly. --- repository/TiddlyWiki/Tiddler.class.st | 23 +++++++++++++++++++++-- repository/TiddlyWiki/TiddlyWiki.class.st | 10 ++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 0aa5084..e284779 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -50,8 +50,13 @@ Tiddler >> asDictionary [ ] { #category : 'converting' } -Tiddler >> asJson [ - ^ STONJSON toStringPretty: self asDictionary +Tiddler >> asJson [ + ^ STON toStringPretty: { self asDictionary } +] + +{ #category : 'converting' } +Tiddler >> asJsonString [ + ^ STONJSON toStringPretty: self asDictionary ] { #category : 'accessing' } @@ -60,6 +65,20 @@ Tiddler >> asJsonTempFile [ ] +{ #category : 'accessing' } +Tiddler >> asStonStringPretty [ + | output temp | + temp := self. + temp wiki: nil. + output := '' writeStream. + (STON writer on: output) + newLine: String crlf; + prettyPrint: true; + keepNewLines: true; + nextPut: temp. + ^ output contents +] + { #category : 'accessing' } Tiddler >> bag [ ^ bag diff --git a/repository/TiddlyWiki/TiddlyWiki.class.st b/repository/TiddlyWiki/TiddlyWiki.class.st index 10595b5..7bb9767 100644 --- a/repository/TiddlyWiki/TiddlyWiki.class.st +++ b/repository/TiddlyWiki/TiddlyWiki.class.st @@ -16,9 +16,15 @@ Class { { #category : 'accessing' } TiddlyWiki >> exportSTONTiddlersFile [ - | stonFile | + | stonFile output | stonFile := self tiddlersJSONFile withoutExtension, 'ston'. - ^ MarkupFile exportAsFileOn: stonFile containing:(STON toStringPretty: self) + output := '' writeStream. + (STON writer on: output ) + newLine: String lf; + prettyPrint: true; + keepNewLines: true; + nextPut: self. + ^ MarkupFile exportAsFileOn: stonFile containing:self ] { #category : 'accessing' }