From 876a32d541d564503dad3fed9126f594b67085d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Tue, 20 Oct 2020 18:35:22 +0200 Subject: [PATCH] Managing styler at loadtime once instead for any codeblock.... faster, better, nicer :) --- .../PRRichTextComposer.class.st | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Pillar-ExporterRichText/PRRichTextComposer.class.st b/src/Pillar-ExporterRichText/PRRichTextComposer.class.st index 8838ebc6..84a4b530 100644 --- a/src/Pillar-ExporterRichText/PRRichTextComposer.class.st +++ b/src/Pillar-ExporterRichText/PRRichTextComposer.class.st @@ -50,7 +50,8 @@ Class { 'HeaderFonts', 'ImageCache', 'NotRendering', - 'OffLine' + 'OffLine', + 'Stylers' ], #category : #'Pillar-ExporterRichText-Core' } @@ -79,7 +80,7 @@ PRRichTextComposer class >> bulletForLevel: level [ ifTrue: [ ^ $- asText ] ] -{ #category : #stylers } +{ #category : #'styler - declaration' } PRRichTextComposer class >> codeStylerFor: aString [ @@ -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 [ - + + "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 [ @@ -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 [ @@ -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 [ - + ^aString asText ]