GrafoscopioUtils/repository/Grafoscopio-Utils/PandocWork.class.st

119 lines
3.6 KiB
Smalltalk

"
I model a work (book, booklet, web page, etc) in Pandoc, its table of contents, its metadata file to
control exportation and other elements.
I can be used to improve reproductibility of published works that use Pandoc.
By default it is supposed that a root folder contains the set of folders, organized by
language (following the ISO 639-1 two letters convetion) where the contents of the work
and their translations are located.
Chapters, subchapters, sections and subsections are contained there as Markdown files
and its order is stated as a ordered dictionary for each language.
A YAML metadata block is used in each file to map translations between files and languages
and other sources, synchronizations and meta data.
"
Class {
#name : #PandocWork,
#superclass : #Object,
#instVars : [
'language',
'contents',
'metadataFiles',
'rootFolder',
'manifest'
],
#category : #'Grafoscopio-Utils'
}
{ #category : #utilities }
PandocWork >> buildManifest [
"I create a manifest, that lists all the files which are needed to create a
derivate file (PDF, EPUB, etc) with their checksums and folder locations.
I can be used to associated derivated files with their sources."
| checksums |
checksums := OrderedDictionary new.
self contents keysDo: [ :folder |
(self contents at: folder) do: [ :fileName | | keyName contentFile |
keyName := fileName, self defaultFileExtension.
contentFile := self rootFolder / self language / folder / keyName.
checksums at: keyName put: (GrafoscopioUtils checksumFor: contentFile)].
self manifest at: folder put: checksums ].
]
{ #category : #accessing }
PandocWork >> contents [
^ contents
]
{ #category : #accessing }
PandocWork >> contents: anOrderedDictionary [
"I model the table of contents of the work.
The key of the dictionary is the folder, inside the language folder (see the language variable)
where the files are stored, and the value is and ordered collection of the files on such folder
which are part ot the exported result, without the file extension (by default is supposed to be '.md')"
contents := anOrderedDictionary
]
{ #category : #utilities }
PandocWork >> defaultFileExtension [
^ '.md'
]
{ #category : #accessing }
PandocWork >> language [
^ language
]
{ #category : #accessing }
PandocWork >> language: aISOLangString [
"I model the lanaguage of a work as a ISO 639-1 two letters string.
I used to stablish the folder where the content is stored, following the convention a folder
by language."
language := aISOLangString
]
{ #category : #accessing }
PandocWork >> manifest [
"I create a manifest, that lists all the files which are needed to create a
derivate file (PDF, EPUB, etc) with their checksums and folder locations.
I can be used to associated derivated files with their sources."
^ manifest ifNil: [ ^ manifest := OrderedDictionary new ]
]
{ #category : #accessing }
PandocWork >> manifest: anOrderedDictionary [
manifest := anOrderedDictionary
]
{ #category : #accessing }
PandocWork >> metadataFiles [
^ metadataFiles
]
{ #category : #accessing }
PandocWork >> metadataFiles: aCollection [
"I model the YAML metadata files that are used to control the output of the exportation.
I can have several files, controlling several outputs, one for PDF, one for HTML, one for EPUB
and so on.
This should be stated in the name of the metadatafile and by default will be controlling PDF
output."
metadataFiles := aCollection
]
{ #category : #accessing }
PandocWork >> rootFolder [
^ rootFolder
]
{ #category : #accessing }
PandocWork >> rootFolder: aFileReference [
"I model the folder where the Markdown files are located."
rootFolder := aFileReference
]