-
Notifications
You must be signed in to change notification settings - Fork 33
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can add on microroot something like
this will probably only works when we have metadata so on MicElement we should define another
|
||
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 | ||
] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed the summariser as well as all the components date sorter, blogentry... 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 [ | ||
|
||
|
@@ -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. | ||
|
@@ -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' } | ||
|
@@ -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' } | ||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
] |
There was a problem hiding this comment.
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.