diff --git a/repository/Brea/BreaFile.class.st b/repository/Brea/BreaFile.class.st new file mode 100644 index 0000000..2be7049 --- /dev/null +++ b/repository/Brea/BreaFile.class.st @@ -0,0 +1,71 @@ +" +I model the file where contents (data and/or metadata) for the Brea CSM pages are stored. +" +Class { + #name : #BreaFile, + #superclass : #Object, + #instVars : [ + 'folder', + 'name' + ], + #category : #Brea +} + +{ #category : #'instance creation' } +BreaFile class >> fromShortName: nameString andFolder: aFileLocation [ + "I create a new BreaFile assigning priorities to the filename discovery according to + their extension currently present in a particular folder." + | extensions | + + extensions := #('md' 'json' 'yaml'). + extensions do: [ :ext | | markupFile filename | + filename := nameString, '.', ext. + markupFile := aFileLocation / filename. + markupFile exists ifTrue: [ ^ self new name: filename; folder: aFileLocation ]. + ]. + ^ nil. +] + +{ #category : #accessing } +BreaFile >> contentString [ + + self name ifNil: [ ^ nil ]. + (self name endsWith: '.md') ifTrue: [ ^ self contents contents ]. + (self name endsWith: '.json') ifTrue: [ ^ self contents asString ]. +] + +{ #category : #accessing } +BreaFile >> contents [ + | file | + self name ifNil: [ ^ nil ]. + file := self folder / self name. + (self name endsWith: '.md') ifTrue: [ ^ Markdown fromFile: file ]. + (self name endsWith: '.json') ifTrue: [ ^ NeoJSONObject fromString: file contents ] +] + +{ #category : #accessing } +BreaFile >> folder [ + ^ folder +] + +{ #category : #accessing } +BreaFile >> folder: anObject [ + folder := anObject +] + +{ #category : #accessing } +BreaFile >> metadata [ + self name ifNil: [ ^ nil ]. + (self name endsWith: '.md') ifTrue: [ ^ self contents metadata ]. + (self name endsWith: '.md') ifTrue: [ ^ self contents at: 'metadata' ifAbsent: [ ^ nil ] ]. +] + +{ #category : #accessing } +BreaFile >> name [ + ^ name +] + +{ #category : #accessing } +BreaFile >> name: anObject [ + name := anObject +] diff --git a/repository/Brea/BreaPage.class.st b/repository/Brea/BreaPage.class.st index fd9f959..5c75984 100644 --- a/repository/Brea/BreaPage.class.st +++ b/repository/Brea/BreaPage.class.st @@ -16,7 +16,8 @@ Class { 'splitters', 'subpages', 'metadata', - 'folder' + 'folder', + 'file' ], #category : #Brea } @@ -24,7 +25,7 @@ Class { { #category : #operation } BreaPage >> bodyContentsAsHTML [ | sourcePage | - self markdownFile ifNil: [ ^ self ]. + self contentsFile ifNil: [ ^ self ]. sourcePage := FileLocator temp / 'wikiPage.md'. MarkupFile exportAsFileOn: sourcePage containing: self contents. ^ Pandoc markdownToHtml: sourcePage @@ -50,9 +51,9 @@ BreaPage >> bodyTag: aString [ { #category : #accessing } BreaPage >> contents [ | result | - self markdownFile ifNil: [ ^ self ]. + self contentsFile ifNil: [ ^ nil ]. result := '' writeStream. - result nextPutAll: self markdownFile contents. + result nextPutAll: self contentsFile contentString. self subpages ifNotNil: [ self subpages do: [ :sp | | markdownTempFile | markdownTempFile := self folder / (sp, '.md'). @@ -62,6 +63,14 @@ BreaPage >> contents [ ^ result contents. ] +{ #category : #operation } +BreaPage >> contentsFile [ + + self folder ifNil: [ ^ self ]. + self shortName ifNil: [ ^ self ]. + ^ BreaFile fromShortName: self shortName andFolder: self folder. +] + { #category : #'as yet unclassified' } BreaPage >> exportAsHTML [ | htmlContents allActions semaphore result | @@ -83,6 +92,16 @@ BreaPage >> exportAsHTML [ ^ MarkupFile exportAsFileOn: self folder / (self shortName, '.html' ) containing: htmlContents ] +{ #category : #accessing } +BreaPage >> file [ + ^ file +] + +{ #category : #accessing } +BreaPage >> file: anObject [ + file := anObject +] + { #category : #accessing } BreaPage >> folder [ ^ folder @@ -100,16 +119,6 @@ BreaPage >> htmlContents [ ^ (MustacheTemplate on: self templateFile contents) value: self templateData. ] -{ #category : #operation } -BreaPage >> markdownFile [ - | localFile | - self folder ifNil: [ ^ self ]. - self shortName ifNil: [ ^ self ]. - localFile := self folder / (self shortName, '.md'). - localFile exists ifFalse: [ ^ self ]. - ^ Markdown fromFile: localFile -] - { #category : #accessing } BreaPage >> metadata [ ^ metadata @@ -148,7 +157,7 @@ BreaPage >> populateMetadata [ | metadataTemp | self metadata ifNotNil: [ metadataTemp := self metadata ] - ifNil: [ metadataTemp := self markdownFile metadata]. + ifNil: [ metadataTemp := self contentsFile metadata]. metadataTemp keysAndValuesDo: [ :key :value | self templateData at: key put: value ]. ^ templateData diff --git a/repository/Brea/ManifestBrea.class.st b/repository/Brea/ManifestBrea.class.st index 85146e9..dc6527b 100644 --- a/repository/Brea/ManifestBrea.class.st +++ b/repository/Brea/ManifestBrea.class.st @@ -9,5 +9,5 @@ Class { { #category : #'code-critics' } ManifestBrea class >> ruleRBStringConcatenationRuleV1FalsePositive [ - ^ #(#(#(#RGMethodDefinition #(#BreaPage #contents #false)) #'2020-08-28T20:08:20.291489-05:00') ) + ^ #(#(#(#RGMethodDefinition #(#BreaPage #contents #false)) #'2020-08-28T20:08:20.291489-05:00') #(#(#RGMethodDefinition #(#BreaFile #fromShortName:andFolder: #false)) #'2020-11-06T20:59:12.94748-05:00') #(#(#RGMethodDefinition #(#'BreaFile class' #fromShortName:andFolder: #true)) #'2020-11-06T21:02:25.564981-05:00') ) ]