72 lines
1.7 KiB
Smalltalk
72 lines
1.7 KiB
Smalltalk
"
|
|
I model the file where contents (data and/or metadata) for the Brea CSM pages are stored.
|
|
"
|
|
Class {
|
|
#name : #BreaFile,
|
|
#superclass : #Object,
|
|
#instVars : [
|
|
'folder',
|
|
'name'
|
|
],
|
|
#category : #Brea
|
|
}
|
|
|
|
{ #category : #'instance creation' }
|
|
BreaFile class >> fromShortName: nameString andFolder: aFileLocation [
|
|
"I create a new BreaFile assigning priorities to the filename discovery according to
|
|
their extension currently present in a particular folder."
|
|
| extensions |
|
|
|
|
extensions := #('md' 'json' 'yaml').
|
|
extensions do: [ :ext | | markupFile filename |
|
|
filename := nameString, '.', ext.
|
|
markupFile := aFileLocation / filename.
|
|
markupFile exists ifTrue: [ ^ self new name: filename; folder: aFileLocation ].
|
|
].
|
|
^ nil.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaFile >> contentString [
|
|
|
|
self name ifNil: [ ^ nil ].
|
|
(self name endsWith: '.md') ifTrue: [ ^ self contents contents ].
|
|
(self name endsWith: '.json') ifTrue: [ ^ self contents asString ].
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaFile >> contents [
|
|
| file |
|
|
self name ifNil: [ ^ nil ].
|
|
file := self folder / self name.
|
|
(self name endsWith: '.md') ifTrue: [ ^ Markdown fromFile: file ].
|
|
(self name endsWith: '.json') ifTrue: [ ^ NeoJSONObject fromString: file contents ]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaFile >> folder [
|
|
^ folder
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaFile >> folder: anObject [
|
|
folder := anObject
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaFile >> metadata [
|
|
self name ifNil: [ ^ nil ].
|
|
(self name endsWith: '.md') ifTrue: [ ^ self contents metadata ].
|
|
(self name endsWith: '.json') ifTrue: [ ^ self contents asDictionary ].
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaFile >> name [
|
|
^ name
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaFile >> name: anObject [
|
|
name := anObject
|
|
]
|