From b5b531c2e847ee65308605595cbec437ee99e3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Mon, 10 Jun 2024 16:34:17 +0200 Subject: [PATCH] Adding InputFileFinder (without tests yes Yasser you will do them). Refactor the API fo ReferenceChecker (would be good to have some tests to validate the new layering). --- .../MicInputFileFinder.class.st | 27 +++++++++++++ .../MicReferenceChecker.class.st | 38 ++++++++++++++----- .../MicFileResourceReference.class.st | 2 +- src/Microdown/MicInputfileBlock.class.st | 5 ++- src/Microdown/MicZincPathResolver.class.st | 2 + src/Microdown/Microdown.class.st | 2 +- 6 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 src/Microdown-BookTester/MicInputFileFinder.class.st diff --git a/src/Microdown-BookTester/MicInputFileFinder.class.st b/src/Microdown-BookTester/MicInputFileFinder.class.st new file mode 100644 index 00000000..32d14a75 --- /dev/null +++ b/src/Microdown-BookTester/MicInputFileFinder.class.st @@ -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 +] diff --git a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st index 89c4356b..e6272dfa 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st @@ -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 diff --git a/src/Microdown/MicFileResourceReference.class.st b/src/Microdown/MicFileResourceReference.class.st index 8dc98c9c..ad2a8504 100644 --- a/src/Microdown/MicFileResourceReference.class.st +++ b/src/Microdown/MicFileResourceReference.class.st @@ -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 ] ] diff --git a/src/Microdown/MicInputfileBlock.class.st b/src/Microdown/MicInputfileBlock.class.st index c945f800..e80e0b85 100644 --- a/src/Microdown/MicInputfileBlock.class.st +++ b/src/Microdown/MicInputfileBlock.class.st @@ -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. ``. 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 diff --git a/src/Microdown/MicZincPathResolver.class.st b/src/Microdown/MicZincPathResolver.class.st index e37e22be..bd21b21b 100644 --- a/src/Microdown/MicZincPathResolver.class.st +++ b/src/Microdown/MicZincPathResolver.class.st @@ -67,6 +67,8 @@ MicZincPathResolver >> visitFigure: aFigure [ { #category : 'visiting' } MicZincPathResolver >> visitInputFile: anInputFile [ + + self resolveReferenceIn: anInputFile ] diff --git a/src/Microdown/Microdown.class.st b/src/Microdown/Microdown.class.st index 05540506..9fb1fff2 100644 --- a/src/Microdown/Microdown.class.st +++ b/src/Microdown/Microdown.class.st @@ -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