Cleaning markdown exportation.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2017-02-02 22:00:40 +00:00
parent d475287b8e
commit 6bf0ec7e00
6 changed files with 145 additions and 25 deletions

View File

@ -24,7 +24,7 @@ GrafoscopioDocumentation class >> current [
gfcDocumentation repository: (FossilRepo new url: 'http://mutabit.com/repos.fossil/grafoscopio').
gfcDocumentation documents
add: 'Docs/Es/Tutoriales/tutorial.ston';
add: 'Docs/Es/Manual/manual-grafoscopio.ston';
add: 'Docs/En/Books/Manual/manual.ston';
add: 'Docs/En/dev-notes.ston'.
gfcDocumentation localPlace.
^ gfcDocumentation

View File

@ -452,8 +452,9 @@ GrafoscopioGUI class >> startDockingBar [
helpMenu := MenuMorph new.
helpMenu
add: 'Tutorial (Spanish)' target: (GrafoscopioNotebook new) selector: #openTutorial;
add: 'Manual' target: (self new) selector: #openManual;
add: 'Manual' target: (GrafoscopioNotebook new) selector: #openManual;
add: 'Manual (PDF)' target: (self new) selector: #openPDFManual;
add: 'Dev''s notes' target: (GrafoscopioNotebook new) selector: #openDevNotes;
add: 'About Grafoscopio' target: self selector: #messageAbout.
dockingBar := DockingBarMorph new.

View File

@ -302,7 +302,8 @@ GrafoscopioNode >> deleteReferencesToRoot: aRootNode [
{ #category : #movement }
GrafoscopioNode >> demote [
"Moves the current node down in the hierachy, making a children of its current previous slibing"
"I move the current node down in the hierachy, making it a children of its current previous
slibing"
| collection index predecessor |
collection := self parent children.
@ -316,6 +317,16 @@ GrafoscopioNode >> demote [
{ #category : #exporting }
GrafoscopioNode >> exportCodeBlockTo: aStream [
"I convert the content of a node taged as 'código' (code) as pandoc markdown and put it
into aStream."
aStream nextPutAll: ('~~~'); lf.
aStream nextPutAll: (self body contents asString withInternetLineEndings); lf.
aStream nextPutAll: ('~~~'); lf.
^aStream contents
]
{ #category : #exporting }
GrafoscopioNode >> exportDecoratedCodeBlockTo: aStream [
"I convert the content of a node taged as 'código' (code) as pandoc markdown and put it
into aStream.
The code block is decorated with LaTeX commands for proper syntax highlighting using pygments.
@ -326,15 +337,26 @@ GrafoscopioNode >> exportCodeBlockTo: aStream [
^aStream contents
]
{ #category : #exporting }
GrafoscopioNode >> exportPreambleOldTo: aStream [
"comment stating purpose of message"
| configDict |
(self header = '%config')
ifTrue: [
configDict := STON fromString: (self body).
aStream nextPutAll: 'title: ', (configDict at: 'title'); lf.
aStream nextPutAll: 'author: ', ((configDict at: 'author') at: 'given'), ' ', ((configDict at: 'author') at: 'family'); lf.
aStream nextPutAll: 'bibliography: ', (configDict at: 'bibliography'); lf.
aStream nextPutAll: 'abstract: ', '|'; lf; nextPutAll: (configDict at: 'abstract'); lf.
].
aStream nextPutAll: '---'; lf.
]
{ #category : #exporting }
GrafoscopioNode >> exportPreambleTo: aStream [
"comment stating purpose of message"
| configDict |
aStream nextPutAll: '---'; lf.
aStream nextPutAll: 'header-includes:'; lf.
aStream nextPutAll: ' - \documentclass{article}'; lf.
aStream nextPutAll: ' - \usepackage{minted}'; lf.
aStream nextPutAll: ' - \usemintedstyle{friendly}'; lf.
(self header = '%config')
ifTrue: [
configDict := STON fromString: (self body).
@ -668,7 +690,10 @@ GrafoscopioNode >> removeLastNode [
{ #category : #'add/remove nodes' }
GrafoscopioNode >> removeNode: aNode [
self children remove: aNode.
(self children includes: aNode)
ifTrue: [ self children remove: aNode ]
ifFalse: [ self inform: 'The node doesn''t belong to this node children' ]
]

View File

@ -9,11 +9,27 @@ Class {
{ #category : #tests }
GrafoscopioNodeTest >> testAddingChildren [
| tree nnode orig modif |
| tree nnode orig |
tree := GrafoscopioNode new becomeDefaultTestTree.
nnode := GrafoscopioNode new.
orig := tree children size.
tree addNode: nnode.
self assert: tree children size equals: orig + 1.
]
{ #category : #tests }
GrafoscopioNodeTest >> testDemoteNode [
| tree child1 child2 |
tree := GrafoscopioNode new.
child1 := GrafoscopioNode new.
child2 := GrafoscopioNode new.
tree
addNode: child1;
addNode: child2.
child2 demote.
self assert: child2 level equals: child1 level + 1
]
@ -21,3 +37,27 @@ GrafoscopioNodeTest >> testAddingChildren [
GrafoscopioNodeTest >> testInitializeIsOk [
self shouldnt: [ GrafoscopioNode new ] raise: Error
]
{ #category : #tests }
GrafoscopioNodeTest >> testPromoteNode [
| tree child1 child2 |
tree := GrafoscopioNode new.
child1 := GrafoscopioNode new.
child2 := GrafoscopioNode new.
tree addNode: child1.
child1 addNode: child2.
child2 promote.
self assert: child2 level equals: child1 level
]
{ #category : #tests }
GrafoscopioNodeTest >> testRemovingChildren [
| tree orig |
tree := GrafoscopioNode new becomeDefaultTestTree.
orig := tree children size.
orig > 0 ifTrue: [ tree removeNode: (tree children at: 1) ].
self assert: tree children size equals: orig - 1.
]

View File

@ -101,20 +101,42 @@ GrafoscopioNotebook >> demoteNode [
self notebookContent: notebook.
]
{ #category : #persistence }
GrafoscopioNotebook >> exportAsLaTeX [
"I export the current tree/document to a LaTeX file, using pandoc external app.
I suppose pandoc is already installed and available in the system."
| texFile |
self markdownFile exists ifTrue: [ self markdownFile delete ].
self exportAsMarkdown.
texFile := self markdownFile parent fullName,'/', self markdownFile basenameWithoutExtension, '.tex'.
OSProcess command: "Transcript show:" 'pandoc --standalone ', self markdownFile fullName, ' -o ', texFile.
self inform: ('File exported as: ', String cr, texFile).
]
{ #category : #persistence }
GrafoscopioNotebook >> exportAsMarkdown [
"I save the current tree/document to a file"
| markdownFile |
"I export the current tree/document to a markdown file"
workingFile
ifNil: [ self inform: 'File NOT exported. Please save the notebook on hard drive first' ]
ifNotNil: [
markdownFile := (((workingFile parent) / workingFile basenameWithoutExtension) fullName, '.markdown') asFileReference.
markdownFile exists ifTrue: [ markdownFile delete ].
markdownFile ensureCreateFile.
markdownFile writeStreamDo: [:stream | stream nextPutAll: self notebook asMarkdown].
self markdownFile exists ifTrue: [ self markdownFile delete ].
self markdownFile ensureCreateFile.
self markdownFile writeStreamDo: [:stream | stream nextPutAll: self notebook asMarkdown].
"[ self exportAsMarkdown: self notebook on: ( markdownFile writeStream )]
ensure: [ (markdownFile writeStream) ifNotNil: #close ]."
self inform: ('File exported as: ', String cr, markdownFile fullName)]
self inform: ('File exported as: ', String cr, self markdownFile fullName)]
]
{ #category : #persistence }
GrafoscopioNotebook >> exportAsPDF [
"I export the current tree/document to a PDF file, using pandoc and LaTeX external apps.
The latex engine used is xelatex, to minimize errors and warnings related with UTF8 support.
I suppose all them are already installed and defined in the system."
| pdfFile |
self markdownFile exists ifFalse: [ self exportAsMarkdown ].
pdfFile := self markdownFile parent fullName,'/', self markdownFile basenameWithoutExtension, '.pdf'.
OSProcess command: 'pandoc --latex-engine=xelatex ', self markdownFile fullName, ' -o ', pdfFile.
self inform: ('File exported as: ', String cr, pdfFile).
]
{ #category : #persistence }
@ -191,6 +213,14 @@ GrafoscopioNotebook >> links: anObject [
links := anObject
]
{ #category : #persistence }
GrafoscopioNotebook >> markdownFile [
"I define the location of the markdown file where the notebook will be exported"
| markdownFile |
markdownFile := (((workingFile parent) / workingFile basenameWithoutExtension) fullName, '.markdown') asFileReference.
^ markdownFile
]
{ #category : #'editing nodes' }
GrafoscopioNotebook >> moveNodeAfter [
| editedNode |
@ -366,11 +396,16 @@ GrafoscopioNotebook >> notebookSubMenu [
name: 'Export as html';
icon: Smalltalk ui icons smallWindowIcon;
action: [ self inform: 'To be implemented...' ] ].
group addItem: [ :item |
item
name: 'Export as LaTeX';
icon: Smalltalk ui icons smallPrintIcon;
action: [ self exportAsLaTeX ] ].
group addItem: [ :item |
item
name: 'Export as pdf';
icon: Smalltalk ui icons smallPrintIcon;
action: [ self inform: 'To be implemented...' ] ].
action: [ self exportAsPDF ] ].
group addItem: [ :item |
item
name: 'See html';
@ -401,6 +436,25 @@ GrafoscopioNotebook >> openDefault [
^ nb openWithSpec.
]
{ #category : #persistence }
GrafoscopioNotebook >> openDevNotes [
self openDocumentationNotebookAt: 3.
]
{ #category : #persistence }
GrafoscopioNotebook >> openDocumentationNotebookAt: index [
"I open a notebook included with the documentation, located at a given index"
| notebookTemp gfcDocs |
gfcDocs := GrafoscopioDocumentation current.
(index between: 1 and: gfcDocs documents size)
ifFalse: [ ^ self ]
ifTrue: [
notebookTemp := (gfcDocs localPlace fullName, '/', (gfcDocs documents at: index)) asFileReference.
notebookTemp exists
ifTrue: [self class new openFromFile: notebookTemp]
ifFalse: [ GrafoscopioGUI updateDocumentationUI ]]
]
{ #category : #persistence }
GrafoscopioNotebook >> openFromFile: aFileName [
"I open a notebook from a file named aFileName containing a grafoscopio tree"
@ -454,14 +508,14 @@ GrafoscopioNotebook >> openFromUrlUI [
self class new openFromUrl: fileUrl
]
{ #category : #persistence }
GrafoscopioNotebook >> openManual [
self openDocumentationNotebookAt: 2.
]
{ #category : #persistence }
GrafoscopioNotebook >> openTutorial [
| tutorial gfcDocs |
gfcDocs := GrafoscopioDocumentation current.
tutorial := (gfcDocs localPlace fullName, '/', (gfcDocs documents at: 1)) asFileReference.
tutorial exists
ifTrue: [self class new openFromFile: tutorial]
ifFalse: [ GrafoscopioGUI updateDocumentationUI ]
self openDocumentationNotebookAt: 1.
]
{ #category : #'editing nodes' }

View File

@ -19,7 +19,7 @@ ManifestGrafoscopio class >> ruleRBEqualsTrueRuleV1FalsePositive [
{ #category : #'code-critics' }
ManifestGrafoscopio class >> ruleRBLongMethodsRuleV1FalsePositive [
^ #(#(#(#RGMethodDefinition #(#GrafoscopioNotebook #newWindowMainMenu #false)) #'2016-12-17T18:51:33.99062-05:00') )
^ #(#(#(#RGMethodDefinition #(#GrafoscopioNotebook #newWindowMainMenu #false)) #'2016-12-17T18:51:33.99062-05:00') #(#(#RGMethodDefinition #(#GrafoscopioNotebook #notebookSubMenu #false)) #'2017-02-02T11:43:53.106456-05:00') )
]
{ #category : #'code-critics' }