Skip to content
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

Integrate BeautifulComments directly into Pharo #16176

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/BaselineOfIDE/BaselineOfIDE.class.st
Expand Up @@ -126,7 +126,7 @@ BaselineOfIDE >> baseline: spec [
self newTools: spec.
self drTests: spec.
self microdown: spec.
self beautifulComments: spec.
spec package: #'BeautifulComments' with: [ spec requires: #( 'Microdown') ].
self documentBrowserCore: spec.
self welcomeBrowser: spec.
self roassal: spec.
Expand All @@ -136,13 +136,6 @@ BaselineOfIDE >> baseline: spec [
spec package: 'Kernel-ExtraUtils' ]
]

{ #category : 'baselines - dependencies' }
BaselineOfIDE >> beautifulComments: spec [

spec baseline: 'BeautifulComments' with: [
spec repository: (self class environment at: #BaselineOfPharo) beautifulCommentsRepository ]
]

{ #category : 'baselines - dependencies' }
BaselineOfIDE >> documentBrowserCore: spec [

Expand Down Expand Up @@ -219,7 +212,6 @@ BaselineOfIDE >> loadIceberg [
self registerProject: 'NewTools'.
self registerProject: 'Roassal'.
self registerProject: 'Microdown'.
self registerProject: 'BeautifulComments'.
self registerProject: 'DocumentBrowser' baseline: 'NewToolsDocumentBrowser' otherBaselines: #().
self registerProject: 'WelcomeBrowser'.
self registerIceberg
Expand Down
17 changes: 0 additions & 17 deletions src/BaselineOfPharo/BaselineOfPharo.class.st
Expand Up @@ -12,23 +12,6 @@ Class {
#tag : 'Base'
}

{ #category : 'accessing - external projects' }
BaselineOfPharo class >> beautifulComments [
<externalProject>

^ PharoExternalProject
newName: 'BeautifulComments'
owner: 'pillar-markup'
project: 'BeautifulComments'
version: 'Pharo12'
]

{ #category : 'repository urls' }
BaselineOfPharo class >> beautifulCommentsRepository [

^ (self externalProjectNamed: 'BeautifulComments') repository
]

{ #category : 'private' }
BaselineOfPharo class >> declareExternalProjects [

Expand Down
93 changes: 93 additions & 0 deletions src/BeautifulComments/BCBeautifulCommentsSettingsTest.class.st
@@ -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 src/BeautifulComments/BCFailingOnPurposeForTestBlock.class.st
@@ -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 src/BeautifulComments/BCFailingOnPurposeForTestError.class.st
@@ -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'
}
101 changes: 101 additions & 0 deletions src/BeautifulComments/BeautifulComments.class.st
@@ -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 src/BeautifulComments/BeautifulCommentsTextStyler.class.st
@@ -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

]
48 changes: 48 additions & 0 deletions src/BeautifulComments/ClyEditCommentSwitchMorph.class.st
@@ -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
]