Cleaning up the code. Trying to find why code nodes are serialized so big! (problem was solved already for textual nodes)

This commit is contained in:
Offray Vladimir Luna Cárdenas 2016-03-14 22:12:14 +00:00 committed by SantiagoBragagnolo
parent 26bf6f988e
commit 10d5176906
2 changed files with 82 additions and 271 deletions

View File

@ -87,38 +87,31 @@ GrafoscopioBrowser class >> configureSettings [
{ #category : #updating }
GrafoscopioBrowser class >> downloadTutorial [
"I download the interactive tutorial in STON format.
I define some metadata associated to the tutorial document.
Language is provided according to the ISO 639-1 code convention."
If a the tutorial is already present in the system I made a temporal backup and download a new copy"
| doc client |
| client localTutorial temporalBackup remoteTutorial |
doc := Dictionary
with: 'type' -> 'tutorial'
with: 'language' -> 'ES_CO'
with: 'remote' -> 'http://mutabit.com/repos.fossil/grafoscopio/doc/tip/Docs/Es/Tutoriales/tutorial.ston'
with: 'local' -> './Docs/Es/Tutoriales/'.
((doc at: 'local'), 'tutorial.ston') asFileReference exists
localTutorial := './', (self tutorialData at: 'relativePath'), (self tutorialData at: 'filename').
temporalBackup := './', (self tutorialData at: 'relativePath'), 'tutorial.temp.ston'.
remoteTutorial := (self tutorialData at: 'remoteRepo'), 'doc/tip/', (self tutorialData at: 'relativePath'), (self tutorialData at: 'filename').
localTutorial asFileReference exists
ifTrue: [
((doc at: 'local'), 'tutorial.temp.ston') asFileReference exists
ifTrue: [ ((doc at: 'local'), 'tutorial.temp.ston') asFileReference delete].
((doc at: 'local'), 'tutorial.ston') asFileReference renameTo: 'tutorial.temp.ston'
temporalBackup asFileReference exists ifTrue: [ temporalBackup asFileReference delete].
localTutorial asFileReference renameTo: 'tutorial.temp.ston'
].
[:bar |
[: bar |
bar title: 'Actualizando el tutorial...'.
[client := ZnClient new.
client
get: (doc at: 'remote');
get: remoteTutorial;
signalProgress: true;
downloadTo: (doc at: 'local').
]
downloadTo: ('./', (self tutorialData at: 'relativePath')). ]
on: HTTPProgress
do: [ :progress |
progress isEmpty ifFalse: [ bar current: progress percentage ].
progress resume ].
] asJob run.
client isSuccess
ifFalse: [ self inform: 'Algo salió mal. Verifique su conexión a Internet.' ]
]
{ #category : #'graphical interface' }
@ -267,11 +260,11 @@ GrafoscopioBrowser class >> startDockingBar [
launchMenu := MenuMorph new.
launchMenu
add: 'Documento interactivo nuevo' target: GrafoscopioBrowser selector: #open;
add: 'Documento interactivo desde archivo' target: (GrafoscopioBrowser new) selector: #openFromFileSelector;
add: 'Documento interactivo desde Internet' target: (GrafoscopioBrowser new) selector: #openFromUrlUI;
add: 'Documentos interactivos recientes' target: GrafoscopioBrowser selector: #openFromRecentlyUsed;
add: 'Documentos interactivos de ejemplo' target: GrafoscopioBrowser selector: #messageNotImplementedYet;
add: 'Cuaderno nuevo' target: GrafoscopioBrowser selector: #open;
add: 'Cuaderno desde archivo...' target: (GrafoscopioBrowser new) selector: #openFromFileSelector;
add: 'Cuaderno desde Internet...' target: (GrafoscopioBrowser new) selector: #openFromUrlUI;
add: 'Cuadernos recientes...' target: GrafoscopioBrowser selector: #openFromRecentlyUsed;
add: 'Cuadernos de ejemplo' target: GrafoscopioBrowser selector: #messageNotImplementedYet;
add: 'Ejemplos de visualizaciones en Roassal' target: (RTExampleBrowser new) selector: #open;
add: 'Playground' target: (Smalltalk tools) selector: #openWorkspace;
add: 'Transcript' target: (Smalltalk tools) selector: #openTranscript.
@ -307,6 +300,39 @@ GrafoscopioBrowser class >> startDockingBar [
openInWorld.
]
{ #category : #updating }
GrafoscopioBrowser class >> tutorialData [
"I define some metadata associated to the tutorial document.
Language is provided according to the ISO 639-1 code convention."
| docData |
docData := Dictionary
with: 'type' -> 'tutorial'
with: 'languageCode' -> 'ES_CO'
with: 'remoteRepo' -> 'http://mutabit.com/repos.fossil/grafoscopio/'
with: 'relativePath' -> 'Docs/Es/Tutoriales/'
with: 'filename' -> 'tutorial.ston'.
^ docData
]
{ #category : #updating }
GrafoscopioBrowser class >> tutorialIsUpdated [
"I compare the cryptografic signatures of the local copy of the tutorial and the remote one to see if the're the same,
in which case I return True or False in any other cases."
| folderLastContents lastRemoteTutorial localTutorial |
localTutorial := './', (GrafoscopioBrowser tutorialData at: 'relativePath'), (GrafoscopioBrowser tutorialData at: 'filename').
folderLastContents := NeoJSONReader fromString:
(ZnEasy get: (self tutorialData at: 'remoteRepo'), 'json/dir?ci=tip&name=', (self tutorialData at: 'relativePath')) contents.
lastRemoteTutorial := ((folderLastContents at: 'payload') at: 'entries')
detect: [:entry | (entry at: 'name') = (self tutorialData at: 'filename') ].
^ (lastRemoteTutorial at: 'uuid') = (SHA1 new hashMessage: (localTutorial asFileReference contents)) hex
]
{ #category : #updating }
GrafoscopioBrowser class >> updateDataviz [
"Updates Dataviz package with new versions of itself take from the source code repository and
@ -369,39 +395,6 @@ GrafoscopioBrowser class >> updateDocumentation [
].
]
{ #category : #updating }
GrafoscopioBrowser class >> updateDocumentationTemp [
"Updates documentation (manual, tutorials) from official repository"
| update filePath fileLocation client docs |
update := (UIManager default
confirm: '¿Desea actualizar la documentación?'
label: 'Actualizar documentación').
update
ifTrue: [
docs := Dictionary
with: 'tutorial' -> (Dictionary
with: 'remote' -> 'http://mutabit.com/repos.fossil/grafoscopio/doc/tip/Docs/Es/Tutoriales/tutorial.ston'
with: 'local' -> './Docs/Es/Tutoriales/'
).
docs do: [:each |
client := ZnClient new.
client get: (each at: 'remote').
client isSuccess
ifFalse: [ self inform: 'Algo salió mal. Verifique su conexión a Internet.' ]
ifTrue: [
filePath := each at: 'local'.
filePath asFileReference ensureCreateDirectory.
fileLocation := filePath, ((each at: 'remote') splitOn: '/') last.
fileLocation asFileReference
writeStreamDo: [:stream |
stream write: client contents utf8Decoded asString].
].
self inform: 'Actualización de la documentación terminada'.
]
].
]
{ #category : #updating }
GrafoscopioBrowser class >> updateGrafoscopio [
"Updates Grafoscopio with new versions of itself take from the source code repository and
@ -549,12 +542,20 @@ GrafoscopioBrowser class >> updateSystem [
GrafoscopioBrowser class >> updateTutorial [
"I Update main tutorial from official repository"
| update |
update := (UIManager default
| update unnecessaryUpdate |
update := UIManager default
confirm: '¿Desea actualizar el tutorial?'
label: 'Actualizar el tutorial').
label: 'Actualizar el tutorial'.
update
ifTrue: [self downloadTutorial]
ifTrue: [
self tutorialIsUpdated
ifFalse: [self downloadTutorial]
ifTrue: [
unnecessaryUpdate := UIManager default
abort: 'El tutorial ya se encuentra en su versión más reciente.'
title: 'Nada que actualizar!'
]
]
]
{ #category : #updating }
@ -614,29 +615,6 @@ GrafoscopioBrowser >> addToTagsAvailable [
]
{ #category : #'graphical interface' }
GrafoscopioBrowser >> body2ForTransmediaIn: constructor for: aNode [
"Shows the body of a transmedia type of nodes, which are tagged as 'original' and 'transmediado'"
| innerBrowser originalNode transmediaNode |
aNode tags = 'original'
ifFalse: [^self ]
ifTrue: [
innerBrowser := GLMTabulator new.
GLMTabulator new.
innerBrowser
column: [ :c |
c row: [ :r | r column: #original; column: #transmediado] span: 7";
row: #buttons; span: 1"].
originalNode := aNode.
originalNode children isNotNil
ifTrue: [transmediaNode := originalNode children detect: [:node | node tags = 'transmediado']
ifNone: [ transmediaNode := nil ] ].
constructor custom: innerBrowser]
]
{ #category : #'graphical interface' }
GrafoscopioBrowser >> bodyForCodeIn: constructor for: aNode [
"Shows the body of a node as an interactive playground. If node is not tagged it will return itself,
@ -652,24 +630,6 @@ GrafoscopioBrowser >> bodyForCodeIn: constructor for: aNode [
]
{ #category : #'graphical interface' }
GrafoscopioBrowser >> bodyForTransmediaIn: constructor for: aNode [
"Shows the body of a transmedia type of nodes, which are tagged as 'original' and 'transmediado'"
aNode tags = 'original'
ifFalse: [^self ]
ifTrue: [constructor custom: (self panelTransmediaFor: aNode)]
]
{ #category : #'graphical interface' }
GrafoscopioBrowser >> bodyForTransmediaOn: constructor [
"Shows the body of a transmedia type of node"
constructor custom: self panelBrowserForTransmediaton.
]
{ #category : #'graphical interface' }
GrafoscopioBrowser >> bodyIn: constructor [
"Shows the body of a selected node"
@ -689,7 +649,7 @@ GrafoscopioBrowser >> bodyIn: constructor for: aNode [
| specialTags |
specialTags := #('código' 'original').
specialTags := #('código').
(specialTags includes: aNode tags)
ifTrue: [^self ].
(constructor text)
@ -732,7 +692,7 @@ browser
(browser transmit)
to: #nodeBody;
from: #tree;
andShow: [ :a | self bodyIn: a].
andShow: [ :a | self bodyIn: a asString].
(browser transmit )
from: #tree port: #selection;
from: #nodeBody port: #text;
@ -796,8 +756,7 @@ browser
when: [:selection | selection notNil];
andShow: [ :a :node |
self bodyIn: a for: node.
self bodyForCodeIn: a for: node.
self bodyForTransmediaIn: a for: node ].
self bodyForCodeIn: a for: node].
(browser transmit )
from: #tree port: #selection;
from: #nodeBody port: #text;
@ -806,7 +765,7 @@ browser
transformed: [:node :content |
node tags = 'código'
ifFalse: [node body: content asString]
ifTrue: [node body: content]].
ifTrue: [node body: content asString]].
(browser transmit)
from: #tree;
to: #nodeHeader;
@ -819,57 +778,6 @@ browser
transformed: [:node :text | node header: text asString]
]
{ #category : #'graphical interface' }
GrafoscopioBrowser >> buildBrowserNamed: aName inMode: aModeName [
"Main method for building the interface for trees and its nodes. The name of the browser corresponds to the name of the file
where tree is stored (or is named 'draft.ston' by default). The name of the mode correspond to a way of showing and dealing with
the data.
The idea is to support several modes in the future, starting with the 'Transmediaton' mode and adding more as needed."
self configureInitialTags.
browser := GLMTabulator new
title: aName, ' | Grafoscopio'.
browser
column: [:c |
c row: #tree span: 6;
row: #nodeHeader span: 1] span: 2;
column: [ :c |
c row: #nodeBody span: 2] span: 5.
browser
updateOn: GLMItemAdded from: #yourself;
updateOn: GLMItemRemoved from: #yourself.
(browser transmit)
to: #tree;
andShow: [:a | self treeOn: a].
"Creating a self updatable body pane"
(browser transmit)
to: #nodeBody;
from: #tree;
andShow: [ :a |
(aModeName = 'transmedia')
ifTrue: [self bodyForTransmediaOn: a]].
(browser transmit )
from: #tree port: #selection;
from: #nodeBody port: #text;
when: [:node :text | text notNil];
to: #nodeBody port: #neverland;
transformed: [:node :text | node body: text asString].
(browser transmit)
from: #tree;
to: #nodeHeader;
andShow: [ :h | self headerOn: h ].
(browser transmit )
from: #tree port: #selection;
from: #nodeHeader port: #text;
when: [:node :text | text notNil];
to: #nodeHeader port: #neverland1;
transformed: [:node :text | node header: text asString]
]
{ #category : #'persistance / repositories' }
GrafoscopioBrowser >> commitToRepository [
"Commits to the associated repository for the current document tree.
@ -1137,24 +1045,6 @@ GrafoscopioBrowser >> openFromFile: aFileName [
browser openOn: mainTree children.
]
{ #category : #persistence }
GrafoscopioBrowser >> openFromFile: aFileName inMode: aModeName [
"Opens a tree from a file named aFileName"
| currentChildren |
GrafoscopioBrowser configureSettings.
aFileName isNil ifTrue: [ ^nil ].
workingFile := aFileName name asFileReference.
currentChildren := (STON fromString: aFileName contents).
self buildBrowserNamed: aFileName basenameWithIndicator inMode: aModeName.
mainTree := GrafoscopioNode new
header: 'Arbol principal';
level: 0.
mainTree children: currentChildren.
browser openOn: mainTree children.
]
{ #category : #persistence }
GrafoscopioBrowser >> openFromFileSelector [
"Opens a tree from a file by using the file selector GUI."
@ -1238,21 +1128,6 @@ GrafoscopioBrowser >> openLandscape [
]
{ #category : #persistence }
GrafoscopioBrowser >> openLast [
"Opens a new browser with a fixed 'last' working tree. May be this should be changed"
| workingFile currentChildren| "workingChildren would sound too cruel!"
self buildBrowser.
workingFile := '/home/offray/Documentos/U/Libertadores/Grafoscopio/bootstrapping-objeto-investigacion.ston' asFileReference readStream.
currentChildren := (STON fromStream: workingFile).
mainTree := GrafoscopioNode new
header: 'Bootstrapping the research object';
level: 0.
mainTree children: currentChildren.
browser openOn: mainTree children.
]
{ #category : #persistence }
GrafoscopioBrowser >> openTutorialInGrafoscopio [
"Opens the help tree from a file"
@ -1269,15 +1144,6 @@ GrafoscopioBrowser >> openTutorialInGrafoscopio [
browser openOn: mainTree children.
]
{ #category : #persistence }
GrafoscopioBrowser >> openWorking [
"Opens a new browser with the last working tree"
self buildBrowser.
mainTree := '/home/offray/Documentos/U/Libertadores/Grafoscopio/bootstrapping-objeto-investigacion.ston' asFileReference readStream.
browser openOn: mainTree children.
]
{ #category : #'graphical interface' }
GrafoscopioBrowser >> panelAsCodeFor: aNode [
"Shows an interactive playground for Smalltalk code in a node body"
@ -1287,9 +1153,9 @@ GrafoscopioBrowser >> panelAsCodeFor: aNode [
browser column: #code.
browser transmit
to: #code;
transformed: [ GTPlayPage new content: aNode body ];
transformed: [ GTPlayPage new content: aNode body asString];
andShow: [ :a | a custom: GTPlayground new ].
browser sendToOutside: #nodeBody from: #code -> #text.
browser sendToOutside: (#nodeBody asString) from: #code -> #text.
^ browser.
]

View File

@ -85,7 +85,7 @@ GrafoscopioNode >> addNodeAfter [
{ #category : #accessing }
GrafoscopioNode >> ancestors [
"Returns a collection of all the nodes wich are ancestors of the receiver node"
"I return a collection of all the nodes wich are ancestors of the receiver node"
| currentNode ancestors |
currentNode := self.
@ -102,8 +102,9 @@ GrafoscopioNode >> ancestors [
{ #category : #accessing }
GrafoscopioNode >> ancestorsHeaders [
"Returns the headers of all the ancestors of the node. Maybe this and 'headers' should be integrated, so both act on a collection of
children instead of having two separate methods"
"Returns the headers of all the ancestors of the node.
Maybe this and 'headers' should be integrated, so both act on a collection of children instead of
having two separate methods"
| currentNode ancestors |
currentNode := self.
@ -146,43 +147,31 @@ GrafoscopioNode >> asSton [
{ #category : #initialization }
GrafoscopioNode >> becomeDefaultTestTree [
| node1 node2 node3 |
| node1 node2 |
self level: 0.
self header: 'Arbol principal'.
node1 := GrafoscopioNode new
header: 'Nodo 1';
body: 'Texto 1'.
header: 'Markup';
body: 'I am just a node with markup'.
node2 := GrafoscopioNode new
header: 'Nodo 2';
body: 'Texto 2'.
node3 := GrafoscopioNode new
header: 'Nodo 3';
body: 'ProfStef openPharoZenWorkspace';
header: 'Code';
body: 'PharoTutorial openPharoZenWorkspace';
tagAs: 'código'.
self
addNode: node1;
addNode: node2.
node2 addNode: node3.
]
{ #category : #initialization }
GrafoscopioNode >> becomeDefaultTree [
| node1 node2 node3 |
"I create a starting tree for all grafoscopio notebooks with just one textual node"
| node1 |
self level: 0.
self header: 'Arbol principal'.
node1 := GrafoscopioNode
header: 'Nodo 1'
body: 'Texto 1'.
node2 := GrafoscopioNode
header: 'Nodo 2'
body: 'Texto 2'.
node3 := GrafoscopioNode
header: 'Nodo 3'
body: 'Texto 3'.
self
addNode: node1;
addNode: node2.
node2 addNode: node3.
body: 'Texto 1'.
self addNode: node1.
]
{ #category : #accessing }
@ -343,16 +332,6 @@ GrafoscopioNode >> level: anInteger [
level := anInteger
]
{ #category : #accessing }
GrafoscopioNode >> localRepository [
^ localRepository
]
{ #category : #accessing }
GrafoscopioNode >> localRepository: anObject [
localRepository := anObject
]
{ #category : #exporting }
GrafoscopioNode >> markdownContent [
"Extracts the markdown of a node using body as content, header as title and level as hierarchical level of the title.
@ -530,40 +509,6 @@ GrafoscopioNode >> removeNode: aNode [
]
{ #category : #exporting }
GrafoscopioNode >> returnConfig [
"Detects a children node containing the configuration for the creation of the output files. If nothing is detected,
creates defaults for that. Pending:
- Verifying that file data in config node is accurate, and if not create the proper locations.
- Maybe there is a need to consider if it should run on all the tree, instead of a particular node."
| configString configNode configDict |
configNode := (self children) detect: [:nodeContent | nodeContent header = 'Config' ] ifNone: [ nil ].
"This part always enter for the nil option! MUST BE CORRECTED"
configNode isNil
ifTrue: [
configString := '{
"title": "Boostrapping para el objeto de investigación",
"author": {
"given": "Offray Vladimir",
"family": "Luna Cárdenas"
},
"file": {
"relative-path" : "U/Libertadores/Grafoscopio/",
"name": "bootstrapping-objeto-investigacion",
"formats": [
#ston,
#markdown
]
}
}'
]
ifFalse: [ configString := configNode body ].
configDict := STON fromString: configString.
^configDict
]
{ #category : #accessing }
GrafoscopioNode >> saveContent: anObject [
"Sets the receivers body to the given object"
@ -577,8 +522,8 @@ GrafoscopioNode >> tagAs: aTag [
know if a tag excludes others from the same node"
tags := aTag.
aTag = 'código'
ifTrue: [self body: (GTPlayPage new content: self body) content]
"aTag = 'código'
ifTrue: [self body: (GTPlayPage new content: self body) content]"
]
{ #category : #accessing }