Skip to content

Commit

Permalink
Introduce some logic to support unsuccesful request in richtextrenderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Jul 28, 2020
1 parent 63eeb89 commit 181dd56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Pillar-ExporterRichText/PRRichTextComposer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ PRRichTextComposer putOffLine
In addition, images are cached to avoid multiple http requests.
The cache can be reset executing `PRRichTextComposer resetCache`. When the system is off line and an image is requested, a placeholder is computed but not put in the cache. This way when the system is put online the requested elements will be requested and put in the cache (without needing to flush placeholders from the cache).
When the system is online but the request failed we return a placeholder.
#### Known limits
Monospaced text (e.g., `Point`, `Point class`, `Point>>#setX:setY:`, or `#'Pillar-ExporterPillar'`) uses TextAction to trigger browser opening on the corresponding element. It would be better to use a TextLink because the styler is aware of them.
Expand Down Expand Up @@ -423,19 +421,29 @@ PRRichTextComposer >> imageFromUrl: aUrl [

^ OffLine
ifFalse: [
ImageCache
[ ImageCache
at: aUrl asString
ifAbsentPut: [ ZnEasy getPng: aUrl ] ]
ifAbsentPut: [ ZnEasy getPng: aUrl ]]
on: ZnHttpUnsuccessful
do: [ :ex | self imageOffLineFromUrl: aUrl ] ]
ifTrue: [
"we are off but the image is there so we return it,"
^ ImageCache
at: aUrl asString
ifPresent: [ :i | ^ i ]
ifAbsent: [ (StringMorph contents: 'In Offline mode!
When online, you should see: ' , aUrl asString) imageForm ]
self imageOffLineFromUrl: aUrl
]
]

{ #category : #'visiting - document' }
PRRichTextComposer >> imageOffLineFromUrl: aUrl [

"we are off but the image is there so we return it,"
^ ImageCache
at: aUrl asString
ifPresent: [ :i | i ]
ifAbsent: [ (StringMorph contents: 'In Offline mode!
When online, you should see: ' , aUrl asString) imageForm ]

]

{ #category : #initialization }
PRRichTextComposer >> initialize [
super initialize.
Expand Down
1 change: 1 addition & 0 deletions src/Pillar-ExporterRichText/PRRichTextWriterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ PRRichTextWriterTest >> superscriptFormat [

{ #category : #'tests - Format' }
PRRichTextWriterTest >> testBoldFormat [

self assertWriting: sample bold include: self boldFormat
]

Expand Down

0 comments on commit 181dd56

Please sign in to comment.