Class { #name : #PubPub, #superclass : #Object, #instVars : [ 'address', 'tableOfContents', 'titles', 'folder', 'currentLanguage', 'languages' ], #category : #'MiniDocs-Model' } { #category : #accessing } PubPub >> addTableOfContents: anOrderedDictionary [ self tableOfContents at: (self currentLanguage) put: anOrderedDictionary; yourself ] { #category : #accessing } PubPub >> addTitle: aString [ self titles at: (self currentLanguage) put: aString ] { #category : #accessing } PubPub >> address [ ^ address ] { #category : #accessing } PubPub >> address: anUrl [ address := anUrl ] { #category : #accessing } PubPub >> currentLanguage [ ^ currentLanguage ] { #category : #accessing } PubPub >> currentLanguage: twoLettersInISO639_1 [ currentLanguage := twoLettersInISO639_1 ] { #category : #accessing } PubPub >> defaultTitle [ ^ self titles associations first value ] { #category : #accessing } PubPub >> downloadContents [ | workingDirectory | workingDirectory := self folder / self currentLanguage / 'book'. self tableOfContentsDictionary keysAndValuesDo: [ :name :chapterAddress | |currentFileName| currentFileName := name, '--', chapterAddress, '.md'. (workingDirectory / currentFileName) asFileReference ensureDelete. (workingDirectory / 'markdown') asFileReference ensureDelete. ZnClient new get: self address, 'pub/', chapterAddress, '/download/markdown'; downloadTo: workingDirectory . workingDirectory / 'markdown' renameTo: currentFileName ]. ^ workingDirectory ] { #category : #accessing } PubPub >> exportMarkdeepFiles [ | markdownFiles markdeepDocs | markdownFiles := self languageFolder allChildren select: [:file | file basename endsWith: '.md' ]. markdeepDocs := markdownFiles collect: [:file | (Markdeep fromMarkdownFile:file) ]. markdeepDocs do: [:each | each fromPubPubToMarkdeep exportAsFile ]. ^ self languageFolder ] { #category : #accessing } PubPub >> extractAllContentsRaw [ ^ self frontPage xpath: '//div[@class="layout-pubs-block"]' ] { #category : #accessing } PubPub >> extractRawTableOfContents [ ^ self extractAllContentsRaw first xpath: '//div[contains(concat(" ",normalize-space(@class)," "), " pub-preview-component ")]' ] { #category : #accessing } PubPub >> folder [ ^ folder ensureCreateDirectory ] { #category : #accessing } PubPub >> folder: localDirectory [ folder := localDirectory ] { #category : #accessing } PubPub >> frontPage [ "This should scrap contents of the book's front-page and translate them into Markdeep, according to our templates." ^ (XMLHTMLParser on: (self address asUrl retrieveContents)) parseDocument ] { #category : #accessing } PubPub >> languageFolder [ ^ self folder / self currentLanguage ] { #category : #accessing } PubPub >> markdeepFrontPage [ | frontPage markdeepIndex | frontPage := Markdeep new. frontPage title: self defaultTitle; file: self languageFolder / 'frontPage.md.html'. markdeepIndex := '' writeStream. self tableOfContents do: [:pubPubContent| markdeepIndex nextPutAll: pubPubContent asMarkdeepFrontPageElement ]. frontPage body: markdeepIndex contents. ^ frontPage ] { #category : #accessing } PubPub >> populateTableOfContents [ | contentsCollection | contentsCollection := self extractRawTableOfContents collect: [:each | (PubPubContent fromXML: each) language: self currentLanguage ]. self addTableOfContents: contentsCollection asOrderedCollection ] { #category : #accessing } PubPub >> printOn: aStream [ super printOn: aStream. aStream nextPutAll: '(',self defaultTitle, ' | ', self address, ' )' ] { #category : #accessing } PubPub >> tableOfContents [ tableOfContents ifNil: [^ tableOfContents := Dictionary new]. ^ tableOfContents at: self currentLanguage ] { #category : #accessing } PubPub >> tableOfContents: anObject [ tableOfContents := anObject ] { #category : #accessing } PubPub >> tableOfContentsDictionary [ | response | response := OrderedDictionary new. self tableOfContents do: [:content | response at: content shortName put: content id ]. ^ response ] { #category : #accessing } PubPub >> titles [ ^ titles ifNil: [titles := OrderedDictionary new] ]