Renaming and PetitParser for YAML.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2020-10-21 18:40:05 -05:00
parent 321daf7165
commit 471353880e
2 changed files with 46 additions and 46 deletions

View File

@ -6,23 +6,23 @@ FossilRepo for that).
I can be used for other types of publications, like blog post though. I can be used for other types of publications, like blog post though.
" "
Class { Class {
#name : #BreaWikiPage, #name : #BreaPage,
#superclass : #Object, #superclass : #Object,
#instVars : [ #instVars : [
'shortName', 'shortName',
'template', 'template',
'templateData', 'templateData',
'namespace',
'bodyTag', 'bodyTag',
'splitters', 'splitters',
'subpages', 'subpages',
'metadata' 'metadata',
'folder'
], ],
#category : #Brea #category : #Brea
} }
{ #category : #operation } { #category : #operation }
BreaWikiPage >> bodyContentsAsHTML [ BreaPage >> bodyContentsAsHTML [
| sourcePage | | sourcePage |
self markdownFile ifNil: [ ^ self ]. self markdownFile ifNil: [ ^ self ].
sourcePage := FileLocator temp / 'wikiPage.md'. sourcePage := FileLocator temp / 'wikiPage.md'.
@ -31,12 +31,12 @@ BreaWikiPage >> bodyContentsAsHTML [
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> bodyTag [ BreaPage >> bodyTag [
^ bodyTag ^ bodyTag
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> bodyTag: aString [ BreaPage >> bodyTag: aString [
"I represent the Mustache Template tag used to denote the body part of a page. "I represent the Mustache Template tag used to denote the body part of a page.
While the metadata is self describing via YAML metadata blocks in Markddown, so While the metadata is self describing via YAML metadata blocks in Markddown, so
they map where ever they are needed in a template, the Markdown file that will be converted they map where ever they are needed in a template, the Markdown file that will be converted
@ -48,14 +48,14 @@ BreaWikiPage >> bodyTag: aString [
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> contents [ BreaPage >> contents [
| result | | result |
self markdownFile ifNil: [ ^ self ]. self markdownFile ifNil: [ ^ self ].
result := '' writeStream. result := '' writeStream.
result nextPutAll: self markdownFile contents. result nextPutAll: self markdownFile contents.
self subpages ifNotNil: [ self subpages ifNotNil: [
self subpages do: [ :sp | | markdownTempFile | self subpages do: [ :sp | | markdownTempFile |
markdownTempFile := self namespace / (sp, '.md'). markdownTempFile := self folder / (sp, '.md').
result nextPutAll: (Markdown fromFile: markdownTempFile) contents. result nextPutAll: (Markdown fromFile: markdownTempFile) contents.
] ]
]. ].
@ -63,7 +63,7 @@ BreaWikiPage >> contents [
] ]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> exportAsHTML [ BreaPage >> exportAsHTML [
| htmlContents allActions semaphore result | | htmlContents allActions semaphore result |
self shortName ifNil: [ ^ self ]. self shortName ifNil: [ ^ self ].
self template ifNil: [ ^ self ]. self template ifNil: [ ^ self ].
@ -80,50 +80,50 @@ BreaWikiPage >> exportAsHTML [
]. ].
semaphore wait. semaphore wait.
htmlContents := (MustacheTemplate on: result templateFile contents) value: result templateData. htmlContents := (MustacheTemplate on: result templateFile contents) value: result templateData.
^ MarkupFile exportAsFileOn: self namespace / (self shortName, '.html' ) containing: htmlContents ^ MarkupFile exportAsFileOn: self folder / (self shortName, '.html' ) containing: htmlContents
]
{ #category : #accessing }
BreaPage >> folder [
^ folder
]
{ #category : #accessing }
BreaPage >> folder: folderFileReference [
folder := folderFileReference
] ]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> htmlContents [ BreaPage >> htmlContents [
self shortName ifNil: [ ^ self ]. self shortName ifNil: [ ^ self ].
self template ifNil: [ ^ self ]. self template ifNil: [ ^ self ].
^ (MustacheTemplate on: self templateFile contents) value: self templateData. ^ (MustacheTemplate on: self templateFile contents) value: self templateData.
] ]
{ #category : #operation } { #category : #operation }
BreaWikiPage >> markdownFile [ BreaPage >> markdownFile [
| localFile | | localFile |
self namespace ifNil: [ ^ self ]. self folder ifNil: [ ^ self ].
self shortName ifNil: [ ^ self ]. self shortName ifNil: [ ^ self ].
localFile := self namespace / (self shortName, '.md'). localFile := self folder / (self shortName, '.md').
localFile exists ifFalse: [ ^ self ]. localFile exists ifFalse: [ ^ self ].
^ Markdown fromFile: localFile ^ Markdown fromFile: localFile
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> metadata [ BreaPage >> metadata [
^ metadata ^ metadata
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> metadata: aDictionary [ BreaPage >> metadata: aDictionary [
"External place where page metadata is located (on Internet or the local file system) in JSON format. "External place where page metadata is located (on Internet or the local file system) in JSON format.
If nil, is suposed that is placed in the Markdown file with the page contents." If nil, is suposed that is placed in the Markdown file with the page contents."
metadata := aDictionary metadata := aDictionary
] ]
{ #category : #accessing }
BreaWikiPage >> namespace [
^ namespace
]
{ #category : #accessing }
BreaWikiPage >> namespace: folderFileReference [
namespace := folderFileReference
]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> populateBodyAs: key [ BreaPage >> populateBodyAs: key [
| allActions result semaphore | | allActions result semaphore |
allActions := TKTFuture all: { allActions := TKTFuture all: {
[ self bodyContentsAsHTML ] future. [ self bodyContentsAsHTML ] future.
@ -138,13 +138,13 @@ BreaWikiPage >> populateBodyAs: key [
] ]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> populateExternalMetadata [ BreaPage >> populateExternalMetadata [
self metadata ifNil: [ ^ self ]. self metadata ifNil: [ ^ self ].
self self
] ]
{ #category : #operation } { #category : #operation }
BreaWikiPage >> populateMetadata [ BreaPage >> populateMetadata [
| metadataTemp | | metadataTemp |
self metadata self metadata
ifNotNil: [ metadataTemp := self metadata ] ifNotNil: [ metadataTemp := self metadata ]
@ -155,24 +155,24 @@ BreaWikiPage >> populateMetadata [
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> shortName [ BreaPage >> shortName [
^ shortName ^ shortName
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> shortName: aString [ BreaPage >> shortName: aString [
"The name of the file tha contains the light markup to produce the web page, without file extension. "The name of the file tha contains the light markup to produce the web page, without file extension.
By default I work with Markdown files." By default I work with Markdown files."
shortName := aString shortName := aString
] ]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> split [ BreaPage >> split [
self splitters keysAndValuesDo: [ :key :value | self split: key with: value ]. self splitters keysAndValuesDo: [ :key :value | self split: key with: value ].
] ]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> split: key with: subkey [ BreaPage >> split: key with: subkey [
"I split a comma separated collection of subkeys stored in the 'key' field and name each one as 'subkey' "I split a comma separated collection of subkeys stored in the 'key' field and name each one as 'subkey'
to put it indiviudally in a Mustache template." to put it indiviudally in a Mustache template."
| allSubkeys cleaned data | | allSubkeys cleaned data |
@ -185,58 +185,58 @@ BreaWikiPage >> split: key with: subkey [
] ]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> splitterAt: key with: subkey [ BreaPage >> splitterAt: key with: subkey [
self splitters at: key put: subkey self splitters at: key put: subkey
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> splitters [ BreaPage >> splitters [
^ splitters ifNil: [ splitters := Dictionary new ] ^ splitters ifNil: [ splitters := Dictionary new ]
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> splitters: aDictionary [ BreaPage >> splitters: aDictionary [
"I model the pattern where a Mustache template contains something like "I model the pattern where a Mustache template contains something like
{{# key}} {{value}} {{/ key}} and has data that needs to be split before injecting it in the template." {{# key}} {{value}} {{/ key}} and has data that needs to be split before injecting it in the template."
splitters := aDictionary splitters := aDictionary
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> subpages [ BreaPage >> subpages [
^ subpages ^ subpages
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> subpages: shortNamesList [ BreaPage >> subpages: shortNamesList [
"I am used when a page is composed of other subpages (for example with link aliases) that are shared "I am used when a page is composed of other subpages (for example with link aliases) that are shared
accross several pages." accross several pages."
subpages := shortNamesList subpages := shortNamesList
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> template [ BreaPage >> template [
^ template ^ template
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> template: mustacheFileName [ BreaPage >> template: mustacheFileName [
"Usually templates and their pages are located in the same folder." "Usually templates and their pages are located in the same folder."
template := mustacheFileName template := mustacheFileName
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> templateData [ BreaPage >> templateData [
^ templateData ifNil: [ templateData := Dictionary new ] ^ templateData ifNil: [ templateData := Dictionary new ]
] ]
{ #category : #accessing } { #category : #accessing }
BreaWikiPage >> templateData: aDictionary [ BreaPage >> templateData: aDictionary [
templateData := aDictionary templateData := aDictionary
] ]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
BreaWikiPage >> templateFile [ BreaPage >> templateFile [
self namespace ifNil: [ ^ self ]. self folder ifNil: [ ^ self ].
self template ifNil: [ ^ self ]. self template ifNil: [ ^ self ].
^ self namespace / self template ^ self folder / self template
] ]

View File

@ -9,5 +9,5 @@ Class {
{ #category : #'code-critics' } { #category : #'code-critics' }
ManifestBrea class >> ruleRBStringConcatenationRuleV1FalsePositive [ ManifestBrea class >> ruleRBStringConcatenationRuleV1FalsePositive [
^ #(#(#(#RGMethodDefinition #(#BreaWikiPage #contents #false)) #'2020-08-28T20:08:20.291489-05:00') ) ^ #(#(#(#RGMethodDefinition #(#BreaPage #contents #false)) #'2020-08-28T20:08:20.291489-05:00') )
] ]