2021-02-23 17:01:54 +00:00
|
|
|
"
|
|
|
|
I model a TiddlyWiki.
|
|
|
|
More information:
|
|
|
|
|
|
|
|
https://tiddlywiki.com/
|
|
|
|
"
|
|
|
|
Class {
|
2021-10-19 23:23:57 +00:00
|
|
|
#name : #TiddlyWiki,
|
|
|
|
#superclass : #Object,
|
2021-02-23 17:01:54 +00:00
|
|
|
#instVars : [
|
2021-07-15 22:45:53 +00:00
|
|
|
'tiddlers',
|
2021-09-14 01:19:31 +00:00
|
|
|
'file',
|
|
|
|
'remote',
|
|
|
|
'name'
|
2021-02-23 17:01:54 +00:00
|
|
|
],
|
2021-10-20 18:35:57 +00:00
|
|
|
#category : #'TiddlyWiki-Model'
|
2021-02-23 17:01:54 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 01:49:58 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
TiddlyWiki class >> fromJSONUrl: anUrlString [
|
2021-11-05 22:19:09 +00:00
|
|
|
| rawContents contentsString |
|
|
|
|
rawContents := anUrlString asUrl retrieveContents.
|
|
|
|
rawContents class = ByteArray
|
|
|
|
ifTrue: [ contentsString := rawContents utf8Decoded ]
|
|
|
|
ifFalse: [ contentsString := rawContents ].
|
2021-11-04 01:49:58 +00:00
|
|
|
^ self new
|
2021-11-05 22:19:09 +00:00
|
|
|
fromDictionary: (STONJSON fromString: contentsString);
|
|
|
|
remote: anUrlString;
|
|
|
|
name: anUrlString
|
2021-11-04 01:49:58 +00:00
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-16 00:21:53 +00:00
|
|
|
TiddlyWiki >> addToConfigFile [
|
2021-11-05 13:21:59 +00:00
|
|
|
| cleaned newConfig |
|
2021-09-16 00:21:53 +00:00
|
|
|
cleaned := self copy.
|
|
|
|
cleaned tiddlers: nil.
|
2021-11-05 13:21:59 +00:00
|
|
|
newConfig := self configDictonary
|
2021-09-16 00:21:53 +00:00
|
|
|
at: cleaned name put: cleaned;
|
|
|
|
yourself.
|
2021-11-05 13:21:59 +00:00
|
|
|
^ MarkupFile exportAsFileOn: self configFile containing:(STON toStringPretty: newConfig)
|
2021-09-16 00:37:57 +00:00
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-16 00:37:57 +00:00
|
|
|
TiddlyWiki >> configDictonary [
|
|
|
|
^ STONJSON fromString: self configFile contents.
|
2021-09-16 00:21:53 +00:00
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-16 00:21:53 +00:00
|
|
|
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-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-10-06 00:26:17 +00:00
|
|
|
TiddlyWiki >> exportJSONSubtiddlers: subtiddlersCollection [
|
|
|
|
^ MarkupFile exportAsFileOn: self file parent / 'subtiddlers.json' containing: (self jsonSubtiddlers: subtiddlersCollection)
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-10 16:24:19 +00:00
|
|
|
TiddlyWiki >> exportSTONFile [
|
2021-10-20 18:35:57 +00:00
|
|
|
| stonFile output wikiTemp |
|
2021-11-04 09:37:45 +00:00
|
|
|
self tiddlersJSONFile
|
|
|
|
ifNil: [
|
|
|
|
self inform: 'No JSON Tiddlers file found. If you have one, please provide its location'.
|
|
|
|
stonFile := FileLocator temp / 'tiddlers.ston' ]
|
|
|
|
ifNotNil: [ stonFile := self tiddlersJSONFile withoutExtension, 'ston' ].
|
2021-09-08 22:52:03 +00:00
|
|
|
output := '' writeStream.
|
|
|
|
(STON writer on: output )
|
|
|
|
newLine: String lf;
|
|
|
|
prettyPrint: true;
|
|
|
|
keepNewLines: true;
|
2021-10-20 18:35:57 +00:00
|
|
|
nextPut: self withoutImages.
|
2021-09-08 23:46:09 +00:00
|
|
|
^ MarkupFile exportAsFileOn: stonFile containing:output contents
|
2021-09-01 23:58:15 +00:00
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-07-15 22:45:53 +00:00
|
|
|
TiddlyWiki >> file [
|
|
|
|
^ file
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-07-15 22:45:53 +00:00
|
|
|
TiddlyWiki >> file: anObject [
|
|
|
|
file := anObject
|
|
|
|
]
|
|
|
|
|
2021-11-04 01:49:58 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
TiddlyWiki >> fromDictionary: tiddlersDict [
|
|
|
|
|
|
|
|
self tiddlers: (tiddlersDict collect: [ :each |
|
|
|
|
Tiddler new
|
|
|
|
fromDictionary: each;
|
|
|
|
wiki: self ])
|
|
|
|
]
|
|
|
|
|
2022-01-10 23:19:17 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
TiddlyWiki >> fromUrl: anUrlString [
|
|
|
|
| docTree rawJsonTiddlers tiddlersDictionary |
|
|
|
|
self remote: anUrlString.
|
|
|
|
docTree := XMLHTMLParser parse: (self remote retrieveContents).
|
|
|
|
rawJsonTiddlers := (docTree xpath: '//script[@class="tiddlywiki-tiddler-store"]') stringValue.
|
|
|
|
tiddlersDictionary := STONJSON fromString: rawJsonTiddlers.
|
|
|
|
self fromDictionary: tiddlersDictionary
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-10 16:24:19 +00:00
|
|
|
TiddlyWiki >> importJSONFile [
|
2021-11-04 01:49:58 +00:00
|
|
|
|
2021-09-10 16:24:19 +00:00
|
|
|
"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-11-04 01:49:58 +00:00
|
|
|
|
2021-08-11 17:10:53 +00:00
|
|
|
| tiddlersDict |
|
|
|
|
self tiddlersJSONFile ifNil: [ ^ self ].
|
|
|
|
tiddlersDict := STONJSON fromString: self tiddlersJSONFile contents.
|
2021-11-04 01:49:58 +00:00
|
|
|
self fromDictionary: tiddlersDict
|
2021-08-11 17:10:53 +00:00
|
|
|
]
|
2021-02-23 17:01:54 +00:00
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-10-06 00:26:17 +00:00
|
|
|
TiddlyWiki >> jsonSubtiddlers: subtiddlersCollection [
|
|
|
|
| subtiddlersDict |
|
|
|
|
subtiddlersDict := subtiddlersCollection collect: [:tiddler | tiddler asDictionary ].
|
|
|
|
^ STONJSON toStringPretty: subtiddlersDict
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-16 00:37:57 +00:00
|
|
|
TiddlyWiki >> loadFromConfig: wikiname [
|
2021-11-10 15:28:42 +00:00
|
|
|
^ (self configDictonary at: wikiname) importJSONFile.
|
2021-09-16 00:37:57 +00:00
|
|
|
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-14 01:19:31 +00:00
|
|
|
TiddlyWiki >> local [
|
|
|
|
^ self file
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-14 01:19:31 +00:00
|
|
|
TiddlyWiki >> local: aFileRefence [
|
|
|
|
^ self file:aFileRefence
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-14 01:19:31 +00:00
|
|
|
TiddlyWiki >> name [
|
2021-09-15 01:14:20 +00:00
|
|
|
| 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
|
2021-09-14 01:19:31 +00:00
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-14 01:19:31 +00:00
|
|
|
TiddlyWiki >> name: aString [
|
|
|
|
|
|
|
|
name := aString
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #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
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-08-11 17:10:53 +00:00
|
|
|
TiddlyWiki >> printOn: aStream [
|
|
|
|
super printOn: aStream.
|
|
|
|
aStream
|
2021-11-04 01:49:58 +00:00
|
|
|
nextPutAll: '( ', self name ,' )'
|
2021-02-23 17:01:54 +00:00
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-14 01:19:31 +00:00
|
|
|
TiddlyWiki >> remote [
|
|
|
|
|
|
|
|
^ remote
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-09-14 01:19:31 +00:00
|
|
|
TiddlyWiki >> remote: aUrlString [
|
|
|
|
|
|
|
|
remote := aUrlString asZnUrl
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-08-17 17:03:53 +00:00
|
|
|
TiddlyWiki >> taggedWith: aTag [
|
|
|
|
^ self tiddlers select: [:tiddler |
|
|
|
|
tiddler tags isNotNil and: [tiddler tags includesSubstring: aTag ]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-02-23 17:01:54 +00:00
|
|
|
TiddlyWiki >> tiddlers [
|
|
|
|
|
|
|
|
^ tiddlers ifNil: [ tiddlers := OrderedCollection new ]
|
|
|
|
]
|
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-02-23 17:01:54 +00:00
|
|
|
TiddlyWiki >> tiddlers: anOrderedCollection [
|
|
|
|
|
|
|
|
tiddlers := anOrderedCollection
|
|
|
|
]
|
2021-07-15 22:45:53 +00:00
|
|
|
|
2021-10-19 23:23:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-07-15 22:45:53 +00:00
|
|
|
TiddlyWiki >> tiddlersJSONFile [
|
2021-09-10 16:24:19 +00:00
|
|
|
| jsonFile |
|
2021-11-04 09:37:45 +00:00
|
|
|
self file ifNil: [
|
|
|
|
self inform: 'No TiddlyWiki HTML file found. If you have one, please provide its location.'.
|
2021-09-10 16:24:19 +00:00
|
|
|
^ 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
|
|
|
]
|
2021-10-20 18:35:57 +00:00
|
|
|
|
2021-11-05 13:21:59 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
TiddlyWiki >> tiddlersJSONUrl [
|
|
|
|
self remote ifNil: [^ nil].
|
|
|
|
]
|
|
|
|
|
2021-10-20 18:35:57 +00:00
|
|
|
{ #category : #accessing }
|
2021-11-30 19:39:25 +00:00
|
|
|
TiddlyWiki >> withoutApplicationType: application [
|
2021-10-20 18:35:57 +00:00
|
|
|
| filteredTiddlers tempWiki |
|
2021-11-30 19:39:25 +00:00
|
|
|
filteredTiddlers := self tiddlers reject: [:tiddler | tiddler type isNotNil and: [tiddler type beginsWith: application] ].
|
2021-10-20 18:35:57 +00:00
|
|
|
tempWiki := self copy
|
|
|
|
tiddlers: filteredTiddlers.
|
|
|
|
tempWiki tiddlers do: [:tiddler | tiddler wiki: tempWiki ].
|
|
|
|
^ tempWiki
|
|
|
|
]
|
2021-11-30 19:39:25 +00:00
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
TiddlyWiki >> withoutImages [
|
|
|
|
^ self withoutApplicationType: 'image/'
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
TiddlyWiki >> withoutPDFs [
|
|
|
|
^ self withoutApplicationType: 'application/pdf'
|
|
|
|
]
|