diff --git a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st
index 143c7b48..b4ad04a0 100644
--- a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st
+++ b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st
@@ -1,6 +1,9 @@
Class {
#name : 'MicSingleSummarizerTest',
#superclass : 'TestCase',
+ #instVars : [
+ 'micSingleSummarizer'
+ ],
#category : 'Microdown-Blog-Tests',
#package : 'Microdown-Blog-Tests'
}
@@ -16,7 +19,11 @@ MicSingleSummarizerTest >> generateFilesystemExample [
| file |
file := FileSystem memory workingDirectory / 'anExample1.md'.
- file writeStreamDo: [ :stream | stream nextPutAll: '# A Cool Story
+ file writeStreamDo: [ :stream |
+ stream nextPutAll: '{
+ "date" : "8 January 2019"
+}
+# A Cool Story
@sec1
Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no types declaration, no interfaces, no primitive types. Yet a powerful and elegant language with a full syntax fitting in one postcard! Pharo is objects and messages all the way down. _Live_, immersive environment: Immediate feedback at any moment of your development: _Developing_, testing, debugging. Even in production environments, you will never be stuck in compiling and deploying steps again!
@@ -32,7 +39,7 @@ this is a code blu blu
```
' ].
- ^ file.
+ ^ file
]
{ #category : 'enumerating' }
@@ -46,6 +53,69 @@ MicSingleSummarizerTest >> generateFilesystemExampleEmpty [
^ file
]
+{ #category : 'enumerating' }
+MicSingleSummarizerTest >> generateFilesystemExampleWithoutDateInMetadata [
+
+ | file |
+ file := FileSystem memory workingDirectory / 'anExample1.md'.
+ file writeStreamDo: [ :stream |
+ stream nextPutAll: '{
+ "title" : "Cool"
+}
+# A Cool Story
+@sec1
+
+Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no types declaration, no interfaces, no primitive types. Yet a powerful and elegant language with a full syntax fitting in one postcard! Pharo is objects and messages all the way down. _Live_, immersive environment: Immediate feedback at any moment of your development: _Developing_, testing, debugging. Even in production environments, you will never be stuck in compiling and deploying steps again!
+
+
+Amazing debugging experience: The Pharo environment includes a debugger unlike anything you''ve seen before. It allows you to step through code, restart the execution of methods, create methods on the fly, and much more!
+
+Pharo is yours: Pharo is made by an incredible community, with more than 100 contributors for the last revision of the platform and hundreds of people contributing constantly with frameworks and libraries. Fully open-source: Pharo full stack is released under MIT License and available on GitHub
+
+
+```
+this is a code blu blu
+```
+' ].
+
+ ^ file
+]
+
+{ #category : 'enumerating' }
+MicSingleSummarizerTest >> generateFilesystemExampleWithoutMetadata [
+
+ | file |
+ file := FileSystem memory workingDirectory / 'anExample1.md'.
+ file writeStreamDo: [ :stream |
+ stream nextPutAll: '# A Cool Story
+@sec1
+
+Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no types declaration, no interfaces, no primitive types. Yet a powerful and elegant language with a full syntax fitting in one postcard! Pharo is objects and messages all the way down. _Live_, immersive environment: Immediate feedback at any moment of your development: _Developing_, testing, debugging. Even in production environments, you will never be stuck in compiling and deploying steps again!
+
+
+Amazing debugging experience: The Pharo environment includes a debugger unlike anything you''ve seen before. It allows you to step through code, restart the execution of methods, create methods on the fly, and much more!
+
+Pharo is yours: Pharo is made by an incredible community, with more than 100 contributors for the last revision of the platform and hundreds of people contributing constantly with frameworks and libraries. Fully open-source: Pharo full stack is released under MIT License and available on GitHub
+
+
+```
+this is a code blu blu
+```
+' ].
+
+ ^ file
+]
+
+{ #category : 'running' }
+MicSingleSummarizerTest >> setUp [
+
+ super setUp.
+
+ "Put here a common initialization logic for tests"
+ micSingleSummarizer := MicSingleSummarizer new.
+ micSingleSummarizer targetDirectory: '/html/'
+]
+
{ #category : 'tests' }
MicSingleSummarizerTest >> testFirstHeaderBlockOf [
@@ -63,7 +133,10 @@ MicSingleSummarizerTest >> testFirstHeaderBlockOf [
MicSingleSummarizerTest >> testFirstHeaderBlockOfWithNoHeader [
| header |
- header := MicSingleSummarizer new firstHeaderBlockOf:(Microdown parse: self generateFilesystemExampleEmpty asFileReference contents).
+ header := micSingleSummarizer firstHeaderBlockOf:
+ (Microdown parse:
+ self generateFilesystemExampleEmpty asFileReference
+ contents).
self assert: (header isKindOf: MicHeaderBlock).
self assert: header text equals: 'Please define a header'.
@@ -79,7 +152,7 @@ MicSingleSummarizerTest >> testFirstHeaderBlockOfWithNoHeader [
MicSingleSummarizerTest >> testFirstParagraphBlockOf [
| paragraph |
- paragraph := MicSingleSummarizer new
+ paragraph := micSingleSummarizer
maximumWords: 3;
firstParagraphBlockOf: self createMicRootBlock.
self assert: (paragraph isKindOf: MicParagraphBlock).
@@ -97,7 +170,7 @@ MicSingleSummarizerTest >> testFirstParagraphBlockOf [
MicSingleSummarizerTest >> testFirstParagraphBlockOfWithEllipsis [
| paragraph |
- paragraph := MicSingleSummarizer new
+ paragraph := micSingleSummarizer
maximumWords: 3;
firstParagraphBlockOf: self createMicRootBlock.
self assert: (paragraph isKindOf: MicParagraphBlock).
@@ -115,7 +188,7 @@ MicSingleSummarizerTest >> testFirstParagraphBlockOfWithEllipsis [
MicSingleSummarizerTest >> testFirstParagraphBlockOfWithNoParagraph [
| paragraph |
- paragraph := MicSingleSummarizer new
+ paragraph := micSingleSummarizer
maximumWords: 3;
firstParagraphBlockOf: (Microdown parse:
self generateFilesystemExampleEmpty asFileReference
@@ -135,7 +208,7 @@ MicSingleSummarizerTest >> testFirstParagraphBlockOfWithNoParagraph [
MicSingleSummarizerTest >> testFirstParagraphBlockOfWithoutEllipsis [
| paragraph |
- paragraph := MicSingleSummarizer new
+ paragraph := micSingleSummarizer
maximumWords: 5;
firstParagraphBlockOf:
(Microdown parse: 'Pharo is cool').
@@ -154,17 +227,55 @@ MicSingleSummarizerTest >> testFirstParagraphBlockOfWithoutEllipsis [
MicSingleSummarizerTest >> testSummarize [
| root |
- root := MicSingleSummarizer new summarize: self createMicRootBlock.
- self assert: (root isKindOf: MicRootBlock);
- assert: (root children size) equals: 3.
+ root := micSingleSummarizer summarize: self createMicRootBlock.
+ self
+ assert: (root isKindOf: MicRootBlock);
+ assert: root children size equals: 3
]
{ #category : 'tests' }
MicSingleSummarizerTest >> testSummarizeFile [
| root |
- root := MicSingleSummarizer new summarizeFile: self generateFilesystemExample.
+ root := micSingleSummarizer summarizeFile:
+ self generateFilesystemExample.
self assert: (root isKindOf: MicRootBlock)
-
-
+]
+
+{ #category : 'tests' }
+MicSingleSummarizerTest >> testWithMetaDataAndWithDate [
+
+ | root |
+ root := micSingleSummarizer summarize: self createMicRootBlock.
+ self
+ assert: (root isKindOf: MicRootBlock);
+ assert: root children size equals: 3;
+ assert: ((root children at:1) body at: #date ) equals: '8 January 2019'.
+]
+
+{ #category : 'tests' }
+MicSingleSummarizerTest >> testWithMetaDataAndWithoutDate [
+
+ | root |
+ root := micSingleSummarizer summarize:
+ (Microdown parse:
+ self generateFilesystemExampleWithoutDateInMetadata).
+ self
+ assert: (root isKindOf: MicRootBlock);
+ assert: root children size equals: 3;
+ assert: ((root children at: 1) body at: #date)
+ equals: '25 December 1970'
+]
+
+{ #category : 'tests' }
+MicSingleSummarizerTest >> testWithoutMetaData [
+
+ | root |
+ root := micSingleSummarizer summarize: (Microdown parse:
+ self generateFilesystemExampleWithoutMetadata ).
+ self
+ assert: (root isKindOf: MicRootBlock);
+ assert: root children size equals: 3;
+ assert: ((root children at: 1) body at: #date)
+ equals: '25 December 1970'
]
diff --git a/src/Microdown-Blog-Tests/MicSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicSummarizerTest.class.st
index 3cf026af..8d64efa8 100644
--- a/src/Microdown-Blog-Tests/MicSummarizerTest.class.st
+++ b/src/Microdown-Blog-Tests/MicSummarizerTest.class.st
@@ -1,6 +1,9 @@
Class {
#name : 'MicSummarizerTest',
#superclass : 'TestCase',
+ #instVars : [
+ 'micSummarizer'
+ ],
#category : 'Microdown-Blog-Tests',
#package : 'Microdown-Blog-Tests'
}
@@ -22,6 +25,7 @@ MicSummarizerTest >> createListOfMicRootBlock [
| q singleSummarizer |
q := Array new: 3.
singleSummarizer := MicSingleSummarizer new.
+ singleSummarizer targetDirectory: '/html/'.
q
at: 1 put: (singleSummarizer summarize: (Microdown parse:
self generateFilesystemExample1 asFileReference contents));
@@ -94,151 +98,14 @@ When you participate to the mooc you get access to the quizz and the credit vali
^ file
]
-{ #category : 'as yet unclassified' }
-MicSummarizerTest >> htmlBodyTest [
+{ #category : 'running' }
+MicSummarizerTest >> setUp [
- ^ '
-
-Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no ...
-
-If you are either a beginner or an expert in object-oriented programming, _this MOOC_ will ...
-
-Welcome to the Pharo Mooc (a set of videos, exercises, challenges, and miniprojects).
-'
+ super setUp.
+ "Put here a common initialization logic for tests"
+ micSummarizer := MicSummarizer new.
+ micSummarizer targetDirectory: '/html/'
]
{ #category : 'tests' }
@@ -246,16 +113,18 @@ MicSummarizerTest >> testGroupByDate [
| summary group |
summary := self createListOfMicRootBlock.
- group := MicSummarizer new group: summary byDate: (Date newDay: 1 month: 'January' year: 2019).
-
- self assert: group size equals: 2.
+ group := micSummarizer
+ group: summary
+ byDate: (Date newDay: 1 month: 'January' year: 2019).
+
+ self assert: group size equals: 2
]
{ #category : 'tests' }
MicSummarizerTest >> testSummarize [
| summary |
- summary := MicSummarizer new summarize: self createListOfMicRootBlock.
+ summary := micSummarizer summarize: self createListOfMicRootBlock.
self
assert: (summary isKindOf: MicRootBlock);
assert: summary children size equals: 6
@@ -265,7 +134,7 @@ MicSummarizerTest >> testSummarize [
MicSummarizerTest >> testSummarizeFile [
| summary |
- summary := MicSummarizer new summarizeFile: self createListOfFile.
+ summary := micSummarizer summarizeFile: self createListOfFile.
self
assert: (summary isKindOf: MicRootBlock);
assert: summary children size equals: 6
diff --git a/src/Microdown-Blog/MicBlogCreator.class.st b/src/Microdown-Blog/MicBlogCreator.class.st
new file mode 100644
index 00000000..2d302854
--- /dev/null
+++ b/src/Microdown-Blog/MicBlogCreator.class.st
@@ -0,0 +1,151 @@
+Class {
+ #name : 'MicBlogCreator',
+ #superclass : 'Object',
+ #instVars : [
+ 'sourceDirectory',
+ 'targetDirectory'
+ ],
+ #category : 'Microdown-Blog',
+ #package : 'Microdown-Blog'
+}
+
+{ #category : 'as yet unclassified' }
+MicBlogCreator class >> createFrom: source to: target [
+
+ | tmp1 |
+ tmp1 := self new.
+ tmp1
+ sourceDirectory: source;
+ targetDirectory: target.
+ tmp1 createAllHtmlFile.
+]
+
+{ #category : 'as yet unclassified' }
+MicBlogCreator >> collectAllFile [
+
+ ^ (FileReference / sourceDirectory) allChildren select: [ :each | each isFile ]
+]
+
+{ #category : 'rendering' }
+MicBlogCreator >> createAllHtmlFile [
+
+ | allFile allFileParse sum summar |
+ allFile := self collectAllFile.
+ allFileParse := allFile collect: [ :each |
+ Microdown parse: each asFileReference contents ].
+
+ allFileParse do: [ :each | self createHtmlFile: each ].
+
+ sum := MicSummarizer new.
+ sum targetDirectory: targetDirectory .
+
+ self createHtmlSummarize: (sum summarizeFile: allFile).
+
+ MicCreateMonth generateDateListSince2014 do: [ :each |
+ summar := sum group: allFileParse byDate: each.
+ summar isNotEmpty ifTrue: [
+ summar := sum summarize: summar.
+ self createHtmlGroupFile: summar at: each ] ]
+]
+
+{ #category : 'rendering' }
+MicBlogCreator >> createHtmlFile: aMicRoot [
+
+ | a q date header |
+
+ self rootAssembly: aMicRoot.
+
+ a := (MicHTMLVisitor new visit: aMicRoot) at: 1.
+
+ date := (aMicRoot children at: 1) body at: #date.
+ date := date asDate.
+ header := MicSingleSummarizer new firstHeaderBlockOf: aMicRoot.
+
+ q := MicHTMLDocument new.
+ q configuration: a configuration.
+ q configuration document: q.
+ q
+ setCharSetUTF8;
+ destinationPath:
+ targetDirectory , '\' , date year asString , '\' , date monthName
+ , '\' , date day asString , '\'.
+ ^ q
+ fileName: header text , '.html';
+ writeDocument: a contents;
+ contents
+]
+
+{ #category : 'rendering' }
+MicBlogCreator >> createHtmlGroupFile: aMicRoot at: aDate [
+
+ | a q |
+ self rootAssembly: aMicRoot.
+
+ a := (MicHTMLVisitor new visit: aMicRoot) at: 1.
+
+ q := MicHTMLDocument new.
+ q configuration: a configuration.
+ q configuration document: q.
+ q
+ setCharSetUTF8;
+ destinationPath:
+ targetDirectory , '\' , aDate year asString , '\' , aDate monthName
+ , '\'.
+ ^ q
+ writeDocument: a contents;
+ contents
+]
+
+{ #category : 'rendering' }
+MicBlogCreator >> createHtmlSummarize: aMicRoot [
+
+ | a q |
+
+ self rootAssembly: aMicRoot.
+
+ a := (MicHTMLVisitor new visit: aMicRoot) at: 1.
+
+ q := MicHTMLDocument new.
+ q configuration: a configuration.
+ q configuration document: q.
+ q
+ setCharSetUTF8;
+ destinationPath: targetDirectory.
+ ^ q
+ writeDocument: a contents;
+ contents
+]
+
+{ #category : 'as yet unclassified' }
+MicBlogCreator >> rootAssembly: aMicRoot [
+
+ aMicRoot addChild: (MicCreateMonth generateMicListBlockOfLinkDateTo: targetDirectory).
+ ^ aMicRoot
+
+
+
+]
+
+{ #category : 'accessing' }
+MicBlogCreator >> sourceDirectory [
+
+ ^ sourceDirectory
+]
+
+{ #category : 'accessing' }
+MicBlogCreator >> sourceDirectory: source [
+
+ sourceDirectory := source.
+]
+
+{ #category : 'accessing' }
+MicBlogCreator >> targetDirectory [
+
+ ^ targetDirectory
+]
+
+{ #category : 'accessing' }
+MicBlogCreator >> targetDirectory: target [
+
+ targetDirectory := target
+]
diff --git a/src/Microdown-Blog/MicCreateMonth.class.st b/src/Microdown-Blog/MicCreateMonth.class.st
new file mode 100644
index 00000000..174eee14
--- /dev/null
+++ b/src/Microdown-Blog/MicCreateMonth.class.st
@@ -0,0 +1,34 @@
+Class {
+ #name : 'MicCreateMonth',
+ #superclass : 'Object',
+ #category : 'Microdown-Blog',
+ #package : 'Microdown-Blog'
+}
+
+{ #category : 'generate' }
+MicCreateMonth class >> generateDateListSince2014 [
+
+ | date t |
+ date := Date newDay: 1 month: 1 year: 2014.
+
+ t := Timespan
+ starting: date
+ duration:
+ (Duration years: [ Date today year - date year + 1 ] value).
+ ^ t months
+]
+
+{ #category : 'generate' }
+MicCreateMonth class >> generateMicListBlockOfLinkDateTo: aDestination [
+
+ | root link inlineParser listElement |
+ root := MicUnorderedListBlock new.
+ inlineParser := MicInlineParser new.
+
+ self generateDateListSince2014 do: [ :each |
+ listElement := MicListItemBlock new.
+ link := MicDocumentTransformer makeALink: each asString to: aDestination, '/', each year asString,'/',each name,'/'.
+ (link at:1) parent: listElement.
+ listElement parent: root ].
+ ^ root
+]
diff --git a/src/Microdown-Blog/MicDocumentTransformer.class.st b/src/Microdown-Blog/MicDocumentTransformer.class.st
new file mode 100644
index 00000000..2f115d2a
--- /dev/null
+++ b/src/Microdown-Blog/MicDocumentTransformer.class.st
@@ -0,0 +1,27 @@
+Class {
+ #name : 'MicDocumentTransformer',
+ #superclass : 'Object',
+ #instVars : [
+ 'targetDirectory'
+ ],
+ #category : 'Microdown-Blog',
+ #package : 'Microdown-Blog'
+}
+
+{ #category : 'as yet unclassified' }
+MicDocumentTransformer class >> makeALink: aText to: aLink [
+
+ ^ MicInlineParser parse: '[' , aText, '](' , aLink , ')'
+]
+
+{ #category : 'accessing' }
+MicDocumentTransformer >> targetDirectory [
+
+ ^ targetDirectory
+]
+
+{ #category : 'accessing' }
+MicDocumentTransformer >> targetDirectory: target [
+
+ targetDirectory := target
+]
diff --git a/src/Microdown-Blog/MicSingleSummarizer.class.st b/src/Microdown-Blog/MicSingleSummarizer.class.st
index d911f022..2fdd0aa2 100644
--- a/src/Microdown-Blog/MicSingleSummarizer.class.st
+++ b/src/Microdown-Blog/MicSingleSummarizer.class.st
@@ -1,64 +1,13 @@
Class {
#name : 'MicSingleSummarizer',
- #superclass : 'Object',
+ #superclass : 'MicDocumentTransformer',
#instVars : [
- 'maximumWords',
- 'destinationDirectory',
- 'filePath'
+ 'maximumWords'
],
#category : 'Microdown-Blog',
#package : 'Microdown-Blog'
}
-{ #category : 'rendering' }
-MicSingleSummarizer >> createHtmlFile: aMicRoot [
-
- | a q date header |
- a := (MicHTMLVisitor new visit: aMicRoot) at: 1.
-
- date := (aMicRoot children at: 1) body at: #date.
- date := date asDate.
- header := self firstHeaderBlockOf: aMicRoot.
-
- q := MicHTMLDocument new.
- q configuration: a configuration.
- q configuration document: q.
- q
- setCharSetUTF8;
- destinationPath:
- destinationDirectory , '\' , date year asString , '\'
- , date monthName , '\' , date day asString , '\'.
- filePath := q destinationPath , header text , '.html'.
- ^ q
- fileName: header text , '.html';
- writeDocument: a contents;
- contents
-]
-
-{ #category : 'accessing' }
-MicSingleSummarizer >> destinationDirectory [
-
- ^ destinationDirectory
-]
-
-{ #category : 'accessing' }
-MicSingleSummarizer >> destinationDirectory: aDestination [
-
- destinationDirectory := aDestination
-]
-
-{ #category : 'accessing' }
-MicSingleSummarizer >> filePath [
-
- ^ filePath
-]
-
-{ #category : 'accessing' }
-MicSingleSummarizer >> filePath: aFilePath [
-
- filePath := aFilePath.
-]
-
{ #category : 'accessing' }
MicSingleSummarizer >> firstHeaderBlockOf: aMicRootBlock [
@@ -70,6 +19,7 @@ MicSingleSummarizer >> firstHeaderBlockOf: aMicRootBlock [
h := MicHeaderBlock new.
t := MicTextBlock new bodyString:
'Please define a header'.
+ h level: 1.
t parent: h.
^ h ].
newHeader := MicHeaderBlock new.
@@ -112,13 +62,30 @@ MicSingleSummarizer >> firstParagraphBlockOf: aMicRootBlock [
^ newParagraph
]
+{ #category : 'parsing' }
+MicSingleSummarizer >> headerLink: aMicRootBlock [
+
+ | headerLink header date |
+ headerLink := MicHeaderBlock new.
+ header := self firstHeaderBlockOf: aMicRootBlock.
+ date := (aMicRootBlock children at: 1) body at: #date.
+ date := date asDate.
+ headerLink
+ addChild: ((self class
+ makeALink: header text
+ to:
+ targetDirectory , date year asString , '/' , date monthName
+ , '/' , date day asString , '/', header text) at: 1);
+ level: header level.
+
+ ^ headerLink
+]
+
{ #category : 'initialization' }
MicSingleSummarizer >> initialize [
super initialize.
maximumWords := 15.
- "Directory for testing, we should change this for the final directory"
- destinationDirectory := '\Users\qmout\Documents\Pharo\images\Microdown\output\html'
]
{ #category : 'accessing' }
@@ -129,14 +96,15 @@ MicSingleSummarizer >> maximumWords: anInteger [
{ #category : 'parsing' }
MicSingleSummarizer >> summarize: aMicRootBlock [
- | element headerLink |
- self createHtmlFile: aMicRootBlock .
+ | element headerLink root|
+ root := self verifyDateMetadata: aMicRootBlock.
element := MicRootBlock new.
- headerLink := self transformHeaderToLinkHeader: (self firstHeaderBlockOf: aMicRootBlock).
+ headerLink := self headerLink: root.
+
element
- addChild: aMicRootBlock children first;
+ addChild: root children first;
addChild: headerLink;
- addChild: (self firstParagraphBlockOf: aMicRootBlock).
+ addChild: (self firstParagraphBlockOf: root).
^ element
]
@@ -149,16 +117,27 @@ MicSingleSummarizer >> summarizeFile: aFileReference [
^ self summarize: p
]
-{ #category : 'parsing' }
-MicSingleSummarizer >> transformHeaderToLinkHeader: aHeader [
-
- | headerLink |
- headerLink := MicHeaderBlock new.
- headerLink
- addChild:
- ((MicInlineParser parse: '[' , aHeader text , '](' , filePath , ')')
- at: 1);
- level: aHeader level.
-
- ^ headerLink
+{ #category : 'as yet unclassified' }
+MicSingleSummarizer >> verifyDateMetadata: aMicRootBlock [
+
+ | newMicRootBlock metadata |
+ newMicRootBlock := MicRootBlock new.
+
+ ((aMicRootBlock children at: 1) isKindOf: MicMetaDataBlock)
+ ifFalse: [
+ metadata := MicMetaDataBlock new.
+ metadata body:
+ (Dictionary
+ newFromKeys: #( #date )
+ andValues: #( '25 December 1970' ))]
+ ifTrue: [
+ metadata := aMicRootBlock children at: 1.
+ (metadata body at: #date) ifNil: [
+ metadata body at: #date put: '25 December 1970' ] ].
+ metadata parent: newMicRootBlock.
+
+ aMicRootBlock children
+ do: [ :each | newMicRootBlock addChild: each ]
+ without: metadata.
+ ^ newMicRootBlock
]
diff --git a/src/Microdown-Blog/MicSummarizer.class.st b/src/Microdown-Blog/MicSummarizer.class.st
index 159ac7e5..36ca0915 100644
--- a/src/Microdown-Blog/MicSummarizer.class.st
+++ b/src/Microdown-Blog/MicSummarizer.class.st
@@ -1,6 +1,6 @@
Class {
#name : 'MicSummarizer',
- #superclass : 'Object',
+ #superclass : 'MicDocumentTransformer',
#instVars : [
'maximumFile'
],
@@ -8,41 +8,13 @@ Class {
#package : 'Microdown-Blog'
}
-{ #category : 'generate' }
-MicSummarizer >> generateDateListSince2014 [
-
- | date t |
-
- date := Date newDay: 1 month: 1 year: 2014.
-
- t := Timespan starting: date duration: (Duration years: [ Date today year - date year + 1] value ).
- ^ t months
-
-]
-
-{ #category : 'generate' }
-MicSummarizer >> generateMicListBlockOfDate [
-
- | root link text inlineParser listElement |
- root := MicUnorderedListBlock new.
- inlineParser := MicInlineParser new.
-
- self generateDateListSince2014 do: [ :each |
- listElement := MicListItemBlock new.
- text := '[' , each asString , '](' , 'http://pharo.org' , ')'.
- link := inlineParser parse: text.
- (link at: 1) parent: listElement.
- listElement parent: root ].
- ^ root
-]
-
{ #category : 'grouping' }
MicSummarizer >> group: aListOfSingleSummarizer byDate: aDate [
| metadataDate |
-
- ^ aListOfSingleSummarizer select: [ :each | metadataDate := ( each children at:1 ) body at: #date.
- ( metadataDate asDate isOnOrAfter:aDate ) and: [ metadataDate asDate isBefore: (aDate addMonths: 1) ] ]
+ ^ aListOfSingleSummarizer select: [ :each |
+ metadataDate := (each children at: 1) body at: #date.
+ metadataDate asDate month = aDate month]
]
{ #category : 'initialization' }
@@ -64,31 +36,6 @@ MicSummarizer >> maximumFile: aNumber [
maximumFile := aNumber
]
-{ #category : 'rendering' }
-MicSummarizer >> render: aMicSummerize [
-
- | a q |
-
- aMicSummerize addChild: self generateMicListBlockOfDate.
-
- a := (MicHTMLVisitor new visit: aMicSummerize) at: 1.
-
- q := MicHTMLDocument new.
- q configuration: a configuration.
- q configuration document: q.
- q setCharSetUTF8.
- ^ q
- writeDocumentBody: a contents;
- writeToFile;
- contents
-]
-
-{ #category : 'rendering' }
-MicSummarizer >> renderFiles: aListOfFiles [
-
- ^ self render: ( self summarizeFile: aListOfFiles )
-]
-
{ #category : 'as yet unclassified' }
MicSummarizer >> summarize: aListOfSingleSummarizer [
@@ -96,6 +43,7 @@ MicSummarizer >> summarize: aListOfSingleSummarizer [
summarize := MicRootBlock new.
singleSummarizer := MicSingleSummarizer new.
+ singleSummarizer targetDirectory: targetDirectory.
selectionSize := maximumFile min: aListOfSingleSummarizer size.
@@ -113,9 +61,10 @@ MicSummarizer >> summarizeFile: aListOfFile [
| list singleSummarizer selectionSize |
singleSummarizer := MicSingleSummarizer new.
+ singleSummarizer targetDirectory: targetDirectory.
list := Array new: aListOfFile size.
-
+
selectionSize := maximumFile min: aListOfFile size.
1 to: selectionSize do: [ :each |