148 lines
3.8 KiB
Smalltalk
148 lines
3.8 KiB
Smalltalk
Extension { #name : #LePage }
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> asHtmlFile [
|
|
|
|
self asMarkdownFile.
|
|
self defaultPandocTemplate exists
|
|
ifFalse: [ MarkupFile installTemplate: 'https://mutabit.com/repos.fossil/mutabit/doc/trunk/plantillas/Pandoc/clean-menu-mod.html' into: self defaultPandocTemplate parent ].
|
|
|
|
OSSUnixSubprocess new
|
|
command: 'pandoc' ;
|
|
arguments: {
|
|
self markdownFileName. '-o'. self htmlFileName .
|
|
'--toc' .
|
|
'--template=', self defaultPandocTemplate basenameWithoutExtension };
|
|
workingDirectory: self storage fullName;
|
|
runAndWaitOnExitDo: [ :process :outString | ^ self storage / self htmlFileName].
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> asMarkdeep [
|
|
| bodyStream markdeep |
|
|
bodyStream := '' writeStream.
|
|
self preorderTraversal do: [:snippet |
|
|
bodyStream nextPutAll: snippet asMarkdeep
|
|
].
|
|
markdeep := Markdeep new
|
|
title: self title;
|
|
body: bodyStream contents;
|
|
navTop: self navTop.
|
|
self metadata keysAndValuesDo: [:k :v |
|
|
k = 'lang'
|
|
ifTrue: [
|
|
markdeep head
|
|
add: '<meta lang="', v,'">';
|
|
yourself.
|
|
]
|
|
ifFalse: [
|
|
markdeep head
|
|
add: '<meta name="', k, '" content="', v,'">';
|
|
yourself.
|
|
]
|
|
].
|
|
self metadata at: 'authors' ifPresent: [:author | markdeep metadata at: 'authors' put: author ].
|
|
self metadata at: 'version' ifPresent: [:version | markdeep metadata at: 'version' put: version ].
|
|
^ markdeep.
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> asMarkdeepFile [
|
|
| folder |
|
|
folder := self options at: 'storage' ifAbsent: [ FileLocator temp ].
|
|
^ self asMarkdeep exportAsFileOn: folder / self markdeepFileName
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> asMarkdown [
|
|
| bodyStream markdown |
|
|
bodyStream := '' writeStream.
|
|
bodyStream
|
|
nextPutAll: '---';
|
|
nextPutAll: String lf.
|
|
self metadata keysAndValuesDo: [ :k :v |
|
|
bodyStream
|
|
nextPutAll: k , ': ' , v;
|
|
nextPutAll: String lf ].
|
|
bodyStream nextPutAll: '---' , String lf , String lf.
|
|
self preorderTraversal
|
|
do: [ :snippet | bodyStream nextPutAll: snippet asMarkdown ].
|
|
markdown := Markdown new contents: bodyStream contents.
|
|
^ markdown
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> asMarkdownFile [
|
|
| folder |
|
|
folder := self options at: 'storage' ifAbsent: [ FileLocator temp ].
|
|
^ MarkupFile exportAsFileOn: folder / self markdownFileName containing: self asMarkdown contents
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> defaultPandocTemplate [
|
|
|
|
^ FileLocator home / '.pandoc' / 'templates' / 'clean-menu-mod.html'
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> exportedFileName [
|
|
| sanitized |
|
|
sanitized := self title asDashedLowercase copyWithoutAll: #($/).
|
|
^ sanitized , '--' , (self uidString copyFrom: 1 to: 5)
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> htmlFileName [
|
|
^ self exportedFileName, '.html'
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> markdeepFileName [
|
|
|
|
^ self markdownFileName , '.html'
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> markdownFileName [
|
|
^ self exportedFileName, '.md'
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> metadata [
|
|
|
|
^ self options at: 'metadata' ifAbsentPut: [ self metadataInit]
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> metadataInit [
|
|
|
|
^ OrderedDictionary new
|
|
at: 'id' put: self uidString;
|
|
at: 'title' put: self contentAsString;
|
|
at: 'created' put: self createTime greaseString;
|
|
at: 'modified' put: self latestEditTime greaseString;
|
|
at: 'creator' put: self createEmail greaseString;
|
|
at: 'modifier' put: self editEmail greaseString;
|
|
yourself
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> options [
|
|
^ options
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> preorderTraversal [
|
|
| output |
|
|
output := OrderedCollection new.
|
|
self withDeepCollect: [:each | each allChildrenBreadthFirstDo: [:child | output add: child]].
|
|
^ output.
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePage >> storage [
|
|
|
|
^ self optionAt: 'storage'
|
|
ifAbsent: [ ^ FileLocator temp ]
|
|
]
|