Skip to content

Commit

Permalink
Managing styler at loadtime once instead for any codeblock.... faster…
Browse files Browse the repository at this point in the history
…, better, nicer :)
  • Loading branch information
Ducasse committed Oct 20, 2020
1 parent 4345fa3 commit 876a32d
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/Pillar-ExporterRichText/PRRichTextComposer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Class {
'HeaderFonts',
'ImageCache',
'NotRendering',
'OffLine'
'OffLine',
'Stylers'
],
#category : #'Pillar-ExporterRichText-Core'
}
Expand Down Expand Up @@ -79,7 +80,7 @@ PRRichTextComposer class >> bulletForLevel: level [
ifTrue: [ ^ $- asText ]
]

{ #category : #stylers }
{ #category : #'styler - declaration' }
PRRichTextComposer class >> codeStylerFor: aString [
<codeblockStylerFor: 'Smalltalk'>

Expand Down Expand Up @@ -114,15 +115,15 @@ PRRichTextComposer class >> counterFor: counter atLevel: level [
ifTrue: [ ^ ($A asInteger + (counter - 1)) asCharacter asText , ')' ]
]

{ #category : #stylers }
{ #category : #'styler - declaration' }
PRRichTextComposer class >> defaultStyler: aString [
<codeblockStylerFor:'default'>
<codeblockStylerFor: 'default'>
"Pay attention without this one the logic can loop."

"By default, render it as code"
^self codeStylerFor: aString
^ self codeStylerFor: aString
]

{ #category : #stylers }
{ #category : #'styler - declaration' }
PRRichTextComposer class >> expressionStylerFor: aString [
<codeblockStylerFor: 'PharoExpression'>

Expand Down Expand Up @@ -165,21 +166,27 @@ PRRichTextComposer class >> initialize [
self notRendering: false.
self resetCache.
self headerFontSizes: #(18 14 12 11 10 10).
self initializeStylers.
]

{ #category : #stylers }
PRRichTextComposer class >> languageStylerFor: aLanguage [
| stylers |
stylers := Dictionary
{ #category : #'class initialization' }
PRRichTextComposer class >> initializeStylers [
"self initializeStylers"
Stylers := Dictionary
newFromAssociations: ((PragmaCollector
filter: [ :prg | prg selector = 'codeblockStylerFor:' ]) reset
collected collect: [ :p | p arguments first -> p method ]).
^ stylers
at: aLanguage
ifAbsent: [ self languageStylerFor: 'default' ]
collected collect: [ :p | p arguments first asLowercase-> p method ])
]

{ #category : #stylers }
PRRichTextComposer class >> languageStylerFor: aLanguage [

^ Stylers
at: aLanguage asLowercase
ifAbsent: [ self languageStylerFor: 'default' ]
]

{ #category : #'styler - declaration' }
PRRichTextComposer class >> methodStylerFor: aString [
<codeblockStylerFor:'PharoMethod'>

Expand Down Expand Up @@ -264,15 +271,15 @@ PRRichTextComposer class >> style: aString asLanguage: aLanguage [
"render aString according to the styler named aLanguage"

| styler |
styler := self languageStylerFor: aLanguage.
styler := self languageStylerFor: aLanguage asLowercase.
^ styler
valueWithReceiver: styler methodClass soleInstance
arguments: (Array with: aString)
]

{ #category : #stylers }
{ #category : #'styler - declaration' }
PRRichTextComposer class >> textStyler: aString [
<codeblockStylerFor:'text'>
<codeblockStylerFor: 'text'>

^aString asText
]
Expand Down

0 comments on commit 876a32d

Please sign in to comment.