From af8b05295e5d3014d0bd5b9e3fa0818482b6e918 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Wed, 11 Aug 2021 12:10:53 -0500 Subject: [PATCH] Improving importation and printing. --- repository/TiddlyWiki/Tiddler.class.st | 14 ++++++++++++ repository/TiddlyWiki/TiddlyWiki.class.st | 28 ++++++++++------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 3b79573..67a56a1 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -86,6 +86,20 @@ Tiddler >> creator: anObject [ creator := anObject ] +{ #category : #accessing } +Tiddler >> fromDictionary: aDictionary [ + self + title: (aDictionary at: 'title'); + text: (aDictionary at: 'text'); + tags: (aDictionary at: 'tags' ifAbsentPut: [ nil ]); + created: (aDictionary at: 'created' ifAbsentPut: [ nil ]); + creator: (aDictionary at: 'creator' ifAbsentPut: [ nil ]); + modified: (aDictionary at: 'modified' ifAbsentPut: [ nil ]); + modifier: (aDictionary at: 'modifier' ifAbsentPut: [ nil ]); + type: (aDictionary at: 'type' ifAbsentPut: [ nil ]); + caption: (aDictionary at: 'caption' ifAbsentPut: [ nil ]). +] + { #category : #'instance creation' } Tiddler >> fromMarkdownParsedItems: aCollection [ | outputStream | diff --git a/repository/TiddlyWiki/TiddlyWiki.class.st b/repository/TiddlyWiki/TiddlyWiki.class.st index 14bb2fe..ba5821f 100644 --- a/repository/TiddlyWiki/TiddlyWiki.class.st +++ b/repository/TiddlyWiki/TiddlyWiki.class.st @@ -24,23 +24,19 @@ TiddlyWiki >> file: anObject [ file := anObject ] -{ #category : #'instance creation' } -TiddlyWiki >> fromJSONString: aString [ - | rawData | - rawData := NeoJSONReader fromString: aString. - rawData do: [ :data | | temp | - temp := Tiddler new. - temp - modified: (data at: 'modified'); - created: (data at: 'created' ifAbsent: [ temp created: nil ]); - title: (data at: 'title'); - tags: (data at: 'tags' ifAbsent: [ temp tags: nil ]); - type: (data at: 'type' ifAbsent: [ temp type: nil ]); - caption: (data at: 'caption' ifAbsent: [ temp caption: nil ]); - text: (data at: 'text'). - self tiddlers add: temp. - ]. +{ #category : #accessing } +TiddlyWiki >> importJSONTiddlers [ + | tiddlersDict | + self tiddlersJSONFile ifNil: [ ^ self ]. + tiddlersDict := STONJSON fromString: self tiddlersJSONFile contents. + self tiddlers: (tiddlersDict collect: [:each | Tiddler new fromDictionary: each ]) +] +{ #category : #accessing } +TiddlyWiki >> printOn: aStream [ + super printOn: aStream. + aStream + nextPutAll: '( ', self file basename ,' )' ] { #category : #accessing }