Skip to content

Commit 25638f4

Browse files
authored
Merge pull request #19 from sarahtathy/sarah-branch
correct the method MDFile>>save: withExtension:
2 parents ad4fdcf + 6c996d3 commit 25638f4

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

src/MicroEd-Spec-Tests/MDEditorFilePresenterTest.class.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ MDEditorFilePresenterTest >> setUp [
2727
presenter := MDEditorPresenter new.
2828
window := presenter open.
2929
text := 'This is just a test'.
30-
fileReference := memoryFS / 'aFileReference.txt'.
30+
fileReference := memoryFS / 'aFileReference.md'.
3131
fileReference writeStreamDo: [
3232
:stream | stream nextPutAll: text ].
3333

@@ -96,6 +96,7 @@ MDEditorFilePresenterTest >> testSaveWithExtension [
9696
| text textPresenter |
9797
text := 'This is just a test'.
9898
textPresenter := self mockTextObject: text.
99+
presenter textInputText: text.
99100
presenter mdFile: mdFile.
100101
presenter saveFile.
101102

src/MicroEd-Spec/MDEditorPresenter.class.st

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ MDEditorPresenter >> cleanOutput [
5252
textOutput text: ''
5353
]
5454

55-
{ #category : 'specs' }
55+
{ #category : 'layout' }
5656
MDEditorPresenter >> defaultLayout [
5757

5858
^ SpBoxLayout newTopToBottom
@@ -160,8 +160,7 @@ MDEditorPresenter >> mdFile [
160160
{ #category : 'accessing' }
161161
MDEditorPresenter >> mdFile: aMDFile [
162162

163-
mdFile := aMDFile.
164-
textInput text: mdFile contents
163+
mdFile := aMDFile.
165164
]
166165

167166
{ #category : 'utilities' }
@@ -208,7 +207,7 @@ MDEditorPresenter >> saveFile [
208207
self mdFile: (self mdFile
209208
save: textInput text asString
210209
withExtension: syntaxState extension).
211-
self updateTitle.
210+
self window ifNotNil: [self updateTitle].
212211

213212
]
214213

@@ -226,7 +225,7 @@ MDEditorPresenter >> startNewFile [
226225

227226
self cleanInput.
228227
mdFile := MDFile new.
229-
self updateTitle
228+
self window ifNotNil: [ self updateTitle ]
230229
]
231230

232231
{ #category : 'accessing' }

src/MicroEd-Tests/MDFileTest.class.st

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ MDFileTest >> setUp [
1919
memoryFS := FileSystem memory.
2020
toDelete := OrderedCollection new.
2121
fileWithoutFileReference := MDFile new.
22-
fileExample := memoryFS / 'example.txt'.
23-
fileReferenceWithName := (memoryFS / 'anotherFile.txt')
22+
fileExample := memoryFS / 'example.md'.
23+
fileReferenceWithName := (memoryFS / 'anotherFile.md')
2424
ensureCreateFile.
2525
toDelete add: fileExample.
2626
fileExample writeStreamDo: [ :stream |
@@ -58,11 +58,11 @@ MDFileTest >> testMDFileExistingFileWithName [
5858

5959
| file fileReferenceWithoutName |
6060

61-
fileReferenceWithoutName := (memoryFS / 'name.txt') ensureCreateFile.
61+
fileReferenceWithoutName := (memoryFS / 'name.md') ensureCreateFile.
6262
toDelete add: fileReferenceWithoutName.
6363
file := MDFile new.
6464
file initializeWithFileReference: fileReferenceWithoutName.
65-
self assert: (file basename endsWith: 'name.txt').
65+
self assert: (file basename endsWith: 'name.md').
6666

6767

6868
]
@@ -72,7 +72,7 @@ MDFileTest >> testMDFileExistingFileWithoutName [
7272

7373
| file fileReferenceWithoutName |
7474

75-
fileReferenceWithoutName := (memoryFS / '.txt') ensureCreateFile.
75+
fileReferenceWithoutName := (memoryFS / '.md') ensureCreateFile.
7676
toDelete add: fileReferenceWithoutName.
7777
file := MDFile new.
7878
file initializeWithFileReference: fileReferenceWithoutName.
@@ -86,5 +86,6 @@ MDFileTest >> testMDFileHasFileReferenceWithFormatISO [
8686
| file date |
8787
file := MDFile newFromFileReference: fileReferenceWithName.
8888
date := DateAndTime now asDate yyyymmdd.
89-
self assert: (file basename includesSubstring: date)
89+
self assert: (file basename includesSubstring: date).
90+
self deny: (fileReferenceWithName exists )
9091
]

src/MicroEd-Tests/MDMicroDownSyntaxTest.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Class {
1212
MDMicroDownSyntaxTest >> testGotExtensionWhenIsNotSpecify [
1313

1414
syntax := MDMicroDownSyntax new.
15-
self assert: syntax extension equals: 'mic'
15+
self assert: syntax extension equals: 'md'
1616
]
1717

1818
{ #category : 'tests' }

src/MicroEd/MDFile.class.st

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MDFile >> basename [
2424
"Answer a String representing the receiver's file name"
2525

2626
| dateCreationOfFileReference |
27-
fileReference ifNil: [ ^ 'Untitled.txt' ].
27+
fileReference ifNil: [ ^ 'Untitled.md' ].
2828
dateCreationOfFileReference := DateAndTime now asDate yyyymmdd.
2929
(fileReference basename includesSubstring:
3030
dateCreationOfFileReference) ifFalse: [
@@ -63,6 +63,12 @@ MDFile >> extension: anExtension [
6363
fileReference extension: anExtension
6464
]
6565

66+
{ #category : 'accessing' }
67+
MDFile >> fileReference [
68+
69+
^ fileReference
70+
]
71+
6672
{ #category : 'accessing' }
6773
MDFile >> hasFile [
6874

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

7278
{ #category : 'accessing' }
7379
MDFile >> initializeWithFileReference: aFileReference [
80+
"Add a file reference in the MDFile"
7481

82+
| newFileReference |
7583
aFileReference ensureCreateFile.
76-
fileReference := aFileReference
84+
fileReference := aFileReference.
85+
"Create of a new file reference which has the ISO format with the default extension: 'md' "
86+
newFileReference := fileReference extension isEmptyOrNil
87+
ifTrue: [
88+
(self basename , '.md') ]
89+
ifFalse: [
90+
self basename ].
91+
aFileReference delete.
92+
93+
fileReference := newFileReference asFileReference.
94+
fileReference ensureCreateFile.
7795
]
7896

7997
{ #category : 'accessing' }
8098
MDFile >> save: aString withExtension: anExtension [
81-
99+
" before put the file reference, ensure that the creation of the basename is set (without the renaming)
100+
fileReference extension = anExtension asString ifFalse: [
101+
fileReference renameTo:
102+
self basename , '.' , anExtension asString ]. "
82103
fileReference asFileReference writeStreamDo: [ :str |
83104
str
84105
nextPutAll: aString ].
85-
fileReference extension = anExtension asString ifFalse: [
86-
fileReference renameTo:
87-
fileReference withoutExtension basename , '.' , anExtension asString ].
106+
107+
88108

89109
]

0 commit comments

Comments
 (0)