Starting support for json data files.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2020-11-07 10:24:01 -05:00
parent c11c00b7d1
commit cd938cf480
3 changed files with 96 additions and 16 deletions

View File

@ -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
]

View File

@ -16,7 +16,8 @@ Class {
'splitters', 'splitters',
'subpages', 'subpages',
'metadata', 'metadata',
'folder' 'folder',
'file'
], ],
#category : #Brea #category : #Brea
} }
@ -24,7 +25,7 @@ Class {
{ #category : #operation } { #category : #operation }
BreaPage >> bodyContentsAsHTML [ BreaPage >> bodyContentsAsHTML [
| sourcePage | | sourcePage |
self markdownFile ifNil: [ ^ self ]. self contentsFile ifNil: [ ^ self ].
sourcePage := FileLocator temp / 'wikiPage.md'. sourcePage := FileLocator temp / 'wikiPage.md'.
MarkupFile exportAsFileOn: sourcePage containing: self contents. MarkupFile exportAsFileOn: sourcePage containing: self contents.
^ Pandoc markdownToHtml: sourcePage ^ Pandoc markdownToHtml: sourcePage
@ -50,9 +51,9 @@ BreaPage >> bodyTag: aString [
{ #category : #accessing } { #category : #accessing }
BreaPage >> contents [ BreaPage >> contents [
| result | | result |
self markdownFile ifNil: [ ^ self ]. self contentsFile ifNil: [ ^ nil ].
result := '' writeStream. result := '' writeStream.
result nextPutAll: self markdownFile contents. result nextPutAll: self contentsFile contentString.
self subpages ifNotNil: [ self subpages ifNotNil: [
self subpages do: [ :sp | | markdownTempFile | self subpages do: [ :sp | | markdownTempFile |
markdownTempFile := self folder / (sp, '.md'). markdownTempFile := self folder / (sp, '.md').
@ -62,6 +63,14 @@ BreaPage >> contents [
^ result 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' } { #category : #'as yet unclassified' }
BreaPage >> exportAsHTML [ BreaPage >> exportAsHTML [
| htmlContents allActions semaphore result | | htmlContents allActions semaphore result |
@ -83,6 +92,16 @@ BreaPage >> exportAsHTML [
^ MarkupFile exportAsFileOn: self folder / (self shortName, '.html' ) containing: htmlContents ^ MarkupFile exportAsFileOn: self folder / (self shortName, '.html' ) containing: htmlContents
] ]
{ #category : #accessing }
BreaPage >> file [
^ file
]
{ #category : #accessing }
BreaPage >> file: anObject [
file := anObject
]
{ #category : #accessing } { #category : #accessing }
BreaPage >> folder [ BreaPage >> folder [
^ folder ^ folder
@ -100,16 +119,6 @@ BreaPage >> htmlContents [
^ (MustacheTemplate on: self templateFile contents) value: self templateData. ^ (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 } { #category : #accessing }
BreaPage >> metadata [ BreaPage >> metadata [
^ metadata ^ metadata
@ -148,7 +157,7 @@ BreaPage >> populateMetadata [
| metadataTemp | | metadataTemp |
self metadata self metadata
ifNotNil: [ metadataTemp := self metadata ] ifNotNil: [ metadataTemp := self metadata ]
ifNil: [ metadataTemp := self markdownFile metadata]. ifNil: [ metadataTemp := self contentsFile metadata].
metadataTemp keysAndValuesDo: [ :key :value | metadataTemp keysAndValuesDo: [ :key :value |
self templateData at: key put: value ]. self templateData at: key put: value ].
^ templateData ^ templateData

View File

@ -9,5 +9,5 @@ Class {
{ #category : #'code-critics' } { #category : #'code-critics' }
ManifestBrea class >> ruleRBStringConcatenationRuleV1FalsePositive [ 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') )
] ]