-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #733 from moufort/dev
Microdown-Blog
- Loading branch information
Showing
6 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Class { | ||
#name : 'MicSingleSummarizerTest', | ||
#superclass : 'TestCase', | ||
#category : 'Microdown-Blog-Tests', | ||
#package : 'Microdown-Blog-Tests' | ||
} | ||
|
||
{ #category : 'enumerating' } | ||
MicSingleSummarizerTest >> createMicRootBlock [ | ||
|
||
^ Microdown parse: self generateFilesystemExample asFileReference contents | ||
] | ||
|
||
{ #category : 'enumerating' } | ||
MicSingleSummarizerTest >> generateFilesystemExample [ | ||
|
||
| file | | ||
file := FileSystem disk 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 : 'tests' } | ||
MicSingleSummarizerTest >> testFirstHeaderBlock [ | ||
|
||
| header | | ||
|
||
header := MicSingleSummarizer new firstHeaderBlockOf: self createMicRootBlock. | ||
self assert: ( header isKindOf: MicHeaderBlock). | ||
self assert: header text equals: 'A Cool Story'. | ||
|
||
self assert: (header headerElements collect: [:each | each plainText ]) asArray equals: #('A Cool Story'). | ||
header headerElements do: [ :each | self assert: each parent equals: header ] | ||
] | ||
|
||
{ #category : 'tests' } | ||
MicSingleSummarizerTest >> testFirstParagraphBlock [ | ||
|
||
| 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 ] | ||
] | ||
|
||
{ #category : 'tests' } | ||
MicSingleSummarizerTest >> testSummarizeFile [ | ||
|
||
| root | | ||
root := MicSingleSummarizer new summarizeFile: self generateFilesystemExample. | ||
self assert: (root isKindOf: MicRootBlock) | ||
|
||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Class { | ||
#name : 'MicSummerizeBlockTest', | ||
#superclass : 'TestCase', | ||
#category : 'Microdown-Blog-Tests', | ||
#package : 'Microdown-Blog-Tests' | ||
} | ||
|
||
{ #category : 'tests' } | ||
MicSummerizeBlockTest >> testCreateSummerize [ | ||
|
||
self assert: 1 equals: 0. | ||
] | ||
|
||
{ #category : 'tests' } | ||
MicSummerizeBlockTest >> testRender [ | ||
|
||
self assert: 1 equals: 0. | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : 'Microdown-Blog-Tests' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Class { | ||
#name : 'MicSingleSummarizer', | ||
#superclass : 'Object', | ||
#instVars : [ | ||
'maximumWords' | ||
], | ||
#category : 'Microdown-Blog', | ||
#package : 'Microdown-Blog' | ||
} | ||
|
||
{ #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 ]. | ||
newHeader := MicHeaderBlock new. | ||
header headerElements do: [ :t | t copy parent: newHeader ]. | ||
^ 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). | ||
newParagraph := MicParagraphBlock new. | ||
textElements do: [ :t | | ||
newParagraph addChild: t copy ]. | ||
^ newParagraph | ||
] | ||
|
||
{ #category : 'initialization' } | ||
MicSingleSummarizer >> initialize [ | ||
|
||
super initialize. | ||
maximumWords := 15 | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MicSingleSummarizer >> maximumWords: anInteger [ | ||
maximumWords := anInteger | ||
] | ||
|
||
{ #category : 'parsing' } | ||
MicSingleSummarizer >> summarize: aMicRootBlock [ | ||
|
||
|
||
| element | | ||
element := MicRootBlock new. | ||
element | ||
addChild: (self firstHeaderBlockOf: aMicRootBlock); | ||
addChild: (self firstParagraphBlockOf: aMicRootBlock). | ||
|
||
^ element. | ||
] | ||
|
||
{ #category : 'parsing' } | ||
MicSingleSummarizer >> summarizeFile: aFileReference [ | ||
|
||
| p | | ||
p := Microdown parse: aFileReference asFileReference contents. | ||
^ self summarize: p | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Class { | ||
#name : 'MicSummarizer', | ||
#superclass : 'Object', | ||
#category : 'Microdown-Blog', | ||
#package : 'Microdown-Blog' | ||
} | ||
|
||
{ #category : 'as yet unclassified' } | ||
MicSummarizer >> createSummerize: aListOfElementSummerizeBlock [ | ||
|
||
| summarize | | ||
|
||
summarize := MicRootBlock new. | ||
|
||
(aListOfElementSummerizeBlock copyFrom: 1 to: 10) do:[ :each | summarize addChild: each title ; addChild: each resume ]. | ||
|
||
^ summarize | ||
] | ||
|
||
{ #category : 'as yet unclassified' } | ||
MicSummarizer >> group: aListOfElementSummerizeBlock byDate: aDate [ | ||
|
||
^ aListOfElementSummerizeBlock select: [ :each | ( each children at:1 ) at: #Date = aDate ] | ||
] | ||
|
||
{ #category : 'rendering' } | ||
MicSummarizer >> render: aMicSummerizeBlock [ | ||
|
||
| a q | | ||
|
||
a := (MicHTMLVisitor new visit: aMicSummerizeBlock ) at: 1. | ||
|
||
q := MicHTMLDocument new. | ||
q configuration: a configuration. | ||
q configuration document: q. | ||
q setCharSetUTF8. | ||
^ q writeDocument: a contents; | ||
writeToFile; | ||
contents. | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : 'Microdown-Blog' } |