This commit is contained in:
Offray Vladimir Luna Cárdenas 2020-07-10 17:56:16 -05:00
commit 9e588bf102
3 changed files with 238 additions and 0 deletions

View File

@ -0,0 +1,118 @@
"
I model information of the items published on Internet Archive (https://archive.org/).
"
Class {
#name : #ArchiveOrgItem,
#superclass : #Object,
#instVars : [
'id',
'metadata'
],
#category : #Brea
}
{ #category : #utility }
ArchiveOrgItem >> archive [
^ 'https://archive.org'
]
{ #category : #utilities }
ArchiveOrgItem >> createHtmlImageGalleryList [
"IMPORTANT: This is just a draft snipped. Should become a proper test o be deleted."
self metadata ifNil: [ self getMetadata ].
^ '
<div id="nanogallery2"
/* gallery settings */
data-nanogallery2 = ''{
"thumbnailHeight": 150,
"thumbnailWidth": 150,
"itemsBaseURL": "', self galleryItemsBaseUrl ,'"
}'' >
<!-- gallery content -->
<a href = "primera 3.jpg" data-ngThumb = "primera 3_thumb.jpg" > </a>
<a href = "segunda.jpg" data-ngThumb = "segunda_thumb.jpg" > </a>
</div>'
]
{ #category : #utilities }
ArchiveOrgItem >> embeddedUrl [
^ 'https://archive.org/embed/', self id.
]
{ #category : #utilities }
ArchiveOrgItem >> galleryItemsBaseUrl [
"I create the place where all image would be located for creating a custom image gallery,
according with the requirements for nanogallery2."
^ 'https://', (self metadata at: 'd2'), (self metadata at: 'dir'), '/'.
]
{ #category : #operation }
ArchiveOrgItem >> getMetadata [
self id ifNil: [ ^ self ].
self metadata: (NeoJSONReader fromString: (self archive, '/metadata/', self id) asUrl retrieveContents)
]
{ #category : #accessing }
ArchiveOrgItem >> id [
^ id
]
{ #category : #accessing }
ArchiveOrgItem >> id: anObject [
id := anObject
]
{ #category : #utilities }
ArchiveOrgItem >> imagesGalleryList [
self metadata ifNil: [ self getMetadata ].
^ (self metadata at: 'files') select: [ :file | (file at: 'format') = 'JPEG Thumb' ]
]
{ #category : #utilities }
ArchiveOrgItem >> imagesGalleryListAsDictionary [
| galleryImages result |
self imagesGalleryList ifNil: [ ^ self ].
galleryImages := OrderedCollection new.
self imagesGalleryList do: [ :imgMetadata |
galleryImages
add: (Dictionary new
at: 'imgOriginal' put: (imgMetadata at: 'original');
at: 'imgThumb' put: (imgMetadata at: 'name');
yourself) ].
result := { 'archiveItemImages' -> galleryImages } asDictionary.
^ result
]
{ #category : #accessing }
ArchiveOrgItem >> metadata [
^ metadata
]
{ #category : #accessing }
ArchiveOrgItem >> metadata: anObject [
metadata := anObject
]
{ #category : #utilities }
ArchiveOrgItem >> subjectTags [
self id ifNil: [ ^ self ].
self metadata ifNil: [ self getMetadata ].
^ (self metadata at: 'metadata') at: 'subject'
]
{ #category : #utilities }
ArchiveOrgItem >> subjectTagsAsDictionary [
| tagList result |
self imagesGalleryList ifNil: [ ^ self ].
tagList := OrderedCollection new.
self subjectTags do: [ :tag |
tagList
add: (Dictionary new
at: 'tag' put: tag;
yourself) ].
result := { 'tagList' -> tagList } asDictionary.
^ result
]

View File

@ -0,0 +1,31 @@
Class {
#name : #BreaDataSource,
#superclass : #Object,
#instVars : [
'source',
'queries'
],
#category : #Brea
}
{ #category : #accessing }
BreaDataSource >> queries [
^ queries
]
{ #category : #accessing }
BreaDataSource >> queries: anObject [
queries := anObject
]
{ #category : #accessing }
BreaDataSource >> source [
^ source
]
{ #category : #accessing }
BreaDataSource >> source: aDictionary [
"Key, value pair in aDictionary contain a short name and a url pointing to a local or a remote
resource. If is local a FileLocator should be provided."
source := aDictionary
]

View File

@ -0,0 +1,89 @@
"
I define a [Mustache][1] template and how it is used to create
derivate output files combining it with particular data sources.
[1]: https://mustache.github.io/
"
Class {
#name : #BreaTemplate,
#superclass : #Object,
#instVars : [
'template',
'data',
'location',
'queries',
'outputs'
],
#category : #Brea
}
{ #category : #adding }
BreaTemplate >> addDataSourceNamed: name with: source [
self
data at: name put: source.
self data.
]
{ #category : #accessing }
BreaTemplate >> data [
^ data ifNil: [ data := Dictionary new ]
]
{ #category : #accessing }
BreaTemplate >> data: aDictionary [
"Each item in the dictionary is a unique alias (as key) and a data location (as value),
usually on the web.
Alias and locations are used later to define data queries to feed into templates."
data := aDictionary
]
{ #category : #accessing }
BreaTemplate >> location [
^ location
]
{ #category : #accessing }
BreaTemplate >> location: aFolderPath [
"This is the place where a template and its derivate files are located.
A shared location is an easy approach to start with and creates more explicit
relation between derived files and templates.
Eventually some re-mapping or re-routing could be used so templates and their outputs
could be further apart."
location := aFolderPath
]
{ #category : #accessing }
BreaTemplate >> outputs [
^ outputs
]
{ #category : #accessing }
BreaTemplate >> outputs: fileNamesList [
"fileNamesList contain the files which are derived from the template."
outputs := fileNamesList
]
{ #category : #accessing }
BreaTemplate >> queries [
^ queries ifNil: [ queries := Dictionary new ]
]
{ #category : #accessing }
BreaTemplate >> queries: aDictionary [
"aDictionary contains the alias for the query as key and a block that will be executed
on a particular data source, as value."
queries := aDictionary
]
{ #category : #accessing }
BreaTemplate >> template [
^ template
]
{ #category : #accessing }
BreaTemplate >> template: aFileName [
"I provide the name of the mustache base template.
The file can have any name, but by convention they end in '.mus.html' 'mus.md' and
so on."
template := aFileName
]