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 #16176 from jecisc/16171-BeautifulComment-should-b…
…e-managed-inside-Pharo Integrate BeautifulComments directly into Pharo
- Loading branch information
Showing
14 changed files
with
826 additions
and
34 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
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
93 changes: 93 additions & 0 deletions
93
src/BeautifulComments/BCBeautifulCommentsSettingsTest.class.st
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,93 @@ | ||
" | ||
This class test that two settings CaptureErrors and Rendering works as intended | ||
" | ||
Class { | ||
#name : 'BCBeautifulCommentsSettingsTest', | ||
#superclass : 'TestCase', | ||
#instVars : [ | ||
'subject' | ||
], | ||
#category : 'BeautifulComments-Tests', | ||
#package : 'BeautifulComments', | ||
#tag : 'Tests' | ||
} | ||
|
||
{ #category : 'running' } | ||
BCBeautifulCommentsSettingsTest >> setUp [ | ||
super setUp. | ||
|
||
subject := BeautifulComments. | ||
BCFailingOnPurposeForTestBlock failOnPurpose: true | ||
] | ||
|
||
{ #category : 'running' } | ||
BCBeautifulCommentsSettingsTest >> tearDown [ | ||
|
||
BCFailingOnPurposeForTestBlock failOnPurpose: false. | ||
super tearDown | ||
] | ||
|
||
{ #category : 'tests' } | ||
BCBeautifulCommentsSettingsTest >> testErrorCatch [ | ||
"Chech that capture errors is working is working when true" | ||
| comment capturing| | ||
capturing := subject captureErrors. | ||
subject captureErrors: true. | ||
comment := subject | ||
renderComment: BCFailingOnPurposeForTestBlock comment | ||
of: self class.. | ||
subject captureErrors: capturing | ||
] | ||
|
||
{ #category : 'tests' } | ||
BCBeautifulCommentsSettingsTest >> testNoErrorCatch [ | ||
"Chech that capture errors is working is working when true" | ||
| capturing| | ||
capturing := subject captureErrors. | ||
subject captureErrors: false. | ||
self | ||
should: [ | ||
subject | ||
renderComment: BCFailingOnPurposeForTestBlock comment | ||
of: self class] | ||
raise: BCFailingOnPurposeForTestError . | ||
subject captureErrors: capturing | ||
] | ||
|
||
{ #category : 'tests' } | ||
BCBeautifulCommentsSettingsTest >> testNotRenderingOfMyOwnComment [ | ||
"Chech that rendering is working when false" | ||
| comment rendering| | ||
rendering := subject rendering. | ||
subject rendering: false. | ||
comment := subject | ||
renderComment: self class comment | ||
of: self class. | ||
self assert: comment isString. | ||
self deny: comment isText. | ||
self assert: (comment asString beginsWith: '# BCBeautifulCommentsSettingsTest'). | ||
self assert: (comment asString includesSubstring: '## Description | ||
This class test that two settings CaptureErrors and Rendering works as intended'). | ||
subject rendering: rendering | ||
] | ||
|
||
{ #category : 'tests' } | ||
BCBeautifulCommentsSettingsTest >> testRenderingOfMyOwnComment [ | ||
"Chech that rendering is working when true" | ||
| comment rendering| | ||
rendering := subject rendering. | ||
subject rendering: true. | ||
comment := subject | ||
renderComment: self class comment | ||
of: self class. | ||
self assert: comment isText. | ||
self assert: (comment asString beginsWith: 'BCBeautifulCommentsSettingsTest'). | ||
self assert: (comment asString includesSubstring: 'This class test that two settings CaptureErrors and Rendering works as intended'). | ||
subject rendering: rendering | ||
] | ||
|
||
{ #category : 'tests' } | ||
BCBeautifulCommentsSettingsTest >> testThereAreTwoSettings [ | ||
"I am an approximation, just making sure the two class variables exist" | ||
self assert: subject classVarNames equals: #(CaptureErrors Rendering) | ||
] |
37 changes: 37 additions & 0 deletions
37
src/BeautifulComments/BCFailingOnPurposeForTestBlock.class.st
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,37 @@ | ||
" | ||
I am a comment which cannot be rendered correctly - I use a dedicated error to fail. | ||
Toggle Edit/View comment to see how this is done. | ||
{!failingOnPurpose!} | ||
" | ||
Class { | ||
#name : 'BCFailingOnPurposeForTestBlock', | ||
#superclass : 'MicAnnotationBlock', | ||
#classVars : [ | ||
'FailOnPurpose' | ||
], | ||
#category : 'BeautifulComments-Tests', | ||
#package : 'BeautifulComments', | ||
#tag : 'Tests' | ||
} | ||
|
||
{ #category : 'accessing' } | ||
BCFailingOnPurposeForTestBlock class >> failOnPurpose [ | ||
FailOnPurpose ifNil: [ FailOnPurpose := false ]. | ||
^ FailOnPurpose | ||
] | ||
|
||
{ #category : 'accessing' } | ||
BCFailingOnPurposeForTestBlock class >> failOnPurpose: aBoolean [ | ||
FailOnPurpose := aBoolean | ||
] | ||
|
||
{ #category : 'accessing' } | ||
BCFailingOnPurposeForTestBlock class >> tag [ | ||
^ #failingOnPurpose | ||
] | ||
|
||
{ #category : 'visiting' } | ||
BCFailingOnPurposeForTestBlock >> accept: aVisitor [ | ||
self class failOnPurpose | ||
ifTrue: [ BCFailingOnPurposeForTestError signal ] | ||
] |
10 changes: 10 additions & 0 deletions
10
src/BeautifulComments/BCFailingOnPurposeForTestError.class.st
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,10 @@ | ||
" | ||
I am a dedicated error used to check the the CaptureErrors setting is working as intended | ||
" | ||
Class { | ||
#name : 'BCFailingOnPurposeForTestError', | ||
#superclass : 'Error', | ||
#category : 'BeautifulComments-Tests', | ||
#package : 'BeautifulComments', | ||
#tag : '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,101 @@ | ||
" | ||
I hold preferences for the BeautifulComments (in class variables and methods on my class side). | ||
## Settings | ||
- In particular one can disable rich text rendering (showing the raw comments of the class), which is done in the settings browser `rendering`, or through my class side method `render: aBoolean`. | ||
- As per fall of 2021 microdown and microdown support in Pharo is still in active development. Errors can occour! It is possible to set the comment to be robust to errors in the microdown in class comments. This is controlled by the `capture errors`, or through the class side method: 'captureErrors: aBoolean`. | ||
" | ||
Class { | ||
#name : 'BeautifulComments', | ||
#superclass : 'Object', | ||
#classVars : [ | ||
'CaptureErrors', | ||
'Rendering' | ||
], | ||
#category : 'BeautifulComments-Core', | ||
#package : 'BeautifulComments', | ||
#tag : 'Core' | ||
} | ||
|
||
{ #category : 'settings' } | ||
BeautifulComments class >> beautifulCommentsSettingsOn: aBuilder [ | ||
"These settings are added to the settings defined in Microdown>>preferencesSettingsOn:" | ||
<systemsettings> | ||
(aBuilder setting: #rendering) | ||
parent: #microdownAndcomments; | ||
label: 'Enable richtext comments'; | ||
default: true; | ||
target: self; | ||
description: self renderingDocForSetting. | ||
(aBuilder setting: #captureErrors) | ||
parent: #microdownAndcomments; | ||
label: 'Enable rendering error capture'; | ||
default: true; | ||
target: self; | ||
description: self captureErrorsDocForSetting | ||
] | ||
|
||
{ #category : 'settings' } | ||
BeautifulComments class >> captureErrors [ | ||
^ CaptureErrors ifNil: [ CaptureErrors := true ] | ||
] | ||
|
||
{ #category : 'settings' } | ||
BeautifulComments class >> captureErrors: aBoolean [ | ||
CaptureErrors := aBoolean | ||
] | ||
|
||
{ #category : 'settings' } | ||
BeautifulComments class >> captureErrorsDocForSetting [ | ||
|
||
^ 'By default microdown errors in comment text will not cause debugger to open. Turn this of to get debugger to open on errors' | ||
] | ||
|
||
{ #category : 'rendering' } | ||
BeautifulComments class >> render: aString [ | ||
"Render a string, in case of error, just return it." | ||
|composer| | ||
composer := self richTextComposer. | ||
self rendering | ||
ifFalse: [ ^ aString ]. | ||
self captureErrors | ||
ifFalse: [ ^ composer asRichText: aString ]. | ||
^ [ composer asRichText: aString ] | ||
on: Error | ||
do: [ aString ] | ||
] | ||
|
||
{ #category : 'rendering' } | ||
BeautifulComments class >> renderComment: aString of: aClassOrPackage [ | ||
"Return aString as part of the templated class comment, when rendering is on. | ||
Else aString." | ||
|
||
| builder | | ||
builder := Microdown builder. | ||
aClassOrPackage buildMicroDownUsing: builder withComment: aString. | ||
^ self render: builder contents | ||
] | ||
|
||
{ #category : 'settings' } | ||
BeautifulComments class >> rendering [ | ||
^ Rendering ifNil: [ true ] | ||
] | ||
|
||
{ #category : 'rendering' } | ||
BeautifulComments class >> rendering: aBoolean [ | ||
Rendering := aBoolean | ||
] | ||
|
||
{ #category : 'settings' } | ||
BeautifulComments class >> renderingDocForSetting [ | ||
|
||
^ 'Comments are by default rendered via microdown. When this setting is on, they are rendered as plain string (showing their Microdown definitions).' | ||
] | ||
|
||
{ #category : 'rendering' } | ||
BeautifulComments class >> richTextComposer [ | ||
^ MicRichTextComposer new | ||
textStyler: BeautifulCommentsTextStyler new; | ||
yourself. | ||
] |
25 changes: 25 additions & 0 deletions
25
src/BeautifulComments/BeautifulCommentsTextStyler.class.st
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,25 @@ | ||
" | ||
I define the parameters of rich text styling for comments. I change two things compared to the standard text styling: | ||
- I use smaller fonts for the headers | ||
- I keep newlines in paragraphs | ||
" | ||
Class { | ||
#name : 'BeautifulCommentsTextStyler', | ||
#superclass : 'MicTextStyler', | ||
#category : 'BeautifulComments-UI', | ||
#package : 'BeautifulComments', | ||
#tag : 'UI' | ||
} | ||
|
||
{ #category : 'public' } | ||
BeautifulCommentsTextStyler >> headerFontSizes [ | ||
^ #(18 16 14 12 11 10) | ||
] | ||
|
||
{ #category : 'composer styles' } | ||
BeautifulCommentsTextStyler >> postTextTreatment: aText [ | ||
"See comment in superclass - keep newlines in paragraphs" | ||
^ aText | ||
|
||
] |
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,48 @@ | ||
" | ||
I implement the toggle edit/view comment in the lower right corner of the class comment pane. | ||
I can be activated by the keyboard shortcut defined in `ClyRichTextClassCommentEditorToolMorph>>buildTextMorph` - command-r | ||
![](https://user-images.githubusercontent.com/17723745/138033718-94ec6db8-f6e3-45fd-93e5-7722261ebc41.png) | ||
" | ||
Class { | ||
#name : 'ClyEditCommentSwitchMorph', | ||
#superclass : 'ClyStatusBarItemMorph', | ||
#instVars : [ | ||
'checkbox' | ||
], | ||
#category : 'BeautifulComments-Core', | ||
#package : 'BeautifulComments', | ||
#tag : 'Core' | ||
} | ||
|
||
{ #category : 'building' } | ||
ClyEditCommentSwitchMorph >> build [ | ||
|
||
checkbox := CheckboxMorph | ||
on: self selected: #status changeSelected: #toggle. | ||
checkbox | ||
getLabelSelector: #definitionTypeLabel; | ||
labelClickable: true; | ||
vResizing: #shrinkWrap; | ||
hResizing: #shrinkWrap; | ||
setBalloonText: 'Click me to edit comment'. | ||
self addMorph: checkbox | ||
] | ||
|
||
{ #category : 'accessing' } | ||
ClyEditCommentSwitchMorph >> definitionTypeLabel [ | ||
^ 'Toggle Edit / View comment' | ||
] | ||
|
||
{ #category : 'building' } | ||
ClyEditCommentSwitchMorph >> status [ | ||
|
||
^ ownerTool isRendering | ||
] | ||
|
||
{ #category : 'operations' } | ||
ClyEditCommentSwitchMorph >> toggle [ | ||
ownerTool toggleMode. | ||
ownerTool update | ||
] |
Oops, something went wrong.