Starting site templates to increase flexibility

and modularity for sites look & feel.
This commit is contained in:
Offray Luna 2017-10-20 16:27:21 +00:00
parent 93b66760e8
commit e7ff603847

View File

@ -7,27 +7,84 @@ Class {
#superclass : #Object, #superclass : #Object,
#instVars : [ #instVars : [
'fossilRepo', 'fossilRepo',
'server' 'server',
'template',
'title'
], ],
#category : #Brea #category : #Brea
} }
{ #category : #utility }
BreaWebsite class >> availableTemplates [
self templates keys.
]
{ #category : #utility } { #category : #utility }
BreaWebsite class >> demoFolder [ BreaWebsite class >> demoFolder [
^ FileLocator temp asFileReference / 'BreaDemo'. ^ FileLocator temp asFileReference / 'BreaDemo'.
] ]
{ #category : #utility } { #category : #example }
BreaWebsite class >> downloadTemplateFiles [ BreaWebsite class >> example [
self downloadTemplateFilesInto: self demoFolder. "I run an example mockup of a website using Brea.
After runing me, go to:
- http://localhost:8080/demo
- http://localhost:8080/members/test
- http://localhost:8080/members/add "
self new
local: FileLocator temp asFileReference / 'BreaDemo';
template: 'portafolio';
downloadTemplate;
modifyTemplate;
start
]
{ #category : #example }
BreaWebsite class >> exampleDashboard [
"I run an example mockup of a website using Brea.
After runing me, go to: http://localhost:8080/demo "
self new
local: FileLocator temp asFileReference / 'BreaDemo';
template: 'dashboard';
downloadTemplate;
modifyTemplate;
start
]
{ #category : #'server handling' }
BreaWebsite class >> stopAll [
"I stop the server"
Teapot stopAll
] ]
{ #category : #utility } { #category : #utility }
BreaWebsite class >> downloadTemplateFilesInto: aDirectory [ BreaWebsite class >> templates [
"I provide the supported MDL templates taken from: https://getmdl.io/templates/"
^ Dictionary new
at: 'portafolio' put: 'https://code.getmdl.io/1.3.0/mdl-template-portfolio.zip';
at: 'dashboard' put: 'https://code.getmdl.io/1.3.0/mdl-template-dashboard.zip';
yourself.
]
{ #category : #utility }
BreaWebsite >> defaultTemplate [
self template
ifNil: [
self template: 'portafolio' ].
^ self template.
]
{ #category : #utility }
BreaWebsite >> downloadDefaultTemplate [
self downloadTemplateNamed: self defaultTemplate Into: self local.
]
{ #category : #utility }
BreaWebsite >> downloadDefaultTemplateInto: aDirectory [
| remoteUrl templatesFile | | remoteUrl templatesFile |
aDirectory ensureDeleteAll. aDirectory ensureDeleteAll.
aDirectory ensureCreateDirectory. aDirectory ensureCreateDirectory.
remoteUrl := 'https://code.getmdl.io/1.3.0/mdl-template-portfolio.zip'. remoteUrl := self class templates at: self template.
GrafoscopioUtils GrafoscopioUtils
downloadingFrom: remoteUrl downloadingFrom: remoteUrl
withMessage: 'Downloading templates' withMessage: 'Downloading templates'
@ -38,38 +95,26 @@ BreaWebsite class >> downloadTemplateFilesInto: aDirectory [
extractAllTo: aDirectory extractAllTo: aDirectory
] ]
{ #category : #example } { #category : #utility }
BreaWebsite class >> example [ BreaWebsite >> downloadTemplate [
"I run an example mockup of a website using Brea. self downloadTemplateNamed: self template Into: self local.
After runing me, go to:
- http://localhost:8080/demo
- http://localhost:8080/members/test
- http://localhost:8080/members/add "
self downloadTemplateFiles.
self replaceDefaultTemplates.
self new
local: FileLocator temp asFileReference / 'BreaDemo';
start
] ]
{ #category : #utility } { #category : #utility }
BreaWebsite class >> replaceDefaultTemplates [ BreaWebsite >> downloadTemplateNamed: aName Into: aDirectory [
"I replace default templates with versioned files, that contains Mustache tags used "aName: String aDirectory: aFileLocation"
for examples." | remoteUrl templatesFile |
| remoteRepoUrl files | aDirectory ensureDeleteAll.
remoteRepoUrl := 'http://mutabit.com/repos.fossil/gig/'. aDirectory ensureCreateDirectory.
files := #('index.html' 'styles.css'). remoteUrl := self class templates at: aName.
files do: [ :file | GrafoscopioUtils
GrafoscopioUtils downloadingFrom: remoteUrl
downloadingFrom: remoteRepoUrl, 'doc/tip/', file withMessage: 'Downloading templates'
withMessage: 'Replacing ', file into: FileLocator temp asFileReference.
into: self demoFolder ] templatesFile := FileLocator temp asFileReference / (remoteUrl splitOn: '/') last.
] ZipArchive new
readFrom: templatesFile;
{ #category : #'server handling' } extractAllTo: aDirectory
BreaWebsite class >> stopAll [
"I stop the server"
Teapot stopAll
] ]
{ #category : #accessing } { #category : #accessing }
@ -106,6 +151,44 @@ BreaWebsite >> local: aFilePath remote: anUrl [
self local: aFilePath self local: aFilePath
] ]
{ #category : #utility }
BreaWebsite >> modifyDashboardTemplate [
"I replace default templates with versioned files, that contains Mustache tags used
for examples."
"This part should be factorized and integrated into a single method tha modifies any
template, instead of repeated the code of modifyPortafolioTemplate."
| remoteRepoUrl files |
remoteRepoUrl := 'http://mutabit.com/repos.fossil/brea/templates/portaforlio'.
files := #('index.html' 'styles.css').
"files do: [ :file |
GrafoscopioUtils
downloadingFrom: remoteRepoUrl, 'doc/tip/', file
withMessage: 'Replacing ', file
into: self local ]"
]
{ #category : #utility }
BreaWebsite >> modifyPortafolioTemplate [
"I replace default templates with versioned files, that contains Mustache tags used
for examples."
| remoteRepoUrl files |
remoteRepoUrl := 'http://mutabit.com/repos.fossil/gig/'.
files := #('index.html' 'styles.css').
files do: [ :file |
GrafoscopioUtils
downloadingFrom: remoteRepoUrl, 'doc/tip/', file
withMessage: 'Replacing ', file
into: self local ]
]
{ #category : #utility }
BreaWebsite >> modifyTemplate [
"I replace default templates with versioned files, that contains Mustache tags used
for examples."
self template = 'portafolio' ifTrue: [ self modifyPortafolioTemplate ].
self template = 'dashboard' ifTrue: [ self modifyDashboardTemplate ]
]
{ #category : #'input processing' } { #category : #'input processing' }
BreaWebsite >> processNewMember: request [ BreaWebsite >> processNewMember: request [
| member badRequest | | member badRequest |
@ -184,3 +267,25 @@ BreaWebsite >> store: anObject [
objects will emerge, I will specialize other ways of storage." objects will emerge, I will specialize other ways of storage."
anObject storeInto: (self storageFor: anObject) anObject storeInto: (self storageFor: anObject)
] ]
{ #category : #accessing }
BreaWebsite >> template [
^ template
]
{ #category : #accessing }
BreaWebsite >> template: aTemplateName [
"I define the default template to be used for the Brea website.
Available options are at self class templates."
template := aTemplateName
]
{ #category : #accessing }
BreaWebsite >> title [
^ title
]
{ #category : #accessing }
BreaWebsite >> title: anObject [
title := anObject
]