108 lines
2.3 KiB
Smalltalk
108 lines
2.3 KiB
Smalltalk
"
|
|
I model a TiddlyWiki.
|
|
More information:
|
|
|
|
https://tiddlywiki.com/
|
|
"
|
|
Class {
|
|
#name : 'TiddlyWiki',
|
|
#superclass : 'Object',
|
|
#instVars : [
|
|
'tiddlers',
|
|
'file'
|
|
],
|
|
#category : 'TiddlyWiki-Model'
|
|
}
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> exportSTONFile [
|
|
| stonFile output |
|
|
stonFile := self tiddlersJSONFile withoutExtension, 'ston'.
|
|
output := '' writeStream.
|
|
(STON writer on: output )
|
|
newLine: String lf;
|
|
prettyPrint: true;
|
|
keepNewLines: true;
|
|
nextPut: self.
|
|
^ MarkupFile exportAsFileOn: stonFile containing:output contents
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> file [
|
|
^ file
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> file: anObject [
|
|
file := anObject
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> importJSONFile [
|
|
"I import a JSON representation of my tiddlers data, that has been previosly exported
|
|
by the TiddlyWiki HTML self contained file.
|
|
Such file is called, by convention, 'tiddlers.json' and stored in the same folder where
|
|
the HTML file is located."
|
|
| tiddlersDict |
|
|
self tiddlersJSONFile ifNil: [ ^ self ].
|
|
tiddlersDict := STONJSON fromString: self tiddlersJSONFile contents.
|
|
self tiddlers: (tiddlersDict collect: [:each |
|
|
Tiddler new
|
|
fromDictionary: each;
|
|
wiki: self
|
|
])
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> networkView [
|
|
| view |
|
|
view := GtMondrian new.
|
|
view nodes
|
|
with: self tiddlers.
|
|
view edges
|
|
connectFromAll: #linkedTiddlers.
|
|
view layout force.
|
|
^ view
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> printOn: aStream [
|
|
super printOn: aStream.
|
|
aStream
|
|
nextPutAll: '( ', self file basename ,' )'
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> taggedWith: aTag [
|
|
^ self tiddlers select: [:tiddler |
|
|
tiddler tags isNotNil and: [tiddler tags includesSubstring: aTag ]
|
|
]
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> tiddlers [
|
|
|
|
^ tiddlers ifNil: [ tiddlers := OrderedCollection new ]
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> tiddlers: anOrderedCollection [
|
|
|
|
tiddlers := anOrderedCollection
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
TiddlyWiki >> tiddlersJSONFile [
|
|
| jsonFile |
|
|
file ifNil: [
|
|
self inform: 'Provide the location of the TiddlyWiki HTML file.'.
|
|
^ nil
|
|
].
|
|
jsonFile := file parent / 'tiddlers.json'.
|
|
jsonFile exists ifFalse: [
|
|
self inform: 'You need to export tiddlers as JSON from TiddlyWiki and locate it in the same folder as the HTML file'.
|
|
^ nil
|
|
].
|
|
^ jsonFile
|
|
]
|