Skip to content

Commit

Permalink
Merge pull request pillar-markup#737 from moufort/dev
Browse files Browse the repository at this point in the history
Correction and update of Microdown-Blog
  • Loading branch information
Ducasse authored May 14, 2024
2 parents c8bc0bc + 0c64216 commit 058838c
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 71 deletions.
81 changes: 70 additions & 11 deletions src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MicSingleSummarizerTest >> createMicRootBlock [
MicSingleSummarizerTest >> generateFilesystemExample [

| file |
file := FileSystem disk workingDirectory / 'anExample1.md'.
file := FileSystem memory workingDirectory / 'anExample1.md'.
file writeStreamDo: [ :stream | stream nextPutAll: '# A Cool Story
@sec1
Expand All @@ -35,8 +35,19 @@ this is a code blu blu
^ file.
]

{ #category : 'enumerating' }
MicSingleSummarizerTest >> generateFilesystemExampleEmpty [

| file |
file := FileSystem memory workingDirectory / 'anExample1.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: '' ].

^ file
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testFirstHeaderBlock [
MicSingleSummarizerTest >> testFirstHeaderBlockOf [

| header |

Expand All @@ -49,18 +60,66 @@ MicSingleSummarizerTest >> testFirstHeaderBlock [
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testFirstParagraphBlock [
MicSingleSummarizerTest >> testFirstHeaderBlockOfWithNoHeader [

| header |
header := MicSingleSummarizer new firstHeaderBlockOf:(Microdown parse: self generateFilesystemExampleEmpty asFileReference contents).
self assert: (header isKindOf: MicHeaderBlock).
self assert: header text equals: 'Please define a header'.

self
assert:
(header headerElements collect: [ :each | each plainText ]) asArray
equals: #( 'Please define a header' ).
header headerElements do: [ :each |
self assert: each parent equals: header ]
]

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

| paragraph |

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

self assert: paragraph textElements size equals: 3.
self assert: (paragraph textElements collect: [:each | each plainText ]) asArray equals: #('Pharo is cool but ' 'this is' ' a superlong ').
paragraph textElements do: [ :each | self assert: each parent equals: paragraph ]
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 ]
]

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

| paragraph |
paragraph := MicSingleSummarizer new
maximumWords: 3;
firstParagraphBlockOf: (Microdown parse:
self generateFilesystemExampleEmpty asFileReference
contents).
self assert: (paragraph isKindOf: MicParagraphBlock).

self assert: paragraph textElements size equals: 1.
self
assert:
(paragraph textElements collect: [ :each | each plainText ]) asArray
equals: #( 'Please add a paragraph' ).
paragraph textElements do: [ :each |
self assert: each parent equals: paragraph ]
]

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

| root |
root := MicSingleSummarizer new summarize: self createMicRootBlock.
self assert: (root isKindOf: MicRootBlock);
assert: (root children size) equals: 3.
]

{ #category : 'tests' }
Expand Down
125 changes: 125 additions & 0 deletions src/Microdown-Blog-Tests/MicSummarizerTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Class {
#name : 'MicSummarizerTest',
#superclass : 'TestCase',
#category : 'Microdown-Blog-Tests',
#package : 'Microdown-Blog-Tests'
}

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

| q |
q := Array new: 3.
q at: 1 put: self generateFilesystemExample1;
at: 2 put: self generateFilesystemExample2;
at: 3 put: self generateFilesystemExample3.
^ q
]

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

| q singleSummarizer |
q := Array new: 3.
singleSummarizer := MicSingleSummarizer new.
q
at: 1 put: (singleSummarizer summarize: (Microdown parse:
self generateFilesystemExample1 asFileReference contents));
at: 2 put: (singleSummarizer summarize: (Microdown parse:
self generateFilesystemExample2 asFileReference contents));
at: 3 put: (singleSummarizer summarize: (Microdown parse:
self generateFilesystemExample3 asFileReference contents)).
^ q
]

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

| file |
file := FileSystem memory workingDirectory / 'anExample1.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: '{
"date" : "8 January 2019"
}
# A Cool Story
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!
' ].

^ file
]

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

| file |
file := FileSystem memory workingDirectory / 'anExample2.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: '{
"date" : "22 January 2019"
}
# Pharo is cool
If you are either a beginner or an expert in object-oriented programming, _this MOOC_ will change the way you program with objects: come and learn or rediscover _object-oriented programming_ with Pharo!
Pharo is a pure _object-oriented programming language_ in the tradition of Smalltalk. It offers a unique developing experience in constant interaction with live objects. Pharo is elegant, fun to use and very powerful. It is very easy to learn and enables to understand advanced concept in a natural way. When programming in Pharo, you are immersed in a world of live objects. You have immediate feedback at any moment of your development on objects representing web applications, code itself, graphics, network. More…
' ].

^ file
]

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

| file |
file := FileSystem memory workingDirectory / 'anExample3.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: '{
"date" : "29 January 2018"
}
# Mooc Pharo
Welcome to the Pharo Mooc (a set of videos, exercises, challenges, and miniprojects).
The Pharo Mooc is fully dubbed in french and english. It comes with subtitles in Japanese, english, french and spanish. This web site contains all the material of this Mooc in free access.
In addition, in average every 18 months the Mooc is proposed and run on the France Université Numérique platform (Even if the platform is french the mooc is run in both languages).
When you participate to the mooc you get access to the quizz and the credit validation.
' ].

^ file
]

