105 lines
2.1 KiB
Smalltalk
105 lines
2.1 KiB
Smalltalk
Class {
|
|
#name : #BreaApp,
|
|
#superclass : #Object,
|
|
#instVars : [
|
|
'name',
|
|
'folder',
|
|
'host',
|
|
'componets'
|
|
],
|
|
#category : #Brea
|
|
}
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> add: anObject [
|
|
anObject class = String ifFalse: [ ].
|
|
self body
|
|
nextPutAll: (Pandoc htmlStringToMarkdown: anObject); cr.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> appName [
|
|
^ self name asCamelCase
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> at: key put: anObject [
|
|
self components at: key put: anObject.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> components [
|
|
^ componets ifNil: [ componets := OrderedDictionary new]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> componentsWebView [
|
|
| response |
|
|
response := '' writeStream.
|
|
self components ifEmpty: [ ^ response contents ].
|
|
self components valuesDo: [ :component |
|
|
response
|
|
nextPutAll: component webView; cr
|
|
].
|
|
^ response contents
|
|
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> defaultView [
|
|
^ '<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="color-scheme" content="light dark" />
|
|
<link rel="stylesheet" href="css/pico.min.css">
|
|
<title>', self name, '</title>
|
|
</head>
|
|
<body>
|
|
<main class="container">
|
|
', self componentsWebView,'
|
|
</main>
|
|
</body>
|
|
</html>'
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> folder [
|
|
^ folder
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> folder: aFileDirectory [
|
|
folder := aFileDirectory
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> name [
|
|
^ name
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> name: aString [
|
|
name := aString
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> parentFolder: anObject [
|
|
self folder: anObject / self name asCamelCase
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> preview [
|
|
| defaultRoute |
|
|
defaultRoute := 'http://localhost:',self webHost server port asString, '/', self appName.
|
|
self webHost
|
|
GET: self appName -> [ self defaultView ].
|
|
GoogleChrome openWindowOn: defaultRoute
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
BreaApp >> webHost [
|
|
^ host ifNil: [ host := Teapot allInstances detect: [ :each | each server isRunning ] ifNone: [ host := Teapot on. host server start ]]
|
|
]
|