Refactoring GrafoscopioNode>>markdownContent and deleting %embed-all keyword. That should be the default behaviour.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2017-02-16 22:02:04 +00:00
parent 245979b9b2
commit 751f60c3df
2 changed files with 46 additions and 11 deletions

View File

@ -327,6 +327,41 @@ GrafoscopioNode >> demote [
] ]
{ #category : #'custom markup' }
GrafoscopioNode >> embedAll [
"This is just a previous part of the messy markDownContent. The %embed-all keyword should be revaluated.
By default a node embeds all its children. Any non-embedable content should be under a %invisible node"
"(temporalBody includesSubstring: '%embed-all')
ifFalse: [ ]
ifTrue: [
self embeddedNodes do: [ :each |
temporalBody := temporalBody copyReplaceAll: '%embed-all' with: (each body, (String with: Character cr),
'%embed-all')].
temporalBody := temporalBody copyReplaceAll: '%embed-all' with: '']"
]
{ #category : #'custom markup' }
GrafoscopioNode >> embedNodes [
"I find any ocurrence of '%embed a node header' in the body of a node and replace it
by the children which have such header.
Using embedded node is useful to change the order in which children appear into parents body,
while exporting"
| temporalBody |
temporalBody := self body.
self embeddedNodes ifNotNil: [ self embeddedNodes do: [ :each |
each tags = 'código'
ifFalse: [temporalBody := temporalBody copyReplaceAll: (each header) with: each body]
ifTrue: [temporalBody := temporalBody copyReplaceAll: (each header) with: each bodyAsCode]]].
^ temporalBody
]
{ #category : #'custom markup' }
GrafoscopioNode >> embeddedNodes [
^ self children select: [:each | each headerStartsWith: '%embed']
]
{ #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 "I convert the content of a node taged as 'código' (code) as pandoc markdown and put it
@ -543,7 +578,7 @@ GrafoscopioNode >> margins [
GrafoscopioNode >> markdownContent [ GrafoscopioNode >> markdownContent [
"Extracts the markdown of a node using body as content, header as title and level as hierarchical level of the title. "Extracts the markdown of a node using body as content, header as title and level as hierarchical level of the title.
If special nodes types are present, converts them into proper markup to be embedded inside markdown" If special nodes types are present, converts them into proper markup to be embedded inside markdown"
| markdown embedNodes temporalBody | | markdown temporalBody |
markdown := '' writeStream. markdown := '' writeStream.
(self class specialWords includes: self header) not & (self class specialWords includes: self header) not &
(self class specialWords includes: ((self header findTokens: $ ) at: 1)) not & (self tags ~= 'código') & (self class specialWords includes: ((self header findTokens: $ ) at: 1)) not & (self tags ~= 'código') &
@ -552,26 +587,21 @@ GrafoscopioNode >> markdownContent [
self level timesRepeat: [ markdown nextPutAll: '#' ]. self level timesRepeat: [ markdown nextPutAll: '#' ].
markdown nextPutAll: ' '. markdown nextPutAll: ' '.
markdown nextPutAll: (self header copyReplaceTokens: #cr with: #lf); crlf; crlf. markdown nextPutAll: (self header copyReplaceTokens: #cr with: #lf); crlf; crlf.
embedNodes := self children select: [:each | each headerStartsWith: '%embed'].
temporalBody := self body asString. temporalBody := self body asString.
embedNodes ifNotNil: [ self embeddedNodes ifNotNil: [
(temporalBody includesSubstring: '%embed-all') (temporalBody includesSubstring: '%embed-all')
ifFalse: [ ifFalse: [temporalBody := self embedNodes ]
embedNodes do: [ :each |
each tags = 'código'
ifFalse: [temporalBody := temporalBody copyReplaceAll: (each header) with: each body]
ifTrue: [temporalBody := temporalBody copyReplaceAll: (each header) with: each bodyAsCode]]]
ifTrue: [ ifTrue: [
embedNodes do: [ :each | self embeddedNodes do: [ :each |
temporalBody := temporalBody copyReplaceAll: '%embed-all' with: (each body, (String with: Character cr), temporalBody := temporalBody copyReplaceAll: '%embed-all' with: (each body, (String with: Character cr),
'%embed-all')]. '%embed-all')].
temporalBody := temporalBody copyReplaceAll: '%embed-all' with: '']]. temporalBody := temporalBody copyReplaceAll: '%embed-all' with: '']].
markdown nextPutAll: (temporalBody contents withInternetLineEndings ); crlf; crlf]. markdown nextPutAll: (temporalBody contents withInternetLineEndings ); crlf; crlf].
(self headerStartsWith: '%idea') (self headerStartsWith: '%idea')
ifTrue: [ ifTrue: [
embedNodes := self children select: [:each | each headerStartsWith: '%embed'].
temporalBody := self body string. temporalBody := self body string.
embedNodes ifNotNil: [ embedNodes do: [ :each | self embeddedNodes ifNotNil: [
self embeddedNodes do: [ :each |
each tags = 'código' each tags = 'código'
ifFalse: [temporalBody := temporalBody copyReplaceAll: (each header) with: each body] ifFalse: [temporalBody := temporalBody copyReplaceAll: (each header) with: each body]
ifTrue: [temporalBody := temporalBody copyReplaceAll: (each header) with: each bodyAsCode]]]. ifTrue: [temporalBody := temporalBody copyReplaceAll: (each header) with: each bodyAsCode]]].

View File

@ -7,6 +7,11 @@ Class {
#category : #Grafoscopio #category : #Grafoscopio
} }
{ #category : #'code-critics' }
ManifestGrafoscopio class >> ruleRBAssignmentInIfTrueRuleV1FalsePositive [
^ #(#(#(#RGMethodDefinition #(#GrafoscopioNode #embedNodes #false)) #'2017-02-16T20:07:02.600781-05:00') )
]
{ #category : #'code-critics' } { #category : #'code-critics' }
ManifestGrafoscopio class >> ruleRBClassNameInSelectorRuleV1FalsePositive [ ManifestGrafoscopio class >> ruleRBClassNameInSelectorRuleV1FalsePositive [
^ #(#(#(#RGMethodDefinition #(#'Documentation class' #current #true)) #'2016-10-07T19:39:23.013722-05:00') ) ^ #(#(#(#RGMethodDefinition #(#'Documentation class' #current #true)) #'2016-10-07T19:39:23.013722-05:00') )