Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add link and test in Web developpemment #740

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,25 @@ MicSingleSummarizerTest >> testFirstParagraphBlockOf [
self
assert:
(paragraph textElements collect: [ :each | each plainText ]) asArray
equals: #( 'Pharo is cool' ).
equals: #( 'Pharo is cool ...' ).
paragraph textElements do: [ :each |
self assert: each parent equals: paragraph ]
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testFirstParagraphBlockOfWithEllipsis [

| paragraph |
paragraph := MicSingleSummarizer new
maximumWords: 3;
firstParagraphBlockOf: self createMicRootBlock.
self assert: (paragraph isKindOf: MicParagraphBlock).

self assert: paragraph textElements size equals: 1.
self
assert:
(paragraph textElements collect: [ :each | each plainText ]) asArray
equals: #( 'Pharo is cool ...' ).
paragraph textElements do: [ :each |
self assert: each parent equals: paragraph ]
]
Expand All @@ -113,6 +131,25 @@ MicSingleSummarizerTest >> testFirstParagraphBlockOfWithNoParagraph [
self assert: each parent equals: paragraph ]
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testFirstParagraphBlockOfWithoutEllipsis [

| paragraph |
paragraph := MicSingleSummarizer new
maximumWords: 5;
firstParagraphBlockOf:
(Microdown parse: 'Pharo is cool').
self assert: (paragraph isKindOf: MicParagraphBlock).

self assert: paragraph textElements size equals: 1.
self
assert:
(paragraph textElements collect: [ :each | each plainText ]) asArray
equals: #( 'Pharo is cool' ).
paragraph textElements do: [ :each |
self assert: each parent equals: paragraph ]
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testSummarize [

Expand Down
147 changes: 147 additions & 0 deletions src/Microdown-Blog-Tests/MicSummarizerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,153 @@ When you participate to the mooc you get access to the quizz and the credit vali
^ file
]

{ #category : 'as yet unclassified' }
MicSummarizerTest >> htmlBodyTest [

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the single summariser I do not get why we would have to have all the links.

^ '<body><main role="main">
<h1><a target="_blank" href="''''/''''">A Cool Story</a></h1>
<p>Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no ...</p>
<h1><a target="_blank" href="''''/''''">Pharo is cool</a></h1>
<p>If you are either a beginner or an expert in object-oriented programming, _this MOOC_ will ...</p>
<h1><a target="_blank" href="''''/''''">Mooc Pharo</a></h1>
<p>Welcome to the Pharo Mooc (a set of videos, exercises, challenges, and miniprojects).</p>
<ul>
<li><a target="_blank" href="http://pharo.org/">January 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2014</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2015</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2016</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2017</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2018</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2019</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2020</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2021</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2022</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2023</a></li>
<li><a target="_blank" href="http://pharo.org/">January 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">February 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">March 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">April 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">May 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">June 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">July 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">August 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">September 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">October 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">November 2024</a></li>
<li><a target="_blank" href="http://pharo.org/">December 2024</a></li>
</ul></main></body>'

]

{ #category : 'tests' }
MicSummarizerTest >> testGroupByDate [

Expand Down
100 changes: 87 additions & 13 deletions src/Microdown-Blog/MicSingleSummarizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,63 @@ Class {
#name : 'MicSingleSummarizer',
#superclass : 'Object',
#instVars : [
'maximumWords'
'maximumWords',
'destinationDirectory',
'filePath'
],
#category : 'Microdown-Blog',
#package : 'Microdown-Blog'
}

{ #category : 'rendering' }
MicSingleSummarizer >> createHtmlFile: aMicRoot [

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add on microroot something like

date
     self children first date
MetaData >> date
     ....
     with a default date if there is none in the metadata

this will probably only works when we have metadata so on MicElement we should define another

date
    ^ Date ....1980

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
]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed the summariser as well as all the components date sorter, blogentry...
should all work from a directory to a directory.

So I asked myself what is filePath vs. destinaryDirectory: why this is not a sourceDirectory

{ #category : 'accessing' }
MicSingleSummarizer >> filePath [

^ filePath
]

{ #category : 'accessing' }
MicSingleSummarizer >> filePath: aFilePath [

filePath := aFilePath.
]

{ #category : 'accessing' }
MicSingleSummarizer >> firstHeaderBlockOf: aMicRootBlock [

Expand All @@ -30,24 +81,30 @@ MicSingleSummarizer >> firstHeaderBlockOf: aMicRootBlock [
{ #category : 'accessing' }
MicSingleSummarizer >> firstParagraphBlockOf: aMicRootBlock [

| p textElements newParagraph selectionSize t sub |
| p textElements newParagraph selectionSize t sub newSub |
p := aMicRootBlock children
detect: [ :each | each isKindOf: MicParagraphBlock ]
ifNone: [
p := MicParagraphBlock new.
t := MicTextBlock new bodyString: 'Please add a paragraph'.
t parent: p.
^ p ].

sub := p text substrings: ' '.
selectionSize := maximumWords min: sub size.
sub := sub first: selectionSize.
newSub := sub first: selectionSize.

textElements := '' writeStream.
sub do: [ :each |
newSub do: [ :each |
textElements
nextPutAll: each;
nextPut: Character space ].

sub size >= maximumWords ifTrue: [ textElements
nextPutAll: '...' ].

textElements close.


newParagraph := MicParagraphBlock new.
t := MicTextBlock new bodyString: textElements ensureNoSpace contents.
Expand All @@ -59,7 +116,9 @@ MicSingleSummarizer >> firstParagraphBlockOf: aMicRootBlock [
MicSingleSummarizer >> initialize [

super initialize.
maximumWords := 15
maximumWords := 15.
"Directory for testing, we should change this for the final directory"
destinationDirectory := '\Users\qmout\Documents\Pharo\images\Microdown\output\html'
]

{ #category : 'accessing' }
Expand All @@ -70,15 +129,16 @@ MicSingleSummarizer >> maximumWords: anInteger [
{ #category : 'parsing' }
MicSingleSummarizer >> summarize: aMicRootBlock [


| element |
| element headerLink |
self createHtmlFile: aMicRootBlock .
element := MicRootBlock new.
element
addChild: (aMicRootBlock children first);
addChild: (self firstHeaderBlockOf: aMicRootBlock);
headerLink := self transformHeaderToLinkHeader: (self firstHeaderBlockOf: aMicRootBlock).
element
addChild: aMicRootBlock children first;
addChild: headerLink;
addChild: (self firstParagraphBlockOf: aMicRootBlock).
^ element.

^ element
]

{ #category : 'parsing' }
Expand All @@ -88,3 +148,17 @@ MicSingleSummarizer >> summarizeFile: aFileReference [
p := Microdown parse: aFileReference asFileReference contents.
^ self summarize: p
]

{ #category : 'parsing' }
MicSingleSummarizer >> transformHeaderToLinkHeader: aHeader [

| headerLink |
headerLink := MicHeaderBlock new.
headerLink
addChild:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extract this expression in makeAlink: to:

((MicInlineParser parse: '[' , aHeader text , '](' , filePath , ')')
at: 1);
level: aHeader level.

^ headerLink
]
Loading
Loading