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

179 lines
5.5 KiB
Smalltalk
Raw Normal View History

"
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',
'manifests'
],
#category : #'Grafoscopio-Utils'
}
{ #category : #utilities }
2019-07-05 12:19:10 +00:00
PandocWork >> buildManifestFileForLanguage: anISOCode on: aFileName [
"anISOCode is the ISO 639-1 two letters language code"
| manifestFile |
2019-07-05 12:19:10 +00:00
manifestFile := (self rootFolder / anISOCode / 'manifests' / aFileName ) asFileReference ensureCreateFile.
self buildManifestForLanguage: 'es'.
GrafoscopioUtils exportAsSton: (self manifests at: anISOCode) on: manifestFile.
^ manifestFile
]
{ #category : #utlity }
PandocWork >> buildManifestForLanguage: anISOCode [
self
metadataManifestForLanguage: anISOCode;
contentsManifestForLanguage: anISOCode.
^ self manifests
]
{ #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 >> contentsManifest [
| 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 ].
^ self manifest
]
{ #category : #utilities }
PandocWork >> contentsManifestForLanguage: anISOCode [
| checksums |
checksums := OrderedDictionary new.
self contents keysDo: [ :folder |
(self contents at: folder) do: [ :fileName | | keyName contentFile |
keyName := fileName, self defaultFileExtension.
contentFile := self rootFolder / anISOCode / folder / keyName.
checksums at: keyName put: (GrafoscopioUtils checksumFor: contentFile)].
(self manifestForLanguage: anISOCode)
add: {folder -> checksums} asOrderedDictionary ].
^ self manifests at: anISOCode
]
{ #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 : #utlity }
PandocWork >> manifestForLanguage: anISOCode [
self manifests at: anISOCode ifAbsent: [
self manifests
at: anISOCode put: OrderedCollection new;
yourself].
^ self manifests at: anISOCode
]
{ #category : #accessing }
PandocWork >> manifests [
^ manifests ifNil: [ ^ manifests := OrderedDictionary new ]
]
{ #category : #accessing }
PandocWork >> manifests: anOrderedDictionary [
manifests := 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 : #utilities }
PandocWork >> metadataManifest [
| languageFolder |
languageFolder := self language.
"Could the similar parts of this and contentsManifest be refactored?"
self metadataFiles do: [ :fileName | | contentFile |
contentFile := self rootFolder / languageFolder / fileName.
self manifest at: languageFolder put: {fileName -> (GrafoscopioUtils checksumFor: contentFile)} asOrderedDictionary ].
^ self manifest
]
{ #category : #utilities }
PandocWork >> metadataManifestForLanguage: anISOCode [
"anISOCode is the ISO 639-1 two letters language code"
"Could the similar parts of this and contentsManifest be refactored?"
self metadataFiles do: [ :fileName | | contentFile |
contentFile := self rootFolder / anISOCode / fileName.
(self manifestForLanguage: anISOCode)
add: {fileName -> (GrafoscopioUtils checksumFor: contentFile)} asOrderedDictionary].
^ self manifests at: anISOCode
]
{ #category : #accessing }
PandocWork >> rootFolder [
^ rootFolder
]
{ #category : #accessing }
PandocWork >> rootFolder: aFileReference [
"I model the folder where the Markdown files are located."
rootFolder := aFileReference
]