From b7fb4c12a8581ba1bad23a982a5081fc3458fa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Sun, 4 Feb 2024 21:08:36 +0100 Subject: [PATCH] Move to BeautifulComments helper methods of buildMicroDownUsing... --- src/BeautifulComments/Class.extension.st | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/BeautifulComments/Class.extension.st b/src/BeautifulComments/Class.extension.st index 1d3ab4e..c4c5ce3 100644 --- a/src/BeautifulComments/Class.extension.st +++ b/src/BeautifulComments/Class.extension.st @@ -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 [ @@ -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' +]