Skip to content

Commit

Permalink
Merge pull request #749 from moufort/webDeveloppemment
Browse files Browse the repository at this point in the history
Change architecture of target directory
  • Loading branch information
Ducasse authored May 24, 2024
2 parents b901bb4 + 76a0cc7 commit 7d035b9
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 43 deletions.
72 changes: 54 additions & 18 deletions src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@ MicBlogCreatorTest >> generateArchitecture [
ref2 writeStreamDo: [ :stream | stream nextPutAll: self fileContent2 ].

ref3 := fileSystem workingDirectory / 'source/anExample3.md'.
ref3 writeStreamDo: [ :stream | stream nextPutAll: self fileContent3 ].

ref3 writeStreamDo: [ :stream | stream nextPutAll: self fileContent3 ]
]

{ #category : 'as yet unclassified' }
MicBlogCreatorTest >> listOfFile [
MicBlogCreatorTest >> listOfFile [

^ (fileSystem / 'source') allChildren select: [ :each | each isFile ]
^ (fileSystem / 'source') allFiles
]

{ #category : 'running' }
Expand All @@ -102,7 +101,7 @@ MicBlogCreatorTest >> testCollectAllMarkDownFile [

| fileList |

fileList := blog collectAllMarkDownFile.
fileList := blog collectAllMarkDownFile: blog sourceDirectory.

self assert: fileList size equals: 3
]
Expand All @@ -119,26 +118,25 @@ MicBlogCreatorTest >> testCopySourceDirectoryInTarget [
MicBlogCreatorTest >> testCreateAllHtmlFile [

| allFile |

blog createAllHtmlFile.

allFile := (fileSystem / 'html') allChildren select: [ :each |
each isFile ].
allFile := (fileSystem / 'html') allFiles.

self assert: allFile size equals: 6
]

{ #category : 'tests' }
MicBlogCreatorTest >> testCreateHtmlFile [

| root |
root := Microdown parse:
(fileSystem / 'source/anExample1.md') readStream.
blog
createHtmlFile: root.
MicBlogCreatorTest >> testCreateHtmlFileToReplace [

self assert:
(fileSystem / 'html/2019/January/8/A Cool Story.html') exists
| root file |

file := self listOfFile at: 1 .

root := Microdown parse: file contents.

MicBlogCreator new createHtmlFile: root toReplace: file.

self assert: file basename equals: 'anExample1.html'
]

{ #category : 'tests' }
Expand All @@ -159,7 +157,7 @@ MicBlogCreatorTest >> testCreateHtmlGroupFileAt [
blog
createHtmlGroupFile: root at: (Month year: 2019 month: 'January').

self assert: (fileSystem / 'html/2019/January/index.html') exists
self assert: (fileSystem / 'html/_monthBlog/January 2019.html') exists
]

{ #category : 'tests' }
Expand All @@ -173,3 +171,41 @@ MicBlogCreatorTest >> testCreateHtmlSummarize [

self assert: (fileSystem / 'html/index.html') exists
]

{ #category : 'tests' }
MicBlogCreatorTest >> testRenameMarkdownIntoHtmlFile [

| fileRef |
fileRef := MicBlogCreator new renameMarkdownIntoHtmlFile:
fileSystem / 'source/anExample1.md'.

self assert: (fileSystem / 'source/anExample1.html') exists.
self assert: (fileSystem / 'source/anExample1.md') exists not
]

{ #category : 'tests' }
MicBlogCreatorTest >> testRootAssembly [

| root file |

file := self listOfFile at: 1.
root := Microdown parse: file contents.

MicBlogCreator new rootAssembly: root.

self assert: root children size equals: 5
]

{ #category : 'tests' }
MicBlogCreatorTest >> testWriteToNamed [

| root file html|

file := self listOfFile at: 1.
root := Microdown parse: file contents.
html := (MicHTMLVisitor new visit: root) at: 1.

MicBlogCreator new write: html to: fileSystem / 'html' named: 'test.html'.

self assert: (fileSystem / 'html/test.html') exists
]
64 changes: 39 additions & 25 deletions src/Microdown-Blog/MicBlogCreator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ MicBlogCreator class >> createFrom: source to: target [
]

{ #category : 'as yet unclassified' }
MicBlogCreator >> collectAllMarkDownFile [
MicBlogCreator >> collectAllMarkDownFile: aFileReference [

^ sourceDirectory allFiles select: [ :each |
^ aFileReference allFiles select: [ :each |
each fullName endsWith: '.md' ]
]

Expand All @@ -46,17 +46,26 @@ MicBlogCreator >> copySourceDirectoryInTarget [
MicBlogCreator >> createAllHtmlFile [

| allFile allFileParse sum summar |
allFile := self collectAllMarkDownFile.
self copySourceDirectoryInTarget.
allFile := self collectAllMarkDownFile: targetDirectory.
allFileParse := allFile collect: [ :each |
Microdown parse: each asFileReference contents ].

allFileParse do: [ :each | self createHtmlFile: each ].
1 to: allFile size do: [ :index |
self
createHtmlFile: (allFileParse at: index)
toReplace: (allFile at: index) ].



sum := MicSummarizer new.
sum targetDirectory: targetDirectory.

self createHtmlSummarize: (sum summarizeFile: allFile).

"JUSQUE LA CA MARCHE"
targetDirectory fileSystem createDirectory: '/html/_monthBlog'.

MicMonthListCreator new generateDateListSince2014 do: [ :each |
summar := sum group: allFileParse byDate: each.
summar isNotEmpty ifTrue: [
Expand All @@ -65,52 +74,57 @@ MicBlogCreator >> createAllHtmlFile [
]

{ #category : 'rendering' }
MicBlogCreator >> createHtmlFile: aMicRoot [
MicBlogCreator >> createHtmlFile: aMicRoot toReplace: aFileReference [

| a q date header fileRef |
| html |
self rootAssembly: aMicRoot.
html := (MicHTMLVisitor new visit: aMicRoot) at: 1.

self renameMarkdownIntoHtmlFile: aFileReference.

a := (MicHTMLVisitor new visit: aMicRoot) at: 1.

date := (aMicRoot children at: 1) body at: #date.
date := date asDate.
header := MicSingleSummarizer new firstHeaderBlockOf: aMicRoot.

fileRef := targetDirectory copyWithPath:
targetDirectory fullPath asUrl path , '/'
, date year asString , '/' , date monthName , '/'
, date day asString , '/'.
aFileReference delete.

self write: a to: fileRef named: header text .
self
write: html
to: aFileReference parent
named: (aFileReference fullName substrings: '/') last
]

{ #category : 'rendering' }
MicBlogCreator >> createHtmlGroupFile: aMicRoot at: aDate [

| a q fileRef |
| a fileRef |
self rootAssembly: aMicRoot.

a := (MicHTMLVisitor new visit: aMicRoot) at: 1.

fileRef := targetDirectory copyWithPath:
targetDirectory fullPath asUrl path , '/'
, aDate year asString , '/' , aDate monthName , '/'.
fileRef := targetDirectory / '_monthBlog'.

self write: a to: fileRef named: 'index' .
self write: a to: fileRef named: aDate asString,'.html'
]

{ #category : 'rendering' }
MicBlogCreator >> createHtmlSummarize: aMicRoot [

| a q fileRef |
| a fileRef |
self rootAssembly: aMicRoot.

a := (MicHTMLVisitor new visit: aMicRoot) at: 1.

fileRef := targetDirectory copyWithPath:
targetDirectory fullPath asUrl path.

self write: a to: fileRef named: 'index' .
self write: a to: fileRef named: 'index.html'
]

{ #category : 'rendering' }
MicBlogCreator >> renameMarkdownIntoHtmlFile: aFileReference [

| newPath |

newPath := aFileReference fullName copyReplaceAll: '.md' with: '.html'.

aFileReference renameTo: newPath
]

{ #category : 'as yet unclassified' }
Expand Down Expand Up @@ -158,7 +172,7 @@ MicBlogCreator >> write: aMicHTMLVisitor to: aPath named: aName [
setCharSetUTF8;
destinationPath: aPath.
^ htmlDocument
fileName: aName , '.html';
fileName: aName;
writeDocument: aMicHTMLVisitor contents;
contents
]

0 comments on commit 7d035b9

Please sign in to comment.