{ #category : 'tests' }
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.
]

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

| summary |
summary := MicSummarizer new summarize: self createListOfMicRootBlock.
self
assert: (summary isKindOf: MicRootBlock);
assert: summary children size equals: 6
]

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

| summary |
summary := MicSummarizer new summarizeFile: self createListOfFile.
self
assert: (summary isKindOf: MicRootBlock);
assert: summary children size equals: 6
]
18 changes: 0 additions & 18 deletions src/Microdown-Blog-Tests/MicSummerizeBlockTest.class.st

This file was deleted.

59 changes: 34 additions & 25 deletions src/Microdown-Blog/MicSingleSummarizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,47 @@ Class {
{ #category : 'accessing' }
MicSingleSummarizer >> firstHeaderBlockOf: aMicRootBlock [


| header newHeader |
header := aMicRootBlock children
detect: [ :each | each isKindOf: MicHeaderBlock ]
ifNone: [
| h t |
h := MicHeaderBlock new.
t := MicTextBlock new bodyString: 'Please define a header'.
h headerElements: { t }.
t parent: h.
^ h ].
header := aMicRootBlock children
detect: [ :each | each isKindOf: MicHeaderBlock ]
ifNone: [
| h t |
h := MicHeaderBlock new.
t := MicTextBlock new bodyString:
'Please define a header'.
t parent: h.
^ h ].
newHeader := MicHeaderBlock new.
header headerElements do: [ :t | t copy parent: newHeader ].
header headerElements do: [ :t | t copy parent: newHeader ].
newHeader level: header level.
^ newHeader
]

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

| p textElements newParagraph selectionSize t |
p := aMicRootBlock children
detect: [ :each | each isKindOf: MicParagraphBlock ]
ifNone: [
p := MicParagraphBlock new.
t := MicTextBlock new bodyString: 'Please add a paragraph'.
p textElements: { t }.
t parent: p.
^ p ].
selectionSize := maximumWords min: p textElements size.
textElements := (p textElements first: selectionSize).

| p textElements newParagraph selectionSize t sub |
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.

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

newParagraph := MicParagraphBlock new.
textElements do: [ :t |
newParagraph addChild: t copy ].
t := MicTextBlock new bodyString: textElements ensureNoSpace contents.
t parent: newParagraph.
^ newParagraph
]

Expand All @@ -66,6 +74,7 @@ MicSingleSummarizer >> summarize: aMicRootBlock [
| element |
element := MicRootBlock new.
element
addChild: (aMicRootBlock children first);
addChild: (self firstHeaderBlockOf: aMicRootBlock);
addChild: (self firstParagraphBlockOf: aMicRootBlock).

Expand Down
Loading

0 comments on commit 058838c

Please sign in to comment.