From a05669966e0f949a8bef92b480de688ba2711e09 Mon Sep 17 00:00:00 2001 From: OffrayLuna Date: Mon, 31 Jul 2017 18:27:57 +0000 Subject: [PATCH] Extending special cases for generic urls plus the urls for playgrounds. --- src/Grafoscopio/GrafoscopioNode.class.st | 47 ++++++++++++++++---- src/Grafoscopio/GrafoscopioNotebook.class.st | 41 ++++++++++------- 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/src/Grafoscopio/GrafoscopioNode.class.st b/src/Grafoscopio/GrafoscopioNode.class.st index d725273..2e02c07 100644 --- a/src/Grafoscopio/GrafoscopioNode.class.st +++ b/src/Grafoscopio/GrafoscopioNode.class.st @@ -229,7 +229,7 @@ GrafoscopioNode >> becomeDefaultTestTree [ { #category : #initialization } GrafoscopioNode >> becomeDefaultTree [ - "I create a starting tree for all grafoscopio notebooks with just one textual node" + "I create a starting tree for all Grafoscopio notebooks with just one textual node as child." | node1 | self level: 0. self header: 'Arbol principal'. @@ -311,6 +311,13 @@ GrafoscopioNode >> copyToClipboard [ ] +{ #category : #operation } +GrafoscopioNode >> cryptoSignature [ + "I return the SHA1SUM of the current tree. I'm used to test changes on the contents + and for traceability of how the document tree is converted to other formats, as markdown." + ^ (SHA1 new hashMessage: self root flatten asSton) hex +] + { #category : #utility } GrafoscopioNode >> deleteReferencesToRoot: aRootNode [ @@ -518,6 +525,24 @@ GrafoscopioNode >> icon: aSymbol [ icon := aSymbol ] +{ #category : #importing } +GrafoscopioNode >> importLinkContent [ + "I take the last link and import its contents in node body. " + self links last asUrl host = 'ws.stfx.eu' ifTrue: [ ^ self ]. + self + body: (ZnClient new get: self links last). +] + +{ #category : #importing } +GrafoscopioNode >> importPlaygroundLink [ + "I take the last link and import its contents in node body. + Last links should be hosted in http://zn.stfx.eu/" + self links last asUrl host = 'ws.stfx.eu' ifFalse: [ ^ self ]. + self + body: (ZnClient new get: self links last); + tagAs: 'código'. +] + { #category : #initialization } GrafoscopioNode >> initialize [ "I create a empty new node" @@ -687,18 +712,22 @@ GrafoscopioNode >> metadata [ { #category : #exporting } GrafoscopioNode >> metadataAsYamlIn: markdownStream [ "I convert the first '%metadata' node into a YAML preamble to be used by Pandoc exportation." - self metadata ifNil: [ ^ self ]. markdownStream - nextPutAll: '---'; + nextPutAll: '---'; + lf; + nextPutAll: 'exportedFrom: ', self cryptoSignature; lf. - self metadata - keysAndValuesDo: [ :k :v | - markdownStream - nextPutAll: (k , ': ' , v asString) withInternetLineEndings; - nextPutAll: String cr ]. + self metadata + ifNotNil: [ + self metadata + keysAndValuesDo: [ :k :v | + markdownStream + nextPutAll: (k , ': ' , v asString) withInternetLineEndings; + nextPutAll: String cr ]]. markdownStream nextPutAll: '---'; - lf; lf + lf; + lf ] { #category : #movement } diff --git a/src/Grafoscopio/GrafoscopioNotebook.class.st b/src/Grafoscopio/GrafoscopioNotebook.class.st index f0ec2a7..61f50d0 100644 --- a/src/Grafoscopio/GrafoscopioNotebook.class.st +++ b/src/Grafoscopio/GrafoscopioNotebook.class.st @@ -47,7 +47,7 @@ GrafoscopioNotebook class >> defaultSpec [ bc add: #body; add: #links height: self toolbarHeight ]]] ] -{ #category : #'as yet unclassified' } +{ #category : #'instance creation' } GrafoscopioNotebook class >> newDefault [ ^ self new. ] @@ -95,6 +95,16 @@ GrafoscopioNotebook >> copyNodeToClipboard [ self notebookContent: notebook. ] +{ #category : #utilities } +GrafoscopioNotebook >> cryptoSignature [ + "I return the cryptographic signature of the workingFile where this notebook is being stored. + I'm useful for data provenance and traceability of derivated files related with this source + notebook." + self workingFile ifNil: [ ^ self ]. + self workingFile contents = '' ifTrue: [ ^ self ]. + ^ (SHA1 new hashMessage: (self workingFile contents)) hex. +] + { #category : #'editing nodes' } GrafoscopioNotebook >> cutNodeToClipboard [ self copyNodeToClipboard; removeNode. @@ -122,7 +132,7 @@ GrafoscopioNotebook >> debugWithSelector: aSymbol [ ^ (nodeContent perform: aSymbol asSymbol) inspect ] -{ #category : #'as yet unclassified' } +{ #category : #utilities } GrafoscopioNotebook >> defineDebugMessageUI [ | answer | answer := UIManager default @@ -234,6 +244,16 @@ GrafoscopioNotebook >> header: anObject [ header := anObject ] +{ #category : #initialization } +GrafoscopioNotebook >> initialize [ + super initialize. + self + notebook: (GrafoscopioNode new becomeDefaultTree); + title: ' New | Grafoscopio notebook'. + self notebookContent: self notebook. + +] + { #category : #initialization } GrafoscopioNotebook >> initializePresenter [ tree whenHighlightedItemChanged: [ :item | @@ -415,14 +435,8 @@ GrafoscopioNotebook >> okToChange [ { #category : #persistence } GrafoscopioNotebook >> openDefault [ "I open a new default notebook" - - | nb | - nb := self class new. - nb - notebook: (GrafoscopioNode new becomeDefaultTree); - title: ' New | Grafoscopio notebook'; - notebookContent: nb notebook. - ^ nb openWithSpec. + + ^ self class new openWithSpec. ] { #category : #persistence } @@ -774,11 +788,8 @@ GrafoscopioNotebook >> updateForSpecialLinks [ currentNode := tree highlightedItem. currentNode ifNil: [ ^ self ]. nodeContent := currentNode content. - nodeContent links last isAsciiString ifFalse: [ ^ self ]. - nodeContent links last asUrl host = 'ws.stfx.eu' ifFalse: [ ^ self ]. - nodeContent - body: (ZnClient new get: nodeContent links last); - tagAs: 'código'. + nodeContent importPlaygroundLink. + nodeContent importLinkContent. self updateBodyFor: currentNode ]