TiddlyWikiPharo/repository/TiddlyWiki/TiddlyWiki.class.st

186 lines
4.0 KiB
Smalltalk
Raw Normal View History

2021-02-23 17:01:54 +00:00
"
I model a TiddlyWiki.
More information:
https://tiddlywiki.com/
"
Class {
#name : 'TiddlyWiki',
#superclass : 'Object',
2021-02-23 17:01:54 +00:00
#instVars : [
2021-07-15 22:45:53 +00:00
'tiddlers',
'file',
'remote',
'name'
2021-02-23 17:01:54 +00:00
],
#category : 'TiddlyWiki-Model'
2021-02-23 17:01:54 +00:00
}
2021-09-16 00:21:53 +00:00
{ #category : 'accessing' }
TiddlyWiki >> addToConfigFile [
2021-09-16 00:37:57 +00:00
| cleaned |
2021-09-16 00:21:53 +00:00
cleaned := self copy.
cleaned tiddlers: nil.
2021-09-16 00:37:57 +00:00
self configDictonary
2021-09-16 00:21:53 +00:00
at: cleaned name put: cleaned;
yourself.
2021-09-16 00:37:57 +00:00
MarkupFile exportAsFileOn: self configFile containing:(STON toStringPretty: self configDictonary)
]
{ #category : 'accessing' }
TiddlyWiki >> configDictonary [
^ STONJSON fromString: self configFile contents.
2021-09-16 00:21:53 +00:00
]
{ #category : 'accessing' }
TiddlyWiki >> configFile [
| tempFile |
tempFile := FileLocator home / '.config' / 'TiddlyWikiPharo' / 'tiddlywiki.conf.ston'.
tempFile ensureCreateFile.
tempFile contents isEmpty ifTrue: [
MarkupFile exportAsFileOn: tempFile containing: ( STON toStringPretty: Dictionary new)
].
^ tempFile
]
2021-09-01 23:58:15 +00:00
{ #category : 'accessing' }
TiddlyWiki >> exportSTONFile [
| stonFile output |
2021-09-01 23:58:15 +00:00
stonFile := self tiddlersJSONFile withoutExtension, 'ston'.
output := '' writeStream.
(STON writer on: output )
newLine: String lf;
prettyPrint: true;
keepNewLines: true;
nextPut: self.
2021-09-08 23:46:09 +00:00
^ MarkupFile exportAsFileOn: stonFile containing:output contents
2021-09-01 23:58:15 +00:00
]
{ #category : 'accessing' }
2021-07-15 22:45:53 +00:00
TiddlyWiki >> file [
^ file
]
{ #category : 'accessing' }
2021-07-15 22:45:53 +00:00
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."
2021-08-11 17:10:53 +00:00
| tiddlersDict |
self tiddlersJSONFile ifNil: [ ^ self ].
tiddlersDict := STONJSON fromString: self tiddlersJSONFile contents.
self tiddlers: (tiddlersDict collect: [:each |
Tiddler new
fromDictionary: each;
wiki: self
])
2021-08-11 17:10:53 +00:00
]
2021-02-23 17:01:54 +00:00
2021-09-16 00:37:57 +00:00
{ #category : 'accessing' }
TiddlyWiki >> loadFromConfig: wikiname [
self configDictonary
]
{ #category : 'accessing' }
TiddlyWiki >> local [
^ self file
]
{ #category : 'accessing' }
TiddlyWiki >> local: aFileRefence [
^ self file:aFileRefence
]
{ #category : 'accessing' }
TiddlyWiki >> name [
| tempName suffix |
name ifNotNil: [ ^ name ].
self file ifNotNil: [ ^ name := self file basenameWithoutExtension ].
self remote ifNil: [ ^ name := nil ].
tempName := self remote file.
(tempName endsWithAnyOf: #('.html' '.htm')) ifTrue: [
suffix := (tempName splitOn: '.') last.
tempName := tempName removeSuffix: '.', suffix.
].
name := tempName
]
{ #category : 'accessing' }
TiddlyWiki >> name: aString [
name := aString
]
{ #category : 'accessing' }
2021-08-17 18:24:00 +00:00
TiddlyWiki >> networkView [
| view |
view := GtMondrian new.
view nodes
with: self tiddlers.
view edges
connectFromAll: #linkedTiddlers.
view layout force.
^ view
]
{ #category : 'accessing' }
2021-08-11 17:10:53 +00:00
TiddlyWiki >> printOn: aStream [
super printOn: aStream.
aStream
nextPutAll: '( ', self file basename ,' )'
2021-02-23 17:01:54 +00:00
]
{ #category : 'accessing' }
TiddlyWiki >> remote [
^ remote
]
{ #category : 'accessing' }
TiddlyWiki >> remote: aUrlString [
remote := aUrlString asZnUrl
]
{ #category : 'accessing' }
TiddlyWiki >> taggedWith: aTag [
^ self tiddlers select: [:tiddler |
tiddler tags isNotNil and: [tiddler tags includesSubstring: aTag ]
]
]
{ #category : 'accessing' }
2021-02-23 17:01:54 +00:00
TiddlyWiki >> tiddlers [
^ tiddlers ifNil: [ tiddlers := OrderedCollection new ]
]
{ #category : 'accessing' }
2021-02-23 17:01:54 +00:00
TiddlyWiki >> tiddlers: anOrderedCollection [
tiddlers := anOrderedCollection
]
2021-07-15 22:45:53 +00:00
{ #category : 'accessing' }
2021-07-15 22:45:53 +00:00
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
2021-07-15 22:45:53 +00:00
]