Skip to content

Commit

Permalink
Adding InputFileFinder (without tests yes Yasser you will do them).
Browse files Browse the repository at this point in the history
Refactor the API fo ReferenceChecker (would be good to have some tests to validate the new layering).
  • Loading branch information
Ducasse committed Jun 10, 2024
1 parent 650e971 commit b5b531c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
27 changes: 27 additions & 0 deletions src/Microdown-BookTester/MicInputFileFinder.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Class {
#name : 'MicInputFileFinder',
#superclass : 'MicrodownVisitor',
#instVars : [
'allFiles'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
}

{ #category : 'accessing' }
MicInputFileFinder >> allFiles [
^ allFiles
]

{ #category : 'initialization' }
MicInputFileFinder >> initialize [

super initialize.
allFiles := OrderedCollection new.
]

{ #category : 'initialization' }
MicInputFileFinder >> visitInputFile: anInputFile [

allFiles add: anInputFile
]
38 changes: 29 additions & 9 deletions src/Microdown-ReferenceChecker/MicReferenceChecker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,45 @@ Class {
#package : 'Microdown-ReferenceChecker'
}

{ #category : 'visiting' }
MicReferenceChecker >> check: aDocument [
"Pay attention checking a file in isolation is DIFFERENT from a list, because document
can have references between them and the checker should be shared amongst the documents
since it collects the references."

aDocument accept: self.
^ self isOk



]

{ #category : 'visiting' }
MicReferenceChecker >> checkDirectory: aDir [
"Take the directory, parse all its children with microdown file parser and let the visitor visit each time then return visitor is ok which should be true if every thing is okay, the visitor turned out to treat the many documents that it visits as one, so if anchor is duplicated in another file it will detect that . "

| parsedFile |
aDir allFiles do: [ :each |
(parsedFile := Microdown parseFile: each) accept: self.
].
^ self isOk

^ self checkList: aDir allFiles
]

{ #category : 'visiting' }
MicReferenceChecker >> checkFile: aFile [
"Will parse the given file and invite the visitor and return visitor isOk value"

| parsedFile |
parsedFile := Microdown parseFile: aFile.
parsedFile accept: self.
| document |
document := Microdown parseFile: aFile.
^ self check: document



]

{ #category : 'visiting' }
MicReferenceChecker >> checkList: aCollection [
"Pay attention checking a file in isolation is DIFFERENT from a list, because document
can have references between them and the checker should be shared amongst the documents
since it collects the references."

aCollection do: [ :each | self check: each ].
^ self isOk


Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicFileResourceReference.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ MicFileResourceReference >> isMicrodownResourceFileReference [

{ #category : 'accessing' }
MicFileResourceReference >> loadChildren [
"return a collection of MifResourceReferences if I am a directory, empty if I am not a directory"
"return a collection of MicResourceReferences if I am a directory, empty if I am not a directory"
self isDirectory ifFalse: [ ^ #() ].
^ self fileReference children
select: [ :child | child isDirectory or: [ #(md mic) includes: child extension ] ]
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown/MicInputfileBlock.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"
I handle an input file.
Note that I should start on a new line but I can end on the same line. So I may look like an inline element but I'm a block one.
I handle an input file e.g. `<!inputFile|path=Chapters/withStyle.md!>`. I should start on a new line but I can end on the same line. So I may look like an inline element but I'm a block one.

Note that my path can be resolved (See asMicResourceReference and MicFileResourceReference for more information how to resolve my path), when resolved the message `reference` return the resolved path (i.e. to go from a relative to an absolute paths).

```text
<!inputFile|path=Chapters/withStyle.md!>
Expand Down
2 changes: 2 additions & 0 deletions src/Microdown/MicZincPathResolver.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ MicZincPathResolver >> visitFigure: aFigure [

{ #category : 'visiting' }
MicZincPathResolver >> visitInputFile: anInputFile [


self resolveReferenceIn: anInputFile
]

Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/Microdown.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Microdown >> parse: aStreamOrString [
Microdown >> parseFile: aFile [

|root|
root := MicrodownParser parse: aFile contents.
root := MicrodownParser parse: aFile contents.
root fromFile: aFile fullName.
^ root

Expand Down

0 comments on commit b5b531c

Please sign in to comment.