Skip to content

Commit

Permalink
Merge pull request #19 from sarahtathy/sarah-branch
Browse files Browse the repository at this point in the history
correct the method MDFile>>save: withExtension:
  • Loading branch information
Ducasse authored Aug 1, 2024
2 parents ad4fdcf + 6c996d3 commit 25638f4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/MicroEd-Spec-Tests/MDEditorFilePresenterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MDEditorFilePresenterTest >> setUp [
presenter := MDEditorPresenter new.
window := presenter open.
text := 'This is just a test'.
fileReference := memoryFS / 'aFileReference.txt'.
fileReference := memoryFS / 'aFileReference.md'.
fileReference writeStreamDo: [
:stream | stream nextPutAll: text ].

Expand Down Expand Up @@ -96,6 +96,7 @@ MDEditorFilePresenterTest >> testSaveWithExtension [
| text textPresenter |
text := 'This is just a test'.
textPresenter := self mockTextObject: text.
presenter textInputText: text.
presenter mdFile: mdFile.
presenter saveFile.

Expand Down
9 changes: 4 additions & 5 deletions src/MicroEd-Spec/MDEditorPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ MDEditorPresenter >> cleanOutput [
textOutput text: ''
]

{ #category : 'specs' }
{ #category : 'layout' }
MDEditorPresenter >> defaultLayout [

^ SpBoxLayout newTopToBottom
Expand Down Expand Up @@ -160,8 +160,7 @@ MDEditorPresenter >> mdFile [
{ #category : 'accessing' }
MDEditorPresenter >> mdFile: aMDFile [

mdFile := aMDFile.
textInput text: mdFile contents
mdFile := aMDFile.
]

{ #category : 'utilities' }
Expand Down Expand Up @@ -208,7 +207,7 @@ MDEditorPresenter >> saveFile [
self mdFile: (self mdFile
save: textInput text asString
withExtension: syntaxState extension).
self updateTitle.
self window ifNotNil: [self updateTitle].

]

Expand All @@ -226,7 +225,7 @@ MDEditorPresenter >> startNewFile [

self cleanInput.
mdFile := MDFile new.
self updateTitle
self window ifNotNil: [ self updateTitle ]
]

{ #category : 'accessing' }
Expand Down
13 changes: 7 additions & 6 deletions src/MicroEd-Tests/MDFileTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ MDFileTest >> setUp [
memoryFS := FileSystem memory.
toDelete := OrderedCollection new.
fileWithoutFileReference := MDFile new.
fileExample := memoryFS / 'example.txt'.
fileReferenceWithName := (memoryFS / 'anotherFile.txt')
fileExample := memoryFS / 'example.md'.
fileReferenceWithName := (memoryFS / 'anotherFile.md')
ensureCreateFile.
toDelete add: fileExample.
fileExample writeStreamDo: [ :stream |
Expand Down Expand Up @@ -58,11 +58,11 @@ MDFileTest >> testMDFileExistingFileWithName [

| file fileReferenceWithoutName |

fileReferenceWithoutName := (memoryFS / 'name.txt') ensureCreateFile.
fileReferenceWithoutName := (memoryFS / 'name.md') ensureCreateFile.
toDelete add: fileReferenceWithoutName.
file := MDFile new.
file initializeWithFileReference: fileReferenceWithoutName.
self assert: (file basename endsWith: 'name.txt').
self assert: (file basename endsWith: 'name.md').


]
Expand All @@ -72,7 +72,7 @@ MDFileTest >> testMDFileExistingFileWithoutName [

| file fileReferenceWithoutName |

fileReferenceWithoutName := (memoryFS / '.txt') ensureCreateFile.
fileReferenceWithoutName := (memoryFS / '.md') ensureCreateFile.
toDelete add: fileReferenceWithoutName.
file := MDFile new.
file initializeWithFileReference: fileReferenceWithoutName.
Expand All @@ -86,5 +86,6 @@ MDFileTest >> testMDFileHasFileReferenceWithFormatISO [
| file date |
file := MDFile newFromFileReference: fileReferenceWithName.
date := DateAndTime now asDate yyyymmdd.
self assert: (file basename includesSubstring: date)
self assert: (file basename includesSubstring: date).
self deny: (fileReferenceWithName exists )
]
2 changes: 1 addition & 1 deletion src/MicroEd-Tests/MDMicroDownSyntaxTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Class {
MDMicroDownSyntaxTest >> testGotExtensionWhenIsNotSpecify [

syntax := MDMicroDownSyntax new.
self assert: syntax extension equals: 'mic'
self assert: syntax extension equals: 'md'
]

{ #category : 'tests' }
Expand Down
32 changes: 26 additions & 6 deletions src/MicroEd/MDFile.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MDFile >> basename [
"Answer a String representing the receiver's file name"

| dateCreationOfFileReference |
fileReference ifNil: [ ^ 'Untitled.txt' ].
fileReference ifNil: [ ^ 'Untitled.md' ].
dateCreationOfFileReference := DateAndTime now asDate yyyymmdd.
(fileReference basename includesSubstring:
dateCreationOfFileReference) ifFalse: [
Expand Down Expand Up @@ -63,6 +63,12 @@ MDFile >> extension: anExtension [
fileReference extension: anExtension
]

{ #category : 'accessing' }
MDFile >> fileReference [

^ fileReference
]

{ #category : 'accessing' }
MDFile >> hasFile [

Expand All @@ -71,19 +77,33 @@ MDFile >> hasFile [

{ #category : 'accessing' }
MDFile >> initializeWithFileReference: aFileReference [
"Add a file reference in the MDFile"

| newFileReference |
aFileReference ensureCreateFile.
fileReference := aFileReference
fileReference := aFileReference.
"Create of a new file reference which has the ISO format with the default extension: 'md' "
newFileReference := fileReference extension isEmptyOrNil
ifTrue: [
(self basename , '.md') ]
ifFalse: [
self basename ].
aFileReference delete.

fileReference := newFileReference asFileReference.
fileReference ensureCreateFile.
]

{ #category : 'accessing' }
MDFile >> save: aString withExtension: anExtension [

" before put the file reference, ensure that the creation of the basename is set (without the renaming)
fileReference extension = anExtension asString ifFalse: [
fileReference renameTo:
self basename , '.' , anExtension asString ]. "
fileReference asFileReference writeStreamDo: [ :str |
str
nextPutAll: aString ].
fileReference extension = anExtension asString ifFalse: [
fileReference renameTo:
fileReference withoutExtension basename , '.' , anExtension asString ].



]

0 comments on commit 25638f4

Please sign in to comment.