From d2f0b7677925b524f72855a612fb05931a290bb4 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Wed, 3 Jul 2024 17:30:49 +0200 Subject: [PATCH 1/3] add a root variable for give the root folder of the blog --- .../MicAbstractBlogCreatorTest.class.st | 3 +- .../MicBlogCreatorTest.class.st | 43 +++++++++---------- .../MicDummyBlogDeployer.class.st | 3 +- .../MicFileTestResources.class.st | 6 +++ .../MicListSummarizerTest.class.st | 6 ++- .../MicMonthListCreatorTest.class.st | 19 ++++++-- .../MicSingleSummarizerTest.class.st | 3 +- .../MicAbstractBlogCreator.class.st | 17 +++++++- src/Microdown-Blog/MicBlogCreator.class.st | 33 +++++++++++++- src/Microdown-Blog/MicListSummarizer.class.st | 1 + .../MicMonthListCreator.class.st | 8 ++-- 11 files changed, 104 insertions(+), 38 deletions(-) diff --git a/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st index 02af29ca..011b7924 100644 --- a/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st @@ -25,7 +25,8 @@ MicAbstractBlogCreatorTest >> setUp [ "Put here a common initialization logic for tests" - abstractBlog := MicAbstractBlogCreator new + abstractBlog := MicAbstractBlogCreator new. + abstractBlog root: MicFileTestResources new genericRootReference ] { #category : 'tests' } diff --git a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st index 0fcefbcc..41cba13a 100644 --- a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st @@ -4,7 +4,8 @@ Class { #instVars : [ 'fileSystem', 'blog', - 'resources' + 'resources', + 'singleSummarizer' ], #category : 'Microdown-Blog-Tests', #package : 'Microdown-Blog-Tests' @@ -44,22 +45,30 @@ MicBlogCreatorTest >> listOfFile [ { #category : 'running' } MicBlogCreatorTest >> setUp [ - | monthList | + | monthList monthListCreator| super setUp. + + "Put here a common initialization logic for tests" + resources := MicFileTestResources new. monthList := { (Month year: 2018 month: 1). (Month year: 2019 month: 1) }. - - "Put here a common initialization logic for tests" - resources := MicFileTestResources new. + monthListCreator := MicMonthListCreator new. + monthListCreator root: resources genericRootReference. + + singleSummarizer := MicSingleSummarizer new. + singleSummarizer targetDirectory: '/'; + root: resources genericRootReference. + self generateArchitecture. blog := MicBlogCreator new. blog targetDirectory: fileSystem / 'html'; sourceDirectory: fileSystem / 'source'; - dateList: (MicMonthListCreator new generateMicListBlockOfLinkDateWith: monthList). + root: resources genericRootReference; + dateList: (monthListCreator generateMicListBlockOfLinkDateWith: monthList). ] { #category : 'tests' } @@ -144,13 +153,10 @@ MicBlogCreatorTest >> testCreateHtmlFileToReplace [ { #category : 'tests' } MicBlogCreatorTest >> testCreateHtmlGroupFileAt [ - | root summarizer singleSummarizer allFileParse | + | root summarizer allFileParse | summarizer := MicListSummarizer new. summarizer targetDirectory: 'html'. - singleSummarizer := MicSingleSummarizer new. - singleSummarizer targetDirectory: blog targetDirectory. - allFileParse := self listOfFile collect: [ :each | singleSummarizer summarizeFile: each ]. @@ -172,6 +178,7 @@ MicBlogCreatorTest >> testCreateHtmlSummarize [ | root summarizer | summarizer := MicListSummarizer new. + summarizer root: resources genericRootReference. summarizer targetDirectory: blog targetDirectory. root := summarizer summarizeFile: self listOfFile. blog createHtmlSummarize: root. @@ -195,17 +202,11 @@ MicBlogCreatorTest >> testInitializeMonthList [ | listSingleSummarizer singleSum1 singleSum2 singleSum3 | listSingleSummarizer := Array new: 3. - singleSum1 := MicSingleSummarizer new targetDirectory: - blog targetDirectory. - singleSum1 := singleSum1 summarizeFile: + singleSum1 := singleSummarizer summarizeFile: fileSystem / 'source' / 'anExample1.md'. - singleSum2 := MicSingleSummarizer new targetDirectory: - blog targetDirectory. - singleSum2 := singleSum2 summarizeFile: + singleSum2 := singleSummarizer summarizeFile: fileSystem / 'source' / 'anExample2.md'. - singleSum3 := MicSingleSummarizer new targetDirectory: - blog targetDirectory. - singleSum3 := singleSum3 summarizeFile: + singleSum3 := singleSummarizer summarizeFile: fileSystem / 'source' / 'test' / 'anExample3.md'. listSingleSummarizer at: 1 put: singleSum1. @@ -243,10 +244,8 @@ MicBlogCreatorTest >> testRootAssembly [ { #category : 'tests' } MicBlogCreatorTest >> testSortSingleSummarizedDocuments [ - | listOfSummarizedDocuments summarized1 summarized2 summarized3 singleSummarizer | + | listOfSummarizedDocuments summarized1 summarized2 summarized3 | listOfSummarizedDocuments := Array new: 3. - singleSummarizer := MicSingleSummarizer new. - singleSummarizer targetDirectory: '/'. summarized1 := singleSummarizer summarize: ((Microdown parse: diff --git a/src/Microdown-Blog-Tests/MicDummyBlogDeployer.class.st b/src/Microdown-Blog-Tests/MicDummyBlogDeployer.class.st index 475b5c6d..af3214cf 100644 --- a/src/Microdown-Blog-Tests/MicDummyBlogDeployer.class.st +++ b/src/Microdown-Blog-Tests/MicDummyBlogDeployer.class.st @@ -38,7 +38,8 @@ MicDummyBlogDeployer >> go [ self deploy. MicBlogCreator createFrom: FileSystem workingDirectory / self sourceFolder - to: self outputDirectory. + to: self outputDirectory + withRoot: 'root'. self launchHTTPServer. 1 seconds wait. self launchBrowser diff --git a/src/Microdown-Blog-Tests/MicFileTestResources.class.st b/src/Microdown-Blog-Tests/MicFileTestResources.class.st index f69e5453..1b0db93a 100644 --- a/src/Microdown-Blog-Tests/MicFileTestResources.class.st +++ b/src/Microdown-Blog-Tests/MicFileTestResources.class.st @@ -265,6 +265,12 @@ When you participate to the mooc you get access to the quizz and the credit vali ^ file ] +{ #category : 'as yet unclassified' } +MicFileTestResources >> genericRootReference [ + + ^ FileReference / '' +] + { #category : 'as yet unclassified' } MicFileTestResources >> workingDirectory [ diff --git a/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st index 93ea1d4b..ed0fc593 100644 --- a/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st +++ b/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st @@ -79,9 +79,11 @@ MicListSummarizerTest >> setUp [ super setUp. resources := MicFileTestResources new. micSummarizer := MicListSummarizer new. - micSummarizer targetDirectory: '/html/' asFileReference. + micSummarizer targetDirectory: '/html/' asFileReference; + root: MicFileTestResources new genericRootReference. singleSummarizer := MicSingleSummarizer new. - singleSummarizer targetDirectory: '/html/' asFileReference. + singleSummarizer targetDirectory: '/html/' asFileReference; + root: MicFileTestResources new genericRootReference. ] { #category : 'tests' } diff --git a/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st b/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st index ddf69e7b..3ba8b685 100644 --- a/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st @@ -1,6 +1,9 @@ Class { #name : 'MicMonthListCreatorTest', #superclass : 'TestCase', + #instVars : [ + 'monthListCreator' + ], #category : 'Microdown-Blog-Tests', #package : 'Microdown-Blog-Tests' } @@ -11,12 +14,22 @@ MicMonthListCreatorTest >> numberOfMonthSince2014 [ ^ Date today year - 2014 * 12 + Date today month index ] +{ #category : 'running' } +MicMonthListCreatorTest >> setUp [ + super setUp. + + "Put here a common initialization logic for tests" + + monthListCreator := MicMonthListCreator new. + monthListCreator root: MicFileTestResources new genericRootReference +] + { #category : 'tests' } MicMonthListCreatorTest >> testGenerateDateListSince2014 [ | dateList | - dateList := MicMonthListCreator new generateDateListSince2014. + dateList := monthListCreator generateDateListSince2014. self assert: dateList size equals: (Date today year - 2014)*12 + Date today month index . self assert: dateList first equals: (Date newDay: 1 month: 1 year: 2014) month . @@ -30,7 +43,7 @@ MicMonthListCreatorTest >> testGenerateMicListBlockOfLinkDate [ fileSystem := FileSystem memory. fileSystem createDirectory: '/html'. - root := MicMonthListCreator new generateMicListBlockOfLinkDate. + root := monthListCreator generateMicListBlockOfLinkDate. self assert: (root isKindOf: MicRootBlock). self @@ -56,7 +69,7 @@ MicMonthListCreatorTest >> testGenerateMicListBlockOfLinkDateWith [ fileSystem := FileSystem memory. fileSystem createDirectory: '/html'. - root := MicMonthListCreator new generateMicListBlockOfLinkDate. + root := monthListCreator generateMicListBlockOfLinkDate. self assert: (root isKindOf: MicRootBlock); diff --git a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st index db775d84..31339395 100644 --- a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st +++ b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st @@ -24,7 +24,8 @@ MicSingleSummarizerTest >> setUp [ super setUp. resources := MicFileTestResources new. micSingleSummarizer := MicSingleSummarizer new. - micSingleSummarizer targetDirectory: '/html/' asFileReference. + micSingleSummarizer targetDirectory: '/html/' asFileReference; + root: resources genericRootReference. ] diff --git a/src/Microdown-Blog/MicAbstractBlogCreator.class.st b/src/Microdown-Blog/MicAbstractBlogCreator.class.st index f03451aa..fca0020c 100644 --- a/src/Microdown-Blog/MicAbstractBlogCreator.class.st +++ b/src/Microdown-Blog/MicAbstractBlogCreator.class.st @@ -2,7 +2,8 @@ Class { #name : 'MicAbstractBlogCreator', #superclass : 'Object', #instVars : [ - 'targetDirectory' + 'targetDirectory', + 'root' ], #category : 'Microdown-Blog', #package : 'Microdown-Blog' @@ -32,7 +33,7 @@ MicAbstractBlogCreator >> makeALink: aText to: aFileReference [ ref := aFileReference asFileReference. ref path isEmpty ifFalse: [ link := ref path fullName ] ]. - ^ (MicInlineParser parse: '[' , text , '](' , link , ')') first + ^ (MicInlineParser parse: '[' , text , '](' , root fullName, link , ')') first ] { #category : 'as yet unclassified' } @@ -41,6 +42,18 @@ MicAbstractBlogCreator >> replacementDate [ ^ '1970/12/25' ] +{ #category : 'accessing' } +MicAbstractBlogCreator >> root [ + + ^ root +] + +{ #category : 'accessing' } +MicAbstractBlogCreator >> root: aFileReferenceOrAString [ + + root := aFileReferenceOrAString asFileReference +] + { #category : 'verifying' } MicAbstractBlogCreator >> setValidDateTo: metadata [ diff --git a/src/Microdown-Blog/MicBlogCreator.class.st b/src/Microdown-Blog/MicBlogCreator.class.st index 9b943066..6fbdd307 100644 --- a/src/Microdown-Blog/MicBlogCreator.class.st +++ b/src/Microdown-Blog/MicBlogCreator.class.st @@ -26,6 +26,7 @@ Class { #instVars : [ 'sourceDirectory', 'targetDirectory', + 'root', 'dateList', 'cssFrameworkName', 'sum' @@ -41,7 +42,20 @@ MicBlogCreator class >> createFrom: sourceReference to: targetReference [ blogCreator := self new. blogCreator sourceDirectory: sourceReference; - targetDirectory: targetReference. + targetDirectory: targetReference; + root: FileReference / ''. + blogCreator createAllHtmlFile +] + +{ #category : 'API' } +MicBlogCreator class >> createFrom: sourceReference to: targetReference withRoot: rootReference [ + + | blogCreator | + blogCreator := self new. + blogCreator + sourceDirectory: sourceReference; + targetDirectory: targetReference; + root: rootReference. blogCreator createAllHtmlFile ] @@ -86,6 +100,7 @@ MicBlogCreator >> createAllHtmlFile [ listOfSingleSummary := allFileParse collect: [ :each | MicSingleSummarizer new targetDirectory: targetDirectory; + root: root; summarize: each ]. self sortSingleSummarizedDocuments: listOfSingleSummary. self initializeMonthList: listOfSingleSummary. @@ -174,6 +189,7 @@ MicBlogCreator >> initializeMonthList: singleSummarizedDocuments [ | summar monthList monthListCreator | monthListCreator := MicMonthListCreator new. + monthListCreator root: root. monthList := monthListCreator createListOfMonthListFromSummarized: singleSummarizedDocuments. @@ -197,6 +213,19 @@ MicBlogCreator >> renameMarkdownIntoHtmlFile: aFileReference [ aFileReference renameTo: newPath ] +{ #category : 'accessing' } +MicBlogCreator >> root [ + + ^ root +] + +{ #category : 'accessing' } +MicBlogCreator >> root: aFileReferenceOrAString [ + + root := aFileReferenceOrAString asFileReference. + sum root: root +] + { #category : 'rendering' } MicBlogCreator >> rootAssembly: aMicRoot [ @@ -248,7 +277,7 @@ MicBlogCreator >> write: aMicHTMLVisitor to: aFileReference [ | htmlDocument cssFramework | cssFramework := MicCSSProvider forCSSNamed: cssFrameworkName. - cssFramework basePath: '/css/'. + cssFramework basePath: root fullName, '/css/'. htmlDocument := MicHTMLDocument new. htmlDocument configuration: aMicHTMLVisitor configuration. diff --git a/src/Microdown-Blog/MicListSummarizer.class.st b/src/Microdown-Blog/MicListSummarizer.class.st index 21c1cae2..5c37be8f 100644 --- a/src/Microdown-Blog/MicListSummarizer.class.st +++ b/src/Microdown-Blog/MicListSummarizer.class.st @@ -73,6 +73,7 @@ MicListSummarizer >> summarizeFile: aListOfFile [ | list singleSummarizer selectionSize | singleSummarizer := MicSingleSummarizer new. singleSummarizer targetDirectory: targetDirectory. + singleSummarizer root: root. list := Array new: aListOfFile size. diff --git a/src/Microdown-Blog/MicMonthListCreator.class.st b/src/Microdown-Blog/MicMonthListCreator.class.st index 07b5ce3a..34bb69d9 100644 --- a/src/Microdown-Blog/MicMonthListCreator.class.st +++ b/src/Microdown-Blog/MicMonthListCreator.class.st @@ -41,8 +41,8 @@ MicMonthListCreator >> generateMicListBlockOfLinkDate [ { #category : 'generate' } MicMonthListCreator >> generateMicListBlockOfLinkDateWith: aMonthList [ - | root link listElement | - root := MicUnorderedListBlock new. + | unorderedList link listElement | + unorderedList := MicUnorderedListBlock new. aMonthList do: [ :each | listElement := MicListItemBlock new. link := self @@ -50,9 +50,9 @@ MicMonthListCreator >> generateMicListBlockOfLinkDateWith: aMonthList [ to: FileReference / '_monthBlog' / (each name , '_' , each year asString , '.html'). link parent: listElement. - listElement parent: root ]. + listElement parent: unorderedList ]. - ^ self generateRootOfMicListBlock: root + ^ self generateRootOfMicListBlock: unorderedList ] { #category : 'generate' } From aefaee587e40236deb27370cab5dd12bdf9c2cef Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Thu, 4 Jul 2024 10:09:37 +0200 Subject: [PATCH 2/3] fix the root path for work in windows and linux --- .../MicAbstractBlogCreatorTest.class.st | 2 +- src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st | 8 ++++---- .../MicFileTestResources.class.st | 7 ++----- .../MicListSummarizerTest.class.st | 4 ++-- .../MicMonthListCreatorTest.class.st | 2 +- .../MicSingleSummarizerTest.class.st | 2 +- src/Microdown-Blog/MicAbstractBlogCreator.class.st | 6 +++--- src/Microdown-Blog/MicBlogCreator.class.st | 12 ++++++------ 8 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st index 011b7924..090d65b0 100644 --- a/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st @@ -26,7 +26,7 @@ MicAbstractBlogCreatorTest >> setUp [ "Put here a common initialization logic for tests" abstractBlog := MicAbstractBlogCreator new. - abstractBlog root: MicFileTestResources new genericRootReference + abstractBlog root: MicFileTestResources new genericRootPath ] { #category : 'tests' } diff --git a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st index 41cba13a..786f4376 100644 --- a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st @@ -56,18 +56,18 @@ MicBlogCreatorTest >> setUp [ (Month year: 2018 month: 1). (Month year: 2019 month: 1) }. monthListCreator := MicMonthListCreator new. - monthListCreator root: resources genericRootReference. + monthListCreator root: resources genericRootPath. singleSummarizer := MicSingleSummarizer new. singleSummarizer targetDirectory: '/'; - root: resources genericRootReference. + root: resources genericRootPath. self generateArchitecture. blog := MicBlogCreator new. blog targetDirectory: fileSystem / 'html'; sourceDirectory: fileSystem / 'source'; - root: resources genericRootReference; + root: resources genericRootPath; dateList: (monthListCreator generateMicListBlockOfLinkDateWith: monthList). ] @@ -178,7 +178,7 @@ MicBlogCreatorTest >> testCreateHtmlSummarize [ | root summarizer | summarizer := MicListSummarizer new. - summarizer root: resources genericRootReference. + summarizer root: resources genericRootPath. summarizer targetDirectory: blog targetDirectory. root := summarizer summarizeFile: self listOfFile. blog createHtmlSummarize: root. diff --git a/src/Microdown-Blog-Tests/MicFileTestResources.class.st b/src/Microdown-Blog-Tests/MicFileTestResources.class.st index 1b0db93a..7905abcc 100644 --- a/src/Microdown-Blog-Tests/MicFileTestResources.class.st +++ b/src/Microdown-Blog-Tests/MicFileTestResources.class.st @@ -1,9 +1,6 @@ Class { #name : 'MicFileTestResources', #superclass : 'Object', - #instVars : [ - 'micSummarizer' - ], #category : 'Microdown-Blog-Tests', #package : 'Microdown-Blog-Tests' } @@ -266,9 +263,9 @@ When you participate to the mooc you get access to the quizz and the credit vali ] { #category : 'as yet unclassified' } -MicFileTestResources >> genericRootReference [ +MicFileTestResources >> genericRootPath [ - ^ FileReference / '' + ^ '' ] { #category : 'as yet unclassified' } diff --git a/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st index ed0fc593..e496935c 100644 --- a/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st +++ b/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st @@ -80,10 +80,10 @@ MicListSummarizerTest >> setUp [ resources := MicFileTestResources new. micSummarizer := MicListSummarizer new. micSummarizer targetDirectory: '/html/' asFileReference; - root: MicFileTestResources new genericRootReference. + root: MicFileTestResources new genericRootPath. singleSummarizer := MicSingleSummarizer new. singleSummarizer targetDirectory: '/html/' asFileReference; - root: MicFileTestResources new genericRootReference. + root: MicFileTestResources new genericRootPath. ] { #category : 'tests' } diff --git a/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st b/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st index 3ba8b685..3d79ed9c 100644 --- a/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st @@ -21,7 +21,7 @@ MicMonthListCreatorTest >> setUp [ "Put here a common initialization logic for tests" monthListCreator := MicMonthListCreator new. - monthListCreator root: MicFileTestResources new genericRootReference + monthListCreator root: MicFileTestResources new genericRootPath ] { #category : 'tests' } diff --git a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st index 31339395..6a18a6ca 100644 --- a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st +++ b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st @@ -25,7 +25,7 @@ MicSingleSummarizerTest >> setUp [ resources := MicFileTestResources new. micSingleSummarizer := MicSingleSummarizer new. micSingleSummarizer targetDirectory: '/html/' asFileReference; - root: resources genericRootReference. + root: resources genericRootPath. ] diff --git a/src/Microdown-Blog/MicAbstractBlogCreator.class.st b/src/Microdown-Blog/MicAbstractBlogCreator.class.st index fca0020c..b2ee262f 100644 --- a/src/Microdown-Blog/MicAbstractBlogCreator.class.st +++ b/src/Microdown-Blog/MicAbstractBlogCreator.class.st @@ -33,7 +33,7 @@ MicAbstractBlogCreator >> makeALink: aText to: aFileReference [ ref := aFileReference asFileReference. ref path isEmpty ifFalse: [ link := ref path fullName ] ]. - ^ (MicInlineParser parse: '[' , text , '](' , root fullName, link , ')') first + ^ (MicInlineParser parse: '[' , text , '](' , root, link , ')') first ] { #category : 'as yet unclassified' } @@ -49,9 +49,9 @@ MicAbstractBlogCreator >> root [ ] { #category : 'accessing' } -MicAbstractBlogCreator >> root: aFileReferenceOrAString [ +MicAbstractBlogCreator >> root: aString [ - root := aFileReferenceOrAString asFileReference + root := aString ] { #category : 'verifying' } diff --git a/src/Microdown-Blog/MicBlogCreator.class.st b/src/Microdown-Blog/MicBlogCreator.class.st index 6fbdd307..549be00d 100644 --- a/src/Microdown-Blog/MicBlogCreator.class.st +++ b/src/Microdown-Blog/MicBlogCreator.class.st @@ -43,19 +43,19 @@ MicBlogCreator class >> createFrom: sourceReference to: targetReference [ blogCreator sourceDirectory: sourceReference; targetDirectory: targetReference; - root: FileReference / ''. + root: ''. blogCreator createAllHtmlFile ] { #category : 'API' } -MicBlogCreator class >> createFrom: sourceReference to: targetReference withRoot: rootReference [ +MicBlogCreator class >> createFrom: sourceReference to: targetReference withRoot: rootPathString [ | blogCreator | blogCreator := self new. blogCreator sourceDirectory: sourceReference; targetDirectory: targetReference; - root: rootReference. + root: rootPathString. blogCreator createAllHtmlFile ] @@ -220,9 +220,9 @@ MicBlogCreator >> root [ ] { #category : 'accessing' } -MicBlogCreator >> root: aFileReferenceOrAString [ +MicBlogCreator >> root: aString [ - root := aFileReferenceOrAString asFileReference. + root := aString. sum root: root ] @@ -277,7 +277,7 @@ MicBlogCreator >> write: aMicHTMLVisitor to: aFileReference [ | htmlDocument cssFramework | cssFramework := MicCSSProvider forCSSNamed: cssFrameworkName. - cssFramework basePath: root fullName, '/css/'. + cssFramework basePath: root, '/css/'. htmlDocument := MicHTMLDocument new. htmlDocument configuration: aMicHTMLVisitor configuration. From 62d0a75d4570e0980e50de0c85f3655d56cc6682 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Thu, 4 Jul 2024 12:07:48 +0200 Subject: [PATCH 3/3] add test for root path in Microdown-Blog --- .../MicAbstractBlogCreatorTest.class.st | 15 +++++- .../MicBlogCreatorTest.class.st | 8 +-- .../MicDummyBlogDeployer.class.st | 3 +- .../MicFileTestResources.class.st | 52 ++++++++++++++++++- .../MicListSummarizerTest.class.st | 22 +++++++- .../MicMonthListCreatorTest.class.st | 34 +++++++++++- .../MicSingleSummarizerTest.class.st | 32 +++++++++++- 7 files changed, 153 insertions(+), 13 deletions(-) diff --git a/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st index 090d65b0..f3916146 100644 --- a/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicAbstractBlogCreatorTest.class.st @@ -26,7 +26,7 @@ MicAbstractBlogCreatorTest >> setUp [ "Put here a common initialization logic for tests" abstractBlog := MicAbstractBlogCreator new. - abstractBlog root: MicFileTestResources new genericRootPath + abstractBlog root: MicFileTestResources new genericEmptyRootPath ] { #category : 'tests' } @@ -62,6 +62,19 @@ MicAbstractBlogCreatorTest >> testMakeALinkToWithNilArguments [ assert: link plainText equals: '[Undefined](Undefined)' ] +{ #category : 'tests' } +MicAbstractBlogCreatorTest >> testMakeALinkToWithRootPath [ + + | link ressources | + ressources := MicFileTestResources new. + abstractBlog root: ressources genericNonEmptyRootPath. + link := abstractBlog makeALink: 'Pharo is cool' to: 'Test' asFileReference. + + self + assert: (link isKindOf: MicLinkBlock); + assert: link plainText equals: '[Pharo is cool](', ressources genericNonEmptyRootPath ,'Test)' +] + { #category : 'tests' } MicAbstractBlogCreatorTest >> testVerifyDateMetadata [ diff --git a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st index 786f4376..4be24f06 100644 --- a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st @@ -56,18 +56,18 @@ MicBlogCreatorTest >> setUp [ (Month year: 2018 month: 1). (Month year: 2019 month: 1) }. monthListCreator := MicMonthListCreator new. - monthListCreator root: resources genericRootPath. + monthListCreator root: resources genericEmptyRootPath. singleSummarizer := MicSingleSummarizer new. singleSummarizer targetDirectory: '/'; - root: resources genericRootPath. + root: resources genericEmptyRootPath. self generateArchitecture. blog := MicBlogCreator new. blog targetDirectory: fileSystem / 'html'; sourceDirectory: fileSystem / 'source'; - root: resources genericRootPath; + root: resources genericEmptyRootPath; dateList: (monthListCreator generateMicListBlockOfLinkDateWith: monthList). ] @@ -178,7 +178,7 @@ MicBlogCreatorTest >> testCreateHtmlSummarize [ | root summarizer | summarizer := MicListSummarizer new. - summarizer root: resources genericRootPath. + summarizer root: resources genericEmptyRootPath. summarizer targetDirectory: blog targetDirectory. root := summarizer summarizeFile: self listOfFile. blog createHtmlSummarize: root. diff --git a/src/Microdown-Blog-Tests/MicDummyBlogDeployer.class.st b/src/Microdown-Blog-Tests/MicDummyBlogDeployer.class.st index af3214cf..475b5c6d 100644 --- a/src/Microdown-Blog-Tests/MicDummyBlogDeployer.class.st +++ b/src/Microdown-Blog-Tests/MicDummyBlogDeployer.class.st @@ -38,8 +38,7 @@ MicDummyBlogDeployer >> go [ self deploy. MicBlogCreator createFrom: FileSystem workingDirectory / self sourceFolder - to: self outputDirectory - withRoot: 'root'. + to: self outputDirectory. self launchHTTPServer. 1 seconds wait. self launchBrowser diff --git a/src/Microdown-Blog-Tests/MicFileTestResources.class.st b/src/Microdown-Blog-Tests/MicFileTestResources.class.st index 7905abcc..a92212f0 100644 --- a/src/Microdown-Blog-Tests/MicFileTestResources.class.st +++ b/src/Microdown-Blog-Tests/MicFileTestResources.class.st @@ -19,6 +19,20 @@ MicFileTestResources >> dumperInput1 [ ^ root ] +{ #category : 'as yet unclassified' } +MicFileTestResources >> dumperInput1WithRootPath [ + + | root | + root := Microdown parse: + '# [A Cool Story](' , '' , self genericNonEmptyRootPath, '/anExample1.html' , '' , ')'. + root children add: (Microdown parse: '2019/01/09') children first. + root children add: (Microdown parse: + 'Pharo is cool but this is a superlong paragraph Simple powerful language: No constructors, no...') + children first. + + ^ root +] + { #category : 'as yet unclassified' } MicFileTestResources >> dumperInput2 [ @@ -34,6 +48,21 @@ MicFileTestResources >> dumperInput2 [ ^ root ] +{ #category : 'as yet unclassified' } +MicFileTestResources >> dumperInput2WithRootPath [ + + | root | + root := Microdown parse: + '# [Pharo is cool](' , '' , self genericNonEmptyRootPath, '/anExample2.html' , '' , ')'. + root children add: + (Microdown parse: '2019/01/22') children first. + root children add: (Microdown parse: + 'If you are either a beginner or an expert in object-oriented programming, this MOOC will...') + children first. + + ^ root +] + { #category : 'as yet unclassified' } MicFileTestResources >> dumperInput3 [ @@ -49,6 +78,21 @@ MicFileTestResources >> dumperInput3 [ ^ root ] +{ #category : 'as yet unclassified' } +MicFileTestResources >> dumperInput3WithRootPath [ + + | root | + root := Microdown parse: + '# [Mooc Pharo](' , '' , self genericNonEmptyRootPath, '/anExample3.html' , '' , ')'. + root children add: + (Microdown parse: '2018/01/29') children first. + root children add: (Microdown parse: + 'Welcome to the Pharo Mooc (a set of videos, exercises, challenges, and miniprojects).') + children first. + + ^ root +] + { #category : 'as yet unclassified' } MicFileTestResources >> fileSystem [ @@ -263,11 +307,17 @@ When you participate to the mooc you get access to the quizz and the credit vali ] { #category : 'as yet unclassified' } -MicFileTestResources >> genericRootPath [ +MicFileTestResources >> genericEmptyRootPath [ ^ '' ] +{ #category : 'as yet unclassified' } +MicFileTestResources >> genericNonEmptyRootPath [ + + ^ 'https://test/' +] + { #category : 'as yet unclassified' } MicFileTestResources >> workingDirectory [ diff --git a/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st index e496935c..caed157e 100644 --- a/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st +++ b/src/Microdown-Blog-Tests/MicListSummarizerTest.class.st @@ -80,10 +80,10 @@ MicListSummarizerTest >> setUp [ resources := MicFileTestResources new. micSummarizer := MicListSummarizer new. micSummarizer targetDirectory: '/html/' asFileReference; - root: MicFileTestResources new genericRootPath. + root: MicFileTestResources new genericEmptyRootPath. singleSummarizer := MicSingleSummarizer new. singleSummarizer targetDirectory: '/html/' asFileReference; - root: MicFileTestResources new genericRootPath. + root: MicFileTestResources new genericEmptyRootPath. ] { #category : 'tests' } @@ -117,6 +117,24 @@ MicListSummarizerTest >> testContentsOfAssembledListsIsCorrect [ self assert: root contents equals: dumper contents ] +{ #category : 'tests' } +MicListSummarizerTest >> testContentsWithRootPath [ + + | root dumper dumper1 dumper2 dumper3 | + singleSummarizer root: resources genericNonEmptyRootPath. + root := MicRealDumper new visit: + (micSummarizer assembleSummarizedDocuments: + self createListOfMicRootBlock). + + dumper1 := MicRealDumper new visit: resources dumperInput1WithRootPath. + dumper2 := MicRealDumper new visit: resources dumperInput2WithRootPath. + dumper3 := MicRealDumper new visit: resources dumperInput3WithRootPath. + + dumper := dumper1 contents , dumper2 contents , dumper3 contents. + + self assert: root contents equals: dumper contents +] + { #category : 'tests' } MicListSummarizerTest >> testGroupByDate [ diff --git a/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st b/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st index 3d79ed9c..7d8dcc95 100644 --- a/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st @@ -2,7 +2,8 @@ Class { #name : 'MicMonthListCreatorTest', #superclass : 'TestCase', #instVars : [ - 'monthListCreator' + 'monthListCreator', + 'ressources' ], #category : 'Microdown-Blog-Tests', #package : 'Microdown-Blog-Tests' @@ -20,8 +21,10 @@ MicMonthListCreatorTest >> setUp [ "Put here a common initialization logic for tests" + ressources := MicFileTestResources new. + monthListCreator := MicMonthListCreator new. - monthListCreator root: MicFileTestResources new genericRootPath + monthListCreator root: MicFileTestResources new genericEmptyRootPath ] { #category : 'tests' } @@ -86,3 +89,30 @@ MicMonthListCreatorTest >> testGenerateMicListBlockOfLinkDateWith [ equals: '[' , Date today month asString , '](/_monthBlog/' , Date today month name , '_' , Date today year asString , '.html)' ] + +{ #category : 'tests' } +MicMonthListCreatorTest >> testGenerateMicListBlockOfLinkDateWithRootPath [ + + | dateList fileSystem root | + fileSystem := FileSystem memory. + fileSystem createDirectory: '/html'. + + monthListCreator root: ressources genericNonEmptyRootPath. + + root := monthListCreator generateMicListBlockOfLinkDate. + + self + assert: (root isKindOf: MicRootBlock); + assert: root children size equals: 2; + assert: (root children first isKindOf: MicHeaderBlock); + assert: (root children second isKindOf: MicUnorderedListBlock). + + dateList := root children second. + self + assert: dateList children size equals: self numberOfMonthSince2014; + assert: dateList children first children first plainText + equals: '[January 2014](', ressources genericNonEmptyRootPath ,'/_monthBlog/January_2014.html)'; + assert: dateList children last children first plainText + equals: '[' , Date today month asString , '](', ressources genericNonEmptyRootPath ,'/_monthBlog/' + , Date today month name , '_' , Date today year asString , '.html)' +] diff --git a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st index 6a18a6ca..85016523 100644 --- a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st +++ b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st @@ -25,7 +25,7 @@ MicSingleSummarizerTest >> setUp [ resources := MicFileTestResources new. micSingleSummarizer := MicSingleSummarizer new. micSingleSummarizer targetDirectory: '/html/' asFileReference; - root: resources genericRootPath. + root: resources genericEmptyRootPath. ] @@ -41,6 +41,20 @@ MicSingleSummarizerTest >> testContents [ self assert: root contents equals: dumper contents ] +{ #category : 'tests' } +MicSingleSummarizerTest >> testContentsWithRootPath [ + + | root dumper | + + micSingleSummarizer root: resources genericNonEmptyRootPath. + root := MicRealDumper new visit: + (micSingleSummarizer summarize: self createMicRootBlock). + + dumper := MicRealDumper new visit: MicFileTestResources new dumperInput1WithRootPath. + + self assert: root contents equals: dumper contents +] + { #category : 'tests' } MicSingleSummarizerTest >> testFirstHeaderBlockOf [ @@ -147,6 +161,22 @@ MicSingleSummarizerTest >> testFirstParagraphBlockOfWithoutEllipsis [ self assert: each parent equals: paragraph ] ] +{ #category : 'tests' } +MicSingleSummarizerTest >> testHeaderLinkWithRootPath [ + + | header linkBlock | + + micSingleSummarizer root: resources genericNonEmptyRootPath. + header := micSingleSummarizer headerLink: self createMicRootBlock. + + self assert: (header isKindOf: MicHeaderBlock). + linkBlock := header children first. + self assert: (linkBlock isKindOf: MicLinkBlock); + assert: linkBlock plainText equals: '[A Cool Story](', resources genericNonEmptyRootPath ,'/anExample1.html)' + + +] + { #category : 'tests' } MicSingleSummarizerTest >> testSummarize [