From e7ff603847233d21906e676d8426845ab8b8b1ea Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Fri, 20 Oct 2017 16:27:21 +0000 Subject: [PATCH] Starting site templates to increase flexibility and modularity for sites look & feel. --- repository/Brea/BreaWebsite.class.st | 175 +++++++++++++++++++++------ 1 file changed, 140 insertions(+), 35 deletions(-) diff --git a/repository/Brea/BreaWebsite.class.st b/repository/Brea/BreaWebsite.class.st index 494cb94..1d9f00d 100644 --- a/repository/Brea/BreaWebsite.class.st +++ b/repository/Brea/BreaWebsite.class.st @@ -7,27 +7,84 @@ Class { #superclass : #Object, #instVars : [ 'fossilRepo', - 'server' + 'server', + 'template', + 'title' ], #category : #Brea } +{ #category : #utility } +BreaWebsite class >> availableTemplates [ + self templates keys. +] + { #category : #utility } BreaWebsite class >> demoFolder [ ^ FileLocator temp asFileReference / 'BreaDemo'. ] -{ #category : #utility } -BreaWebsite class >> downloadTemplateFiles [ - self downloadTemplateFilesInto: self demoFolder. +{ #category : #example } +BreaWebsite class >> example [ + "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 } -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 | aDirectory ensureDeleteAll. aDirectory ensureCreateDirectory. - remoteUrl := 'https://code.getmdl.io/1.3.0/mdl-template-portfolio.zip'. + remoteUrl := self class templates at: self template. GrafoscopioUtils downloadingFrom: remoteUrl withMessage: 'Downloading templates' @@ -38,38 +95,26 @@ BreaWebsite class >> downloadTemplateFilesInto: aDirectory [ extractAllTo: aDirectory ] -{ #category : #example } -BreaWebsite class >> example [ - "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 downloadTemplateFiles. - self replaceDefaultTemplates. - self new - local: FileLocator temp asFileReference / 'BreaDemo'; - start +{ #category : #utility } +BreaWebsite >> downloadTemplate [ + self downloadTemplateNamed: self template Into: self local. ] { #category : #utility } -BreaWebsite class >> replaceDefaultTemplates [ - "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 demoFolder ] -] - -{ #category : #'server handling' } -BreaWebsite class >> stopAll [ - "I stop the server" - Teapot stopAll +BreaWebsite >> downloadTemplateNamed: aName Into: aDirectory [ + "aName: String aDirectory: aFileLocation" + | remoteUrl templatesFile | + aDirectory ensureDeleteAll. + aDirectory ensureCreateDirectory. + remoteUrl := self class templates at: aName. + GrafoscopioUtils + downloadingFrom: remoteUrl + withMessage: 'Downloading templates' + into: FileLocator temp asFileReference. + templatesFile := FileLocator temp asFileReference / (remoteUrl splitOn: '/') last. + ZipArchive new + readFrom: templatesFile; + extractAllTo: aDirectory ] { #category : #accessing } @@ -106,6 +151,44 @@ BreaWebsite >> local: aFilePath remote: anUrl [ 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' } BreaWebsite >> processNewMember: request [ | member badRequest | @@ -184,3 +267,25 @@ BreaWebsite >> store: anObject [ objects will emerge, I will specialize other ways of storage." 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 +]