86 lines
1.8 KiB
Smalltalk
86 lines
1.8 KiB
Smalltalk
Class {
|
||
#name : #PubPubContent,
|
||
#superclass : #Object,
|
||
#instVars : [
|
||
'title',
|
||
'language',
|
||
'url',
|
||
'thumbnail'
|
||
],
|
||
#category : #'MiniDocs-Model'
|
||
}
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent class >> fromXML: anXMLElement [
|
||
^ self new fromXML: anXMLElement
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> fromXML: aXMLElement [
|
||
| image anchor|
|
||
image := aXMLElement contentNodes first xpath: './a/div'.
|
||
image
|
||
ifNotEmpty: [|style rawUrl|
|
||
style := (image first attributeAt: 'style').
|
||
rawUrl := (style splitOn: 'url') second.
|
||
self
|
||
thumbnail:(rawUrl copyFrom: 3 to: rawUrl size - 2)
|
||
].
|
||
anchor := (aXMLElement contentNodes second contentNodes first xpath: './div[@class="title-wrapper"]/a') first.
|
||
self
|
||
title: (anchor attributeAt: 'title');
|
||
url: (anchor attributeAt: 'href').
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> id [
|
||
^ (self url splitOn: $/) last
|
||
]
|
||
|
||
{ #category : #'as yet unclassified' }
|
||
PubPubContent >> language: aString [
|
||
language := aString
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> printOn: aStream [
|
||
super printOn: aStream.
|
||
aStream
|
||
nextPutAll: '( ', self title,' | ', self id, ' )'
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> shortName [
|
||
| sanitized |
|
||
sanitized := (self title splitOn: $:) first.
|
||
sanitized := sanitized copyReplaceAll: '’' with: ''.
|
||
sanitized := sanitized asCamelCase.
|
||
sanitized at: 1 put: sanitized first asLowercase.
|
||
^ sanitized
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> thumbnail: anURL [
|
||
thumbnail := anURL
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> title [
|
||
^ title
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> title: anObject [
|
||
title := anObject
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> url [
|
||
^url
|
||
]
|
||
|
||
{ #category : #accessing }
|
||
PubPubContent >> url: anObject [
|
||
url := anObject
|
||
]
|