Skip to content

Commit

Permalink
Merge pull request #735 from Ducasse/replaceBy
Browse files Browse the repository at this point in the history
Replace by
  • Loading branch information
Ducasse authored May 13, 2024
2 parents f921db5 + 5d94b2b commit 50cbda3
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 31 deletions.
31 changes: 16 additions & 15 deletions src/Microdown-BeamerExporter-Tests/MicBeamerWriterTest.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Class {
#name : #MicBeamerWriterTest,
#superclass : #MicLaTeXWriterTest,
#category : #'Microdown-BeamerExporter-Tests'
#name : 'MicBeamerWriterTest',
#superclass : 'MicLaTeXWriterTest',
#category : 'Microdown-BeamerExporter-Tests',
#package : 'Microdown-BeamerExporter-Tests'
}

{ #category : #tests }
{ #category : 'tests' }
MicBeamerWriterTest class >> testParameters [

^ ParametrizedTestMatrix new
Expand All @@ -15,12 +16,12 @@ MicBeamerWriterTest class >> testParameters [
yourself
]

{ #category : #running }
{ #category : 'running' }
MicBeamerWriterTest >> actualClass [
^ MicBeamerWriter
]

{ #category : #tests }
{ #category : 'tests' }
MicBeamerWriterTest >> testCode [

self writeFor: (factory codeblockNoParamBody: 'this is a code').
Expand All @@ -29,7 +30,7 @@ MicBeamerWriterTest >> testCode [
'\end{listing}', newLine
]

{ #category : #tests }
{ #category : 'tests' }
MicBeamerWriterTest >> testCodeWithCaption [

self writeFor: (factory codeblock: 'caption=Pharo is **cool**' body: 'this is a code').
Expand All @@ -38,7 +39,7 @@ MicBeamerWriterTest >> testCodeWithCaption [
'\end{listing}', newLine
]

{ #category : #tests }
{ #category : 'tests' }
MicBeamerWriterTest >> testCodeWithLabel [

self writeFor: (factory codeblock: 'label=Pharo' body: 'this is a code').
Expand All @@ -47,7 +48,7 @@ MicBeamerWriterTest >> testCodeWithLabel [
'\end{listing}', newLine
]

{ #category : #tests }
{ #category : 'tests' }
MicBeamerWriterTest >> testColumn [

self writeFor: (factory columnSample).
Expand All @@ -56,15 +57,15 @@ MicBeamerWriterTest >> testColumn [
'\end{column}', newLine, newLine
]

{ #category : #tests }
{ #category : 'tests' }
MicBeamerWriterTest >> testColumns [

self writeFor: (factory columnsSample).
self assert: writer contents equals:'\begin{columns}', newLine ,
'\end{columns}', newLine , newLine
]

{ #category : #tests }
{ #category : 'tests' }
MicBeamerWriterTest >> testColumnsWithChildren [

self writeFor: factory columnsWithChildrenSample.
Expand All @@ -78,7 +79,7 @@ MicBeamerWriterTest >> testColumnsWithChildren [
'\end{columns}', newLine , newLine
]

{ #category : #'tests - figure/link' }
{ #category : 'tests - figure/link' }
MicBeamerWriterTest >> testFigure [

self writeFor: factory figureSample.
Expand All @@ -87,7 +88,7 @@ MicBeamerWriterTest >> testFigure [
'\includegraphics[width=0.8\textwidth]{/anUrl}\end{center}', newLine, newLine
]

{ #category : #'tests - figure/link' }
{ #category : 'tests - figure/link' }
MicBeamerWriterTest >> testFigureBold [
"in beamer we do not display caption so bld and the rest goes away."
self writeFor: factory figureBoldSample.
Expand All @@ -96,7 +97,7 @@ MicBeamerWriterTest >> testFigureBold [
'\includegraphics[width=0.8\textwidth]{/anUrl}\end{center}', newLine , newLine
]

{ #category : #'tests - figure/link' }
{ #category : 'tests - figure/link' }
MicBeamerWriterTest >> testFigureRealSample [

self writeFor: factory figureRealSample.
Expand All @@ -105,7 +106,7 @@ MicBeamerWriterTest >> testFigureRealSample [
'\includegraphics[width=0.8\textwidth]{figures/logo.png}\end{center}', newLine , newLine
]

{ #category : #tests }
{ #category : 'tests' }
MicBeamerWriterTest >> testFrameWithoutOption [

self
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Class {
#name : 'MicMicrodownToSlideTest',
#superclass : 'TestCase',
#category : 'Microdown-BeamerExporter-Tests',
#package : 'Microdown-BeamerExporter-Tests'
}

{ #category : 'tests' }
MicMicrodownToSlideTest >> testSectionLevelOneIsMapToSlide [

| doc slide |
doc := MicrodownParser new parse: '# Slide title
- item 1
- item 2
'.
MicMicrodownToSlideVisitor new visit: doc.
slide := doc children first.
self assert: slide class equals: MicSlideBlock.
self assert: slide title equals: 'Slide title'.
self assert: doc children second class equals: MicUnorderedListBlock.


]

{ #category : 'tests' }
MicMicrodownToSlideTest >> testSlideGotCorrectParent [

| doc slide |
doc := MicrodownParser new parse: '# Slide title
- item 1
- item 2
'.
self assert: doc children size equals: 2.
MicMicrodownToSlideVisitor new visit: doc.
slide := doc children first.
self assert: slide parent equals: doc.
self assert: doc children size equals: 2

]
2 changes: 1 addition & 1 deletion src/Microdown-BeamerExporter-Tests/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Microdown-BeamerExporter-Tests' }
Package { #name : 'Microdown-BeamerExporter-Tests' }
13 changes: 13 additions & 0 deletions src/Microdown-BeamerExporter/MicMicrodownToSlideVisitor.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Class {
#name : 'MicMicrodownToSlideVisitor',
#superclass : 'MicrodownVisitor',
#category : 'Microdown-BeamerExporter',
#package : 'Microdown-BeamerExporter'
}

{ #category : 'visiting' }
MicMicrodownToSlideVisitor >> visitHeader: aHeader [

aHeader parent replace: aHeader by: (MicSlideBlock new title: aHeader header)

]
20 changes: 20 additions & 0 deletions src/Microdown-Tests/MicrodownTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,23 @@ MicrodownTest >> testParentBackLinkIsSet [
self assert: h children first equals: t.
self assert: t parent equals: h
]

{ #category : 'tests - replace' }
MicrodownTest >> testParentLinkIsKeptOnReplaceBy [

| h original new |
h := MicHeaderBlock new.
original := MicTextBlock new.
original bodyString: 'Original'.
original parent: h.
self assert: original parent equals: h.
self assert: h children first equals: original.
new := MicTextBlock new.
new bodyString: 'New'.

original replaceBy: new.
self assert: h children size equals: 1.
self assert: h children first equals: new.
self assert: new parent equals: h.

]
15 changes: 6 additions & 9 deletions src/Microdown/MicAbstractBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,17 @@ MicAbstractBlock >> parserClass [
]

{ #category : 'replacement' }
MicAbstractBlock >> replace: aBlock by: anotherBlock [
MicAbstractBlock >> replace: aMicElement by: anotherMicElement [

children replaceAll: aBlock with: anotherBlock
self children replaceAll: aMicElement with: anotherMicElement.
aMicElement basicParent: nil.
anotherMicElement basicParent: self.
]

{ #category : 'replacement' }
MicAbstractBlock >> replace: aBlock byCollection: aCollection [
MicAbstractBlock >> replace: aMicElement byCollection: aCollection [

children := children copyReplaceAll: {aBlock} with: aCollection
]

{ #category : 'replacement' }
MicAbstractBlock >> replaceBy: anotherBlock [
self parent replace: self by: anotherBlock
children := children copyReplaceAll: {aMicElement} with: aCollection
]

{ #category : 'replacement' }
Expand Down
15 changes: 11 additions & 4 deletions src/Microdown/MicArgumentList.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ MicArgumentList class >> split: aString defaultArg: defArg [
{ #category : 'instance creation' }
MicArgumentList class >> split: aString defaultArg: defArg defaultValue: defValue [
^ self new
defaultArg: defArg;
at: defArg put: defValue;
initialValue: defValue;
from: aString;
split: aString defaultArg: defArg defaultValue: defValue;
yourself
]

Expand Down Expand Up @@ -188,6 +185,16 @@ MicArgumentList >> setNoDefaultButArguments: string [

]

{ #category : 'initialization' }
MicArgumentList >> split: aString defaultArg: defArg defaultValue: defValue [

self
defaultArg: defArg;
at: defArg put: defValue;
initialValue: defValue;
from: aString
]

{ #category : 'copying' }
MicArgumentList >> withoutDefaultValue [
"remove the defaultArg if no new value was assigned to it"
Expand Down
12 changes: 12 additions & 0 deletions src/Microdown/MicElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ MicElement >> removeProperty: aKey ifAbsent: aBlock [
^ answer
]

{ #category : 'replacement' }
MicElement >> replaceBy: aMicElement [
"Replace the receiver by the argument.
Make sure that the new element parent is the parent of the receiver."

parent replace: self by: aMicElement.
"We use basicParent and not parent,
because parent is doing an addChild:"
aMicElement basicParent: parent.
parent := nil.
]

{ #category : 'public' }
MicElement >> resolveFrom: aBase [
Microdown resolveDocument: self withBase: aBase
Expand Down
8 changes: 8 additions & 0 deletions src/Microdown/MicEnvironmentBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ MicEnvironmentBlock >> extractFirstLineFrom: aLine [
ifFalse: [ firstLine ]
]

{ #category : 'parse support' }
MicEnvironmentBlock >> initialize [

super initialize.
arguments := MicArgumentList new

]

{ #category : 'markups' }
MicEnvironmentBlock >> lineStartMarkup [

Expand Down
6 changes: 6 additions & 0 deletions src/Microdown/MicEvaluatedBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ MicEvaluatedBlock >> printOn: stream [

]

{ #category : 'replacement' }
MicEvaluatedBlock >> replace: aBlock by: anotherBlock [

self children replaceAll: aBlock with: anotherBlock
]

{ #category : 'accessing' }
MicEvaluatedBlock >> textElement [
"Should only be used for tests"
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown/MicHeaderBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ MicHeaderBlock >> formattedCode [
{ #category : 'accessing' }
MicHeaderBlock >> header [
"I am used to get an adhoc string for the header"
^ String streamContents: [ :s |
children do: [ :e | s nextPutAll: e bodystring ] ]

^ String streamContents: [ :s |
children do: [ :e | s nextPutAll: e bodyString ] ]
]

{ #category : 'accessing' }
Expand Down
8 changes: 8 additions & 0 deletions src/Microdown/MicSlideBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ to have the same slide but on two different layouts and not emit both.
- bullet 3
!>
```
It should be noted that the title is not reified as a Microdown object because so far the extensions does not support a way to describe the argument that should be reified.
"
Class {
#name : 'MicSlideBlock',
Expand Down Expand Up @@ -46,3 +48,9 @@ MicSlideBlock >> tag [
MicSlideBlock >> title [
^ arguments at: 'title' ifAbsent: [ '' ]
]

{ #category : 'accessing' }
MicSlideBlock >> title: aString [

arguments at: #title put: aString
]

0 comments on commit 50cbda3

Please sign in to comment.