TiddlyWikiPharo/repository/TiddlyWiki/TWSeed.class.st
2022-01-21 20:37:56 -05:00

124 lines
2.4 KiB
Smalltalk

Class {
#name : #TWSeed,
#superclass : #Object,
#instVars : [
'name',
'demo'
],
#classVars : [
'list'
],
#category : #'TiddlyWiki-Model'
}
{ #category : #accessing }
TWSeed class >> default [
^ self selectSeed: 'ProjectifyMod'
]
{ #category : #accessing }
TWSeed class >> deleteWikiFileFromFolder: folder andSubfolder: shortName [
| file |
file := folder / shortName / 'index.html'.
file exists ifFalse: [^ self].
^ file ensureDelete.
]
{ #category : #accessing }
TWSeed class >> install: seedName into: folder as: shortName [
| file url seedFile subfolder wiki |
seedFile := self selectSeed: seedName.
subfolder := (folder / shortName) ensureCreateDirectory.
file := subfolder / 'index.html'.
file exists
ifTrue: [ self inform: 'Index file in the wiki subfolder already exists. Please choose:
1 select another folder + shortName combination or
2 run:
self deleteWikiFileFromFolder: folder andSubfolder: shortName.'.
^ self
].
url := seedFile demo.
url asUrl saveContentsToFile: file.
^ wiki := TiddlyWiki new
file: file;
name: shortName.
]
{ #category : #accessing }
TWSeed class >> installDefaultInto: folder as: shortName [
^ self install: 'ProjectifyMod' into: folder as: shortName
]
{ #category : #accessing }
TWSeed class >> list [
^ list
ifNil: [ self initialize.
^ self list.
]
]
{ #category : #accessing }
TWSeed class >> selectSeed: aSeedName [
^ (self list select: [ :seed | seed name = aSeedName ]) first
]
{ #category : #accessing }
TWSeed >> demo [
^ demo
]
{ #category : #accessing }
TWSeed >> demo: anUrl [
demo := anUrl asZnUrl
]
{ #category : #accessing }
TWSeed >> initialize [
super initialize.
list := OrderedCollection new.
list
add: (self class new
name: 'ProjectifyMod';
demo: 'https://mutabit.com/repos.fossil/tiddlywiki/uv/seeds/projectify/projectify-mod.html');
add: (self class new
name: 'Wikilexias';
demo: 'https://mutabit.com/repos.fossil/tiddlywiki/uv/seeds/wikilexias/wikilexias.html');
add: (self class new
name: 'NotebookMod';
demo: '');
add: (self class new
name: 'Grafoscopedia';
demo: '');
add: (self class new
name: 'Holonica';
demo: '').
^ self
]
{ #category : #accessing }
TWSeed >> name [
^ name
]
{ #category : #accessing }
TWSeed >> name: aString [
name := aString
]
{ #category : #accessing }
TWSeed >> preview: anObject [
^ demo := anObject
]