Skip to content

Commit

Permalink
Merge pull request #47 from pillar-markup/getBuildMicroDownUsing
Browse files Browse the repository at this point in the history
Move to BeautifulComments helper methods of buildMicroDownUsing...
  • Loading branch information
Ducasse authored Feb 4, 2024
2 parents adc2440 + b7fb4c1 commit a6be295
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/BeautifulComments/Class.extension.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
Extension { #name : 'Class' }

{ #category : '*BeautifulComments' }
Class >> addDocumentSectionExampleCodeTo: aBuilder [

| exampleCode |
exampleCode := self documentExampleCode.
exampleCode ifNil: [ ^ self ].

aBuilder newLine.
aBuilder header: [ :builder | builder text: 'Example code' ] withLevel: 2.
aBuilder newLine.
aBuilder codeblock: exampleCode
]

{ #category : '*BeautifulComments' }
Class >> addDocumentSectionTo: aBuilder label: label methods: methods [

methods ifEmpty: [ ^ self ].

aBuilder newLine.
aBuilder header: [ :builder | builder text: label ] withLevel: 2.
aBuilder unorderedListDuring: [
(methods sorted: #selector ascending) do: [ :each |
aBuilder item: [
aBuilder monospace: (each methodClass name, '>>#', each selector) ] ] ]
]

{ #category : '*BeautifulComments' }
Class >> buildMicroDownUsing: aBuilder withComment: aString [

Expand All @@ -16,3 +42,32 @@ Class >> buildMicroDownUsing: aBuilder withComment: aString [
label: 'Examples'
methods: (self class methods select: [ :each | each protocol = self documentExamplesProtocol ])
]

{ #category : '*BeautifulComments' }
Class >> documentExampleCode [
| exampleMethod |

exampleMethod := self class methods
detect: [ :each |
(each protocol = self documentExamplesProtocol)
and: [ self documentExampleCodeSelector match: each selector match ] ]
ifNone: [ ^ nil ].

^ (exampleMethod sourceCode lines
allButFirst "Remove method name"
reject: [ :each | each trimLeft beginsWith: '<' ]) "Remove pragmas"
asStringWithCr
trimmed
]

{ #category : '*BeautifulComments' }
Class >> documentExampleCodeSelector [

^ 'example*'
]

{ #category : '*BeautifulComments' }
Class >> documentExamplesProtocol [

^ #'*Examples'
]

0 comments on commit a6be295

Please sign in to comment.