From bda316a44f2fa9ed6adf37316d6c9fe45c50f937 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Thu, 13 Jun 2024 16:48:49 +0200 Subject: [PATCH] fix css link in a file in a different folder level --- .../MicBlogCreatorTest.class.st | 22 ++++++------- src/Microdown-Blog/MicBlogCreator.class.st | 32 +++++++++++++++---- .../MicCSSEntity.class.st | 6 ++++ 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st index e8d90817..704795c9 100644 --- a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st @@ -9,10 +9,10 @@ Class { #package : 'Microdown-Blog-Tests' } -{ #category : 'as yet unclassified' } +{ #category : 'initialization' } MicBlogCreatorTest >> fileContent1 [ -^ '{ + ^ '{ "date" : "8 January 2019" } # A Cool Story @@ -21,11 +21,10 @@ Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No Amazing debugging experience: The Pharo environment includes a debugger unlike anything you''ve seen before. It allows you to step through code, restart the execution of methods, create methods on the fly, and much more! -' - +' ] -{ #category : 'as yet unclassified' } +{ #category : 'initialization' } MicBlogCreatorTest >> fileContent2 [ ^ '{ @@ -41,7 +40,7 @@ Pharo is a pure _object-oriented programming language_ in the tradition of Small ] -{ #category : 'as yet unclassified' } +{ #category : 'initialization' } MicBlogCreatorTest >> fileContent3 [ ^ '{ @@ -59,7 +58,7 @@ When you participate to the mooc you get access to the quizz and the credit vali ' ] -{ #category : 'as yet unclassified' } +{ #category : 'initialization' } MicBlogCreatorTest >> generateArchitecture [ | ref1 ref2 ref3 ref4 | @@ -81,7 +80,7 @@ MicBlogCreatorTest >> generateArchitecture [ ref4 writeStreamDo: [ :stream | stream nextPutAll: 'Du java' ] ] -{ #category : 'as yet unclassified' } +{ #category : 'initialization' } MicBlogCreatorTest >> listOfFile [ ^ (fileSystem / 'source') allFiles @@ -144,7 +143,7 @@ MicBlogCreatorTest >> testCreateAllHtmlFile [ { #category : 'tests' } MicBlogCreatorTest >> testCreateFromTo [ - | allFile nbMonthFile | + | allFile nbMonthFile nbCSSFile| MicBlogCreator createFrom: fileSystem / 'source' to: fileSystem / 'html'. @@ -152,8 +151,9 @@ MicBlogCreatorTest >> testCreateFromTo [ allFile := (fileSystem / 'html') allFiles. nbMonthFile := (Date today year - 2014) * 12 + Date today month index. + nbCSSFile := 1. - self assert: allFile size equals: 5 + nbMonthFile + self assert: allFile size equals: 5 + nbMonthFile + nbCSSFile ] { #category : 'tests' } @@ -251,7 +251,7 @@ MicBlogCreatorTest >> testWriteToNamed [ root := Microdown parse: file contents. html := (MicHTMLVisitor new visit: root) at: 1. - MicBlogCreator new + blog write: html to: fileSystem / 'html' named: 'test.html'. diff --git a/src/Microdown-Blog/MicBlogCreator.class.st b/src/Microdown-Blog/MicBlogCreator.class.st index 16455d12..0bd2b85b 100644 --- a/src/Microdown-Blog/MicBlogCreator.class.st +++ b/src/Microdown-Blog/MicBlogCreator.class.st @@ -172,18 +172,17 @@ MicBlogCreator >> dateList: aDateList [ dateList := aDateList. ] -{ #category : 'as yet unclassified' } +{ #category : 'css' } MicBlogCreator >> downloadCSS [ | a | - targetDirectory fileSystem / 'css'. + (targetDirectory / 'css') ensureCreateDirectory. a := MicCSSProvider new. a findCssNamed: cssFrameworkName; - destinationPath: - '/Users/qmout/Documents/Pharo/images/Microdown/output/html/css'. + destinationPath: targetDirectory / 'css'. a cssDownloader downloadCSSFramework: - (MicCSSProvider forCSSNamed: 'Axist') + (MicCSSProvider forCSSNamed: cssFrameworkName) ] { #category : 'initialization' } @@ -193,6 +192,20 @@ MicBlogCreator >> initialize [ self cssFrameworkName: 'Axist'. ] +{ #category : 'as yet unclassified' } +MicBlogCreator >> levelPathDifferenceForCSS: aStringPath [ + + | result string | + string := aStringPath copyReplaceAll: '\' with: '/'. + + result := ''. + + 2 to: (string substrings: '/') size do: [ :each | + result := result , '../' ]. + + ^ result +] + { #category : 'rendering' } MicBlogCreator >> renameMarkdownIntoHtmlFile: aFileReference [ @@ -237,15 +250,20 @@ MicBlogCreator >> targetDirectory: arg1 [ { #category : 'rendering' } MicBlogCreator >> write: aMicHTMLVisitor to: aPath named: aName [ - | htmlDocument fileName| + | htmlDocument fileName cssFramework | fileName := aName withoutPrefix: '/'. fileName := fileName withoutPrefix: '\'. + + cssFramework := MicCSSProvider forCSSNamed: cssFrameworkName. + cssFramework basePath: + (self levelPathDifferenceForCSS: fileName) , 'css/'. + htmlDocument := MicHTMLDocument new. htmlDocument configuration: aMicHTMLVisitor configuration. htmlDocument configuration document: htmlDocument. htmlDocument setCharSetUTF8; - addCSSNamed: cssFrameworkName; + addCSS: cssFramework; destinationPath: aPath. ^ htmlDocument fileName: fileName; diff --git a/src/Microdown-HTMLExporter/MicCSSEntity.class.st b/src/Microdown-HTMLExporter/MicCSSEntity.class.st index a2a875e2..c4e91cc3 100644 --- a/src/Microdown-HTMLExporter/MicCSSEntity.class.st +++ b/src/Microdown-HTMLExporter/MicCSSEntity.class.st @@ -35,6 +35,12 @@ MicCSSEntity >> basePath [ ifNil: [ basePath := self defaultBasePath ] ] +{ #category : 'defaults' } +MicCSSEntity >> basePath: anObject [ + + basePath := anObject +] + { #category : 'accessing' } MicCSSEntity >> cssFile [ "Answer the receiver's "