Cleaning markdown exportation.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2017-02-02 22:00:40 +00:00 committed by SantiagoBragagnolo
parent dd95e544e6
commit 6d8ce8fc26
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 repository: (FossilRepo new url: 'http://mutabit.com/repos.fossil/grafoscopio').
gfcDocumentation documents gfcDocumentation documents
add: 'Docs/Es/Tutoriales/tutorial.ston'; 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'. add: 'Docs/En/dev-notes.ston'.
gfcDocumentation localPlace. gfcDocumentation localPlace.
^ gfcDocumentation ^ gfcDocumentation

View File

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

View File

@ -302,7 +302,8 @@ GrafoscopioNode >> deleteReferencesToRoot: aRootNode [
{ #category : #movement } { #category : #movement }
GrafoscopioNode >> demote [ 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 index predecessor |
collection := self parent children. collection := self parent children.
@ -316,6 +317,16 @@ GrafoscopioNode >> demote [
{ #category : #exporting } { #category : #exporting }
GrafoscopioNode >> exportCodeBlockTo: aStream [ 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 "I convert the content of a node taged as 'código' (code) as pandoc markdown and put it
into aStream. into aStream.
The code block is decorated with LaTeX commands for proper syntax highlighting using pygments. The code block is decorated with LaTeX commands for proper syntax highlighting using pygments.
@ -326,15 +337,26 @@ GrafoscopioNode >> exportCodeBlockTo: aStream [
^aStream contents ^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 } { #category : #exporting }
GrafoscopioNode >> exportPreambleTo: aStream [ GrafoscopioNode >> exportPreambleTo: aStream [
"comment stating purpose of message" "comment stating purpose of message"
| configDict | | 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') (self header = '%config')
ifTrue: [ ifTrue: [
configDict := STON fromString: (self body). configDict := STON fromString: (self body).
@ -668,7 +690,10 @@ GrafoscopioNode >> removeLastNode [
{ #category : #'add/remove nodes' } { #category : #'add/remove nodes' }
GrafoscopioNode >> removeNode: aNode [ 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 } { #category : #tests }
GrafoscopioNodeTest >> testAddingChildren [ GrafoscopioNodeTest >> testAddingChildren [
| tree nnode orig modif | | tree nnode orig |
tree := GrafoscopioNode new becomeDefaultTestTree. tree := GrafoscopioNode new becomeDefaultTestTree.
nnode := GrafoscopioNode new. nnode := GrafoscopioNode new.
orig := tree children size. orig := tree children size.
tree addNode: nnode. 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 [ GrafoscopioNodeTest >> testInitializeIsOk [
self shouldnt: [ GrafoscopioNode new ] raise: Error 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. 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 } { #category : #persistence }
GrafoscopioNotebook >> exportAsMarkdown [ GrafoscopioNotebook >> exportAsMarkdown [
"I save the current tree/document to a file" "I export the current tree/document to a markdown file"
| markdownFile |
workingFile workingFile
ifNil: [ self inform: 'File NOT exported. Please save the notebook on hard drive first' ] ifNil: [ self inform: 'File NOT exported. Please save the notebook on hard drive first' ]
ifNotNil: [ ifNotNil: [
markdownFile := (((workingFile parent) / workingFile basenameWithoutExtension) fullName, '.markdown') asFileReference. self markdownFile exists ifTrue: [ self markdownFile delete ].
markdownFile exists ifTrue: [ markdownFile delete ]. self markdownFile ensureCreateFile.
markdownFile ensureCreateFile. self markdownFile writeStreamDo: [:stream | stream nextPutAll: self notebook asMarkdown].
markdownFile writeStreamDo: [:stream | stream nextPutAll: self notebook asMarkdown].
"[ self exportAsMarkdown: self notebook on: ( markdownFile writeStream )] "[ self exportAsMarkdown: self notebook on: ( markdownFile writeStream )]
ensure: [ (markdownFile writeStream) ifNotNil: #close ]." 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 } { #category : #persistence }
@ -191,6 +213,14 @@ GrafoscopioNotebook >> links: anObject [
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' } { #category : #'editing nodes' }
GrafoscopioNotebook >> moveNodeAfter [ GrafoscopioNotebook >> moveNodeAfter [
| editedNode | | editedNode |
@ -366,11 +396,16 @@ GrafoscopioNotebook >> notebookSubMenu [
name: 'Export as html'; name: 'Export as html';
icon: Smalltalk ui icons smallWindowIcon; icon: Smalltalk ui icons smallWindowIcon;
action: [ self inform: 'To be implemented...' ] ]. 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 | group addItem: [ :item |
item item
name: 'Export as pdf'; name: 'Export as pdf';
icon: Smalltalk ui icons smallPrintIcon; icon: Smalltalk ui icons smallPrintIcon;
action: [ self inform: 'To be implemented...' ] ]. action: [ self exportAsPDF ] ].
group addItem: [ :item | group addItem: [ :item |
item item
name: 'See html'; name: 'See html';
@ -401,6 +436,25 @@ GrafoscopioNotebook >> openDefault [
^ nb openWithSpec. ^ 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 } { #category : #persistence }
GrafoscopioNotebook >> openFromFile: aFileName [ GrafoscopioNotebook >> openFromFile: aFileName [
"I open a notebook from a file named aFileName containing a grafoscopio tree" "I open a notebook from a file named aFileName containing a grafoscopio tree"
@ -454,14 +508,14 @@ GrafoscopioNotebook >> openFromUrlUI [
self class new openFromUrl: fileUrl self class new openFromUrl: fileUrl
] ]
{ #category : #persistence }
GrafoscopioNotebook >> openManual [
self openDocumentationNotebookAt: 2.
]
{ #category : #persistence } { #category : #persistence }
GrafoscopioNotebook >> openTutorial [ GrafoscopioNotebook >> openTutorial [
| tutorial gfcDocs | self openDocumentationNotebookAt: 1.
gfcDocs := GrafoscopioDocumentation current.
tutorial := (gfcDocs localPlace fullName, '/', (gfcDocs documents at: 1)) asFileReference.
tutorial exists
ifTrue: [self class new openFromFile: tutorial]
ifFalse: [ GrafoscopioGUI updateDocumentationUI ]
] ]
{ #category : #'editing nodes' } { #category : #'editing nodes' }

View File

@ -19,7 +19,7 @@ ManifestGrafoscopio class >> ruleRBEqualsTrueRuleV1FalsePositive [
{ #category : #'code-critics' } { #category : #'code-critics' }
ManifestGrafoscopio class >> ruleRBLongMethodsRuleV1FalsePositive [ 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' } { #category : #'code-critics' }