2021-02-23 17:01:54 +00:00
|
|
|
"
|
|
|
|
I model a Tiddler object in [TiddlyWiki](https://tiddlywiki.com/).
|
|
|
|
|
|
|
|
I implement the standard fields as described in the standard documentation at: <https://tiddlywiki.com/#TiddlerFields>
|
|
|
|
|
|
|
|
"
|
|
|
|
Class {
|
|
|
|
#name : #Tiddler,
|
|
|
|
#superclass : #Object,
|
|
|
|
#instVars : [
|
|
|
|
'title',
|
|
|
|
'text',
|
|
|
|
'modified',
|
|
|
|
'created',
|
|
|
|
'creator',
|
|
|
|
'tags',
|
|
|
|
'type',
|
|
|
|
'list',
|
2021-07-15 22:24:05 +00:00
|
|
|
'caption',
|
|
|
|
'modifier'
|
2021-02-23 17:01:54 +00:00
|
|
|
],
|
|
|
|
#category : #'TiddlyWiki-Model'
|
|
|
|
}
|
|
|
|
|
2021-08-08 18:11:57 +00:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Tiddler class >> nowLocal [
|
|
|
|
^ (ZTimestampFormat fromString: '200102031605067')
|
|
|
|
format: (ZTimestamp fromString: Time nowLocal asDateAndTime asString)
|
|
|
|
]
|
|
|
|
|
2021-06-05 18:32:51 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> asDictionary [
|
|
|
|
^ Dictionary new
|
|
|
|
at: 'title' put: self title;
|
|
|
|
at: 'text' put: self text;
|
|
|
|
at: 'created' put: self created asString;
|
|
|
|
at: 'tags' put: self tags;
|
2021-08-09 13:52:19 +00:00
|
|
|
at: 'type' put: self type;
|
2021-06-05 18:32:51 +00:00
|
|
|
yourself.
|
|
|
|
]
|
|
|
|
|
2021-07-15 22:24:05 +00:00
|
|
|
{ #category : #converting }
|
|
|
|
Tiddler >> asJson [
|
|
|
|
^ STONJSON toStringPretty: self asDictionary
|
|
|
|
]
|
|
|
|
|
2021-02-23 17:01:54 +00:00
|
|
|
{ #category : #accessing }
|
2021-08-07 22:03:22 +00:00
|
|
|
Tiddler >> asJsonTempFile [
|
2021-08-08 18:11:57 +00:00
|
|
|
^ MarkupFile exportAsFileOn: FileLocator temp / self title, 'json' containing:self asJson
|
2021-08-07 22:03:22 +00:00
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2021-02-23 17:01:54 +00:00
|
|
|
Tiddler >> caption [
|
|
|
|
|
|
|
|
^ caption
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> caption: anObject [
|
|
|
|
|
|
|
|
caption := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> created [
|
|
|
|
|
2021-06-05 18:32:51 +00:00
|
|
|
^ created ifNil: [ created := DateAndTime now ]
|
2021-02-23 17:01:54 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> created: anObject [
|
|
|
|
|
|
|
|
created := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> creator [
|
|
|
|
|
|
|
|
^ creator
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> creator: anObject [
|
|
|
|
|
|
|
|
creator := anObject
|
|
|
|
]
|
|
|
|
|
2021-08-11 17:10:53 +00:00
|
|
|
{ #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 ]).
|
|
|
|
]
|
|
|
|
|
2021-02-23 17:01:54 +00:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Tiddler >> fromMarkdownParsedItems: aCollection [
|
|
|
|
| outputStream |
|
|
|
|
outputStream := '' writeStream.
|
|
|
|
aCollection children do: [ :each |
|
|
|
|
each children
|
|
|
|
ifEmpty: [ self itemContentsStringFor: each into: outputStream ]
|
|
|
|
ifNotEmpty: [
|
|
|
|
each children do: [ :child |
|
|
|
|
self itemContentsStringFor: child into: outputStream ] ]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2021-08-04 16:36:20 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> importFedWikiPage: pageViewUrlString [
|
|
|
|
| pageTitle pageViewUrl pageData |
|
|
|
|
pageViewUrl := pageViewUrlString asZnUrl.
|
|
|
|
pageTitle := pageViewUrl segments second.
|
|
|
|
pageData := (pageViewUrl scheme, '://', pageViewUrl host, '/', pageTitle, '.json') asZnUrl.
|
|
|
|
^ STONJSON fromString: pageData retrieveContents
|
|
|
|
]
|
|
|
|
|
2021-02-23 17:01:54 +00:00
|
|
|
{ #category : #utilities }
|
|
|
|
Tiddler >> itemContentsStringFor: item into: stream [
|
|
|
|
stream
|
|
|
|
nextPutAll: item text;
|
|
|
|
nextPut: Character cr;
|
|
|
|
nextPut: Character cr
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> list [
|
|
|
|
|
|
|
|
^ list
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> list: anObject [
|
|
|
|
|
|
|
|
list := anObject
|
|
|
|
]
|
|
|
|
|
2021-07-15 22:24:05 +00:00
|
|
|
{ #category : #utilities }
|
|
|
|
Tiddler >> markdownLinksAsWikiText [
|
|
|
|
"I'm useful to convert _internal_ links between formats, as is a common pattern
|
|
|
|
found when migrating content from Markdown to TiddlyWiki's WikiText.
|
|
|
|
I DON'T work on external links. A better regex could be used for that.
|
|
|
|
See:
|
|
|
|
- https://davidwells.io/snippets/regex-match-markdown-links
|
|
|
|
- http://blog.michaelperrin.fr/2019/02/04/advanced-regular-expressions/"
|
|
|
|
| markdownLinks |
|
|
|
|
markdownLinks := (self text splitOn: Character space) select: [:each | each matchesRegex: '\[(.+)\)'].
|
|
|
|
markdownLinks ifEmpty: [^ self].
|
|
|
|
^ markdownLinks
|
|
|
|
]
|
|
|
|
|
2021-02-23 17:01:54 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> modified [
|
|
|
|
|
|
|
|
^ modified
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> modified: anObject [
|
|
|
|
|
|
|
|
modified := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2021-07-15 22:24:05 +00:00
|
|
|
Tiddler >> modifier [
|
2021-02-23 17:01:54 +00:00
|
|
|
|
2021-07-15 22:24:05 +00:00
|
|
|
^ modifier
|
2021-02-23 17:01:54 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2021-07-15 22:24:05 +00:00
|
|
|
Tiddler >> modifier: anObject [
|
|
|
|
|
|
|
|
modifier := anObject
|
|
|
|
]
|
2021-02-23 17:01:54 +00:00
|
|
|
|
2021-07-15 22:24:05 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> printOn: aStream [
|
|
|
|
super printOn: aStream.
|
|
|
|
aStream
|
|
|
|
nextPutAll: '( ', self title, ' )'
|
2021-02-23 17:01:54 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> tags [
|
|
|
|
|
|
|
|
^ tags
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> tags: anObject [
|
|
|
|
|
|
|
|
tags := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> text [
|
|
|
|
|
|
|
|
^ text
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> text: anObject [
|
|
|
|
|
|
|
|
text := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> title [
|
|
|
|
|
|
|
|
^ title
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> title: anObject [
|
|
|
|
|
|
|
|
title := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> type [
|
|
|
|
|
|
|
|
^ type
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Tiddler >> type: anObject [
|
|
|
|
|
|
|
|
type := anObject
|
|
|
|
]
|