From ae32426cba8c0af1040789ecf2c9d1204a35ed22 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sat, 1 Apr 2017 13:20:17 +0000 Subject: [PATCH] Minor fix on markdown exportation. --- .../Grafoscopio/GrafoscopioNode.class.st | 5 +-- .../Grafoscopio/GrafoscopioNotebook.class.st | 35 ++++++++++++------- .../Grafoscopio/ManifestGrafoscopio.class.st | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/repository/Grafoscopio/GrafoscopioNode.class.st b/repository/Grafoscopio/GrafoscopioNode.class.st index 2984b6a..0045536 100644 --- a/repository/Grafoscopio/GrafoscopioNode.class.st +++ b/repository/Grafoscopio/GrafoscopioNode.class.st @@ -397,13 +397,10 @@ GrafoscopioNode >> exportPreambleTo: aStream [ (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. + aStream nextPutAll: 'abstract: ', '|'; lf; nextPutAll: (configDict at: 'abstract'); lf] ] { #category : #exporting } diff --git a/repository/Grafoscopio/GrafoscopioNotebook.class.st b/repository/Grafoscopio/GrafoscopioNotebook.class.st index 6a2de2c..29bce1a 100644 --- a/repository/Grafoscopio/GrafoscopioNotebook.class.st +++ b/repository/Grafoscopio/GrafoscopioNotebook.class.st @@ -95,6 +95,13 @@ GrafoscopioNotebook >> demoteNode [ self notebookContent: notebook. ] +{ #category : #persistence } +GrafoscopioNotebook >> exportAllSubtreesAsMarkdow [ + + | toBeExported | + toBeExported := (self notebook preorderTraversal) "collect: [ :each | each links last ] " +] + { #category : #persistence } GrafoscopioNotebook >> exportAsHTML [ "I export the current tree/document to a HTML file, using pandoc external app. @@ -123,15 +130,10 @@ GrafoscopioNotebook >> exportAsLaTeX [ { #category : #persistence } GrafoscopioNotebook >> exportAsMarkdown [ - "I export the current tree/document to a markdown file" - workingFile + "I export the current working tree/document to a markdown file." + workingFile ifNil: [ self inform: 'File NOT exported. Please save the notebook on hard drive first' ] - ifNotNil: [ - self markdownFile exists ifTrue: [ self markdownFile delete ]. - self markdownFile - ensureCreateFile; - writeStreamDo: [:stream | stream nextPutAll: self notebook asMarkdown]. - self inform: ('File exported as: ', String cr, self markdownFile fullName)] + ifNotNil: [ self exportNode: (self notebook) asMarkdownIn: (self markdownFile) ] ] { #category : #persistence } @@ -259,14 +261,22 @@ GrafoscopioNotebook >> moveNodeBefore [ { #category : #utilities } GrafoscopioNotebook >> navigateRelativePathFor: aFileString [ - "Given a relative path according to location of the notebook's workingFile, I navigate to that file" + "Given a relative path according to location of the notebook's workingFile, I navigate to that file if exist and create it, including + subdirectories if it does not exist. + If the relative path is located in a subdirectory that shares the route with the notebooks working file, it must start with the folders name, + without using './' to point the same shared root " - | finalLocation | + | finalLocation pathSegments | finalLocation := workingFile parent. - (aFileString splitOn: '/') do: [ :segment | + pathSegments := aFileString splitOn: '/'. + pathSegments allButLastDo: [ :segment | (segment = '..') ifTrue: [ finalLocation := finalLocation parent ] - ifFalse: [finalLocation := finalLocation / segment]]. + ifFalse: [ + finalLocation := finalLocation / segment. + finalLocation exists ifFalse: [ finalLocation ensureCreateDirectory ]]]. + finalLocation := finalLocation / (pathSegments last). + finalLocation exists ifFalse: [ finalLocation ensureCreateFile ]. ^ finalLocation ] @@ -521,6 +531,7 @@ GrafoscopioNotebook >> saveToFile: aFileReference [ [ self exportAsSton: self notebook on: (self workingFile writeStream)] ensure: [ (self workingFile writeStream) ifNotNil: #close ]. self title: self workingFile basenameWithIndicator, ' | Grafoscopio notebook'. + self exportAllSubtreesAsMarkdow. self inform: ('File saved at: ', String cr, self workingFile fullName). GrafoscopioDockingBar updateRecentNotebooksWith: aFileReference. diff --git a/repository/Grafoscopio/ManifestGrafoscopio.class.st b/repository/Grafoscopio/ManifestGrafoscopio.class.st index 30f813f..eb62805 100644 --- a/repository/Grafoscopio/ManifestGrafoscopio.class.st +++ b/repository/Grafoscopio/ManifestGrafoscopio.class.st @@ -9,7 +9,7 @@ Class { { #category : #'code-critics' } ManifestGrafoscopio class >> ruleRBAssignmentInIfTrueRuleV1FalsePositive [ - ^ #(#(#(#RGMethodDefinition #(#GrafoscopioNode #embedNodes #false)) #'2017-02-16T20:07:02.600781-05:00') ) + ^ #(#(#(#RGMethodDefinition #(#GrafoscopioNode #embedNodes #false)) #'2017-02-16T20:07:02.600781-05:00') #(#(#RGMethodDefinition #(#GrafoscopioNotebook #navigateRelativePathFor: #false)) #'2017-03-28T22:30:53.541042-05:00') ) ] { #category : #'code-critics' }