Skip to content

Commit

Permalink
refactoring Microdown Blog
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin.moutte.etu committed Jun 21, 2024
1 parent 1b78cd2 commit 2a39043
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 85 deletions.
15 changes: 0 additions & 15 deletions src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,6 @@ MicBlogCreatorTest >> testCreateFromTo [
self assert: allFile size equals: 8
]

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

| file |

blog
createHtmlEmptyGroupFileAt: (Month year: 2019 month: 'January').

file := fileSystem / 'html/_monthBlog/January_2019.html'.

self assert:
file exists;
assert: (file contents findString: 'No files found') = 0 equals: false.
]

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

Expand Down
4 changes: 3 additions & 1 deletion src/Microdown-Blog/MicAbstractBlogCreator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ Class {
#package : 'Microdown-Blog'
}

{ #category : 'as yet unclassified' }
{ #category : 'make' }
MicAbstractBlogCreator >> makeALink: aText to: aLink [

| text link |

(aText isNil or: aText isEmpty)
ifTrue: [ text := 'Undefined' ]
ifFalse: [ text := aText ].

(aLink isNil or: aLink isEmpty)
ifTrue: [ link := 'Undefined' ]
ifFalse: [ link := aLink ].
Expand Down
130 changes: 69 additions & 61 deletions src/Microdown-Blog/MicBlogCreator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Class {
'sourceDirectory',
'targetDirectory',
'dateList',
'cssFrameworkName'
'cssFrameworkName',
'sum'
],
#category : 'Microdown-Blog',
#package : 'Microdown-Blog'
Expand All @@ -35,13 +36,25 @@ MicBlogCreator class >> createFrom: source to: target [
tmp1 createAllHtmlFile
]

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

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

{ #category : 'collect' }
MicBlogCreator >> collectAndParseAllMarkdownFile [

| allFile allFileParse |

allFile := self collectAllMarkDownFile: targetDirectory.
allFileParse := allFile collect: [ :each |
(Microdown parse: each asFileReference contents)
fromFile: each ].
^ allFileParse
]

{ #category : 'copying' }
MicBlogCreator >> copySourceDirectoryInTarget [

Expand All @@ -53,90 +66,71 @@ MicBlogCreator >> copySourceDirectoryInTarget [
{ #category : 'rendering' }
MicBlogCreator >> createAllHtmlFile [

| allFile allFileParse sum listOfSingleSummarize |
"Copy the source directory in the target directory"
| allFileParse |

self copySourceDirectoryInTarget.

self downloadCSS.

"Collect and parse all Markdown file of targetDirectory"
allFile := self collectAllMarkDownFile: targetDirectory.
allFileParse := allFile collect: [ :each |
(Microdown parse: each asFileReference contents)
fromFile: each ].
allFileParse := self collectAndParseAllMarkdownFile.

"Create _monthListBlog"
self initializeMonthList: allFileParse.

"transform all markdown file into html file"
allFileParse do: [ :each |
self createHtmlFile: each toReplace: each fromFile ].

self generateMainSummary: allFileParse.

"create summarizer html file"
sum := MicSummarizer new.
sum targetDirectory: targetDirectory.

listOfSingleSummarize := allFileParse collect: [ :each |
MicSingleSummarizer new summarize: each ].

self createHtmlSummarize: (sum summarize: listOfSingleSummarize)
]

{ #category : 'rendering' }
MicBlogCreator >> createHtmlEmptyGroupFileAt: aMonth [

| a fileRef root |
root := Microdown parse: 'No files found'.
self rootAssembly: root.

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

fileRef := targetDirectory / '_monthBlog'.

self write: a to: fileRef named: aMonth name , '_' , aMonth year asString , '.html'

]

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

| html |
| visitor |
self rootAssembly: aMicRoot.
html := (MicHTMLVisitor new visit: aMicRoot) first.

visitor := (MicHTMLVisitor new visit: aMicRoot) first.

self renameMarkdownIntoHtmlFile: aFileReference.

aFileReference delete.
self
write: html
to: targetDirectory

self
write: visitor
to: targetDirectory
named:
(aFileReference fullName withoutPrefix:
self targetDirectory fullName)
self targetDirectory fullName)
]

{ #category : 'rendering' }
MicBlogCreator >> createHtmlGroupFile: arg1 at: arg2 [
MicBlogCreator >> createHtmlGroupFile: aMicRoot at: aMonth [

| tmp1 tmp2 |
self rootAssembly: arg1.
tmp1 := (MicHTMLVisitor new visit: arg1) at: 1.
tmp2 := targetDirectory / '_monthBlog'.
| visitor fileRef |
self rootAssembly: aMicRoot.
visitor := (MicHTMLVisitor new visit: aMicRoot) first.
fileRef := targetDirectory / '_monthBlog'.
self
write: tmp1
to: tmp2
named: arg2 name , '_' , arg2 year asString , '.html'
write: visitor
to: fileRef
named: aMonth name , '_' , aMonth year asString , '.html'
]

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

| a |
| visitor |
self rootAssembly: aMicRoot.

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

self write: a to: targetDirectory named: 'index.html'
self write: visitor to: targetDirectory named: 'index.html'
]

{ #category : 'as yet unclassified' }
{ #category : 'accessing' }
MicBlogCreator >> cssFrameworkName: aString [

cssFrameworkName := aString
Expand All @@ -161,19 +155,29 @@ MicBlogCreator >> downloadCSS [
(MicCSSProvider forCSSNamed: cssFrameworkName)
]

{ #category : 'rendering' }
MicBlogCreator >> generateMainSummary: allFileParse [

| listOfSingleSummary |

listOfSingleSummary := allFileParse collect: [ :each |
MicSingleSummarizer new summarize: each ].

self createHtmlSummarize: (sum summarize: listOfSingleSummary)
]

{ #category : 'initialization' }
MicBlogCreator >> initialize [

super initialize.
self cssFrameworkName: 'Axist'.
sum := MicSummarizer new.
]

{ #category : 'rendering' }
MicBlogCreator >> initializeMonthList: listOfSingleSummarize [

| summar sum date |
sum := MicSummarizer new.
sum targetDirectory: targetDirectory.
| summar date |

dateList := MicMonthListCreator new generateDateListSince2014.
date := dateList copy.
Expand All @@ -194,18 +198,20 @@ MicBlogCreator >> initializeMonthList: listOfSingleSummarize [
self createHtmlGroupFile: summar at: each ]
]

{ #category : 'as yet unclassified' }
{ #category : 'css' }
MicBlogCreator >> levelPathDifferenceForCSS: aStringPath [

| result string |
string := aStringPath copyReplaceAll: '\' with: '/'.

result := ''.
result := '' writeStream.

2 to: (string substrings: '/') size do: [ :each |
result := result , '../' ].
result nextPutAll: '../' ].

result close.

^ result
^ result contents
]

{ #category : 'rendering' }
Expand All @@ -218,7 +224,7 @@ MicBlogCreator >> renameMarkdownIntoHtmlFile: aFileReference [
aFileReference renameTo: newPath
]

{ #category : 'as yet unclassified' }
{ #category : 'rendering' }
MicBlogCreator >> rootAssembly: aMicRoot [

aMicRoot addChild: dateList copy.
Expand All @@ -232,9 +238,9 @@ MicBlogCreator >> sourceDirectory [
]

{ #category : 'accessing' }
MicBlogCreator >> sourceDirectory: arg1 [
MicBlogCreator >> sourceDirectory: aFileReference [

sourceDirectory := arg1
sourceDirectory := aFileReference
]

{ #category : 'accessing' }
Expand All @@ -244,9 +250,11 @@ MicBlogCreator >> targetDirectory [
]

{ #category : 'accessing' }
MicBlogCreator >> targetDirectory: arg1 [
MicBlogCreator >> targetDirectory: aFileReference [

targetDirectory := aFileReference.

targetDirectory := arg1
sum targetDirectory: targetDirectory
]

{ #category : 'rendering' }
Expand Down
12 changes: 6 additions & 6 deletions src/Microdown-Blog/MicSingleSummarizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ MicSingleSummarizer >> summarize: aMicRootBlock [
{ #category : 'parsing' }
MicSingleSummarizer >> summarizeFile: aFileReference [

| p |
p := Microdown parse: aFileReference asFileReference contents.
p fromFile: aFileReference.
^ self summarize: p
| root |
root := Microdown parse: aFileReference asFileReference contents.
root fromFile: aFileReference.
^ self summarize: root
]

{ #category : 'as yet unclassified' }
{ #category : 'verifying' }
MicSingleSummarizer >> verifyDateMetadata: aMicRootBlock [

| newMicRootBlock metadata |
newMicRootBlock := MicRootBlock new.

((aMicRootBlock children at: 1) isKindOf: MicMetaDataBlock)
(aMicRootBlock children first isKindOf: MicMetaDataBlock)
ifFalse: [
metadata := MicMetaDataBlock new.
metadata body:
Expand Down
4 changes: 2 additions & 2 deletions src/Microdown-Blog/MicSummarizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ MicSummarizer >> maximumFile: aNumber [
maximumFile := aNumber
]

{ #category : 'as yet unclassified' }
{ #category : 'summarize' }
MicSummarizer >> summarize: aListOfSingleSummarizer [

| summarize root selectionSize |
Expand All @@ -53,7 +53,7 @@ MicSummarizer >> summarize: aListOfSingleSummarizer [
^ summarize
]

{ #category : 'as yet unclassified' }
{ #category : 'summarize' }
MicSummarizer >> summarizeFile: aListOfFile [

| list singleSummarizer selectionSize |
Expand Down

0 comments on commit 2a39043

Please sign in to comment.