Skip to content

Commit

Permalink
Add Spec2 inspector extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
astares committed Oct 24, 2023
1 parent 902fc6b commit 6c049c1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/XML-Parser-Tools/XMLElement.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Extension { #name : #XMLElement }

{ #category : #'*XML-Parser-Tools' }
XMLElement >> inspectAttributesIn: specBuilder [
<inspectorPresentationOrder: 30 title: 'Attributes'>

| builder table |
builder := (StSimpleInspectorBuilder on: specBuilder).

self attributes keysAndValuesDo: [:key :value |
builder key: key value: value
].
table := builder table.
table columns first title: #'Name'.
table columns second title: #'Value'.
^ table



]

{ #category : #'*XML-Parser-Tools' }
XMLElement >> inspectTreeIn: specBuilder [
<inspectorPresentationOrder: 28 title: 'Tree'>

^ specBuilder newTree
roots: (Array with: self);
display: [ :aNode |
self inspectorTreeStringFor: aNode
];
" displayIcon: [ :aNode | aNode iconName ifNotNil: [ :aName | self iconNamed: aName ] ];"
children: [ :aNode | aNode descendantElements ]


]

{ #category : #'*XML-Parser-Tools' }
XMLElement >> inspectorTreeStringFor: anXMLElement [
| display |
display := String streamContents: [:s|
s nextPutAll: anXMLElement name.
anXMLElement hasAttributes ifTrue: [
s space.
anXMLElement attributes associations do: [:association |
s
nextPutAll: association key;
nextPutAll: '="';
nextPutAll: association value;
nextPutAll: '"'.
] separatedBy: [ s space ]
]
].
anXMLElement descendantElements isEmpty ifFalse: [ ^ '<',display, '>' ].
^ anXMLElement asString
]
1 change: 1 addition & 0 deletions src/XML-Parser-Tools/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'XML-Parser-Tools' }

0 comments on commit 6c049c1

Please sign in to comment.