Implement post categories
This commit is contained in:
@@ -4,9 +4,8 @@ Class {
|
|||||||
#instVars : [
|
#instVars : [
|
||||||
'main'
|
'main'
|
||||||
],
|
],
|
||||||
#category : 'TinyBlog-Components-Components',
|
#category : 'TinyBlog-Components',
|
||||||
#package : 'TinyBlog-Components',
|
#package : 'TinyBlog-Components'
|
||||||
#tag : 'Components'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : 'testing' }
|
{ #category : 'testing' }
|
||||||
|
61
src/TinyBlog-Components/TBCategoriesComponent.class.st
Normal file
61
src/TinyBlog-Components/TBCategoriesComponent.class.st
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
Class {
|
||||||
|
#name : 'TBCategoriesComponent',
|
||||||
|
#superclass : 'TBScreenComponent',
|
||||||
|
#instVars : [
|
||||||
|
'categories',
|
||||||
|
'postsList'
|
||||||
|
],
|
||||||
|
#category : 'TinyBlog-Components',
|
||||||
|
#package : 'TinyBlog-Components'
|
||||||
|
}
|
||||||
|
|
||||||
|
{ #category : 'instance creation' }
|
||||||
|
TBCategoriesComponent class >> categories: categories postsList: aTBScreen [
|
||||||
|
^ self new categories: categories; postsList: aTBScreen
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBCategoriesComponent >> categories [
|
||||||
|
|
||||||
|
^ categories
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBCategoriesComponent >> categories: anObject [
|
||||||
|
|
||||||
|
categories := anObject
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBCategoriesComponent >> postsList [
|
||||||
|
|
||||||
|
^ postsList
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBCategoriesComponent >> postsList: anObject [
|
||||||
|
|
||||||
|
postsList := anObject
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'actions' }
|
||||||
|
TBCategoriesComponent >> renderCategoryLinkOn: html with: aCategory [
|
||||||
|
html listGroupLinkedItem
|
||||||
|
class: 'active' if: aCategory = self postsList currentCategory;
|
||||||
|
callback: [ self selectCategory: aCategory ];
|
||||||
|
with: aCategory
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'actions' }
|
||||||
|
TBCategoriesComponent >> renderContentOn: html [
|
||||||
|
html listGroup: [
|
||||||
|
html listGroupItem
|
||||||
|
with: [ html strong: 'Categories' ].
|
||||||
|
categories do: [ :cat |
|
||||||
|
self renderCategoryLinkOn: html with: cat ] ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'actions' }
|
||||||
|
TBCategoriesComponent >> selectCategory: aCategory [
|
||||||
|
postsList currentCategory: aCategory
|
||||||
|
]
|
@@ -1,9 +1,8 @@
|
|||||||
Class {
|
Class {
|
||||||
#name : 'TBHeaderComponent',
|
#name : 'TBHeaderComponent',
|
||||||
#superclass : 'SBSComponent',
|
#superclass : 'SBSComponent',
|
||||||
#category : 'TinyBlog-Components-Components',
|
#category : 'TinyBlog-Components',
|
||||||
#package : 'TinyBlog-Components',
|
#package : 'TinyBlog-Components'
|
||||||
#tag : 'Components'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
|
@@ -4,9 +4,8 @@ Class {
|
|||||||
#instVars : [
|
#instVars : [
|
||||||
'post'
|
'post'
|
||||||
],
|
],
|
||||||
#category : 'TinyBlog-Components-Components',
|
#category : 'TinyBlog-Components',
|
||||||
#package : 'TinyBlog-Components',
|
#package : 'TinyBlog-Components'
|
||||||
#tag : 'Components'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : 'initialization' }
|
{ #category : 'initialization' }
|
||||||
|
@@ -2,40 +2,105 @@ Class {
|
|||||||
#name : 'TBPostsListComponent',
|
#name : 'TBPostsListComponent',
|
||||||
#superclass : 'TBScreenComponent',
|
#superclass : 'TBScreenComponent',
|
||||||
#instVars : [
|
#instVars : [
|
||||||
'postComponents'
|
'postComponents',
|
||||||
|
'currentCategory'
|
||||||
],
|
],
|
||||||
#category : 'TinyBlog-Components-Components',
|
#category : 'TinyBlog-Components',
|
||||||
#package : 'TinyBlog-Components',
|
#package : 'TinyBlog-Components'
|
||||||
#tag : 'Components'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBPostsListComponent >> basicRenderCategoriesOn: html [
|
||||||
|
html render: self categoriesComponent
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBPostsListComponent >> basicRenderPostsOn: html [
|
||||||
|
self readSelectedPosts do: [ :p | html render: (self postComponentFor: p) ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBPostsListComponent >> categoriesComponent [
|
||||||
|
^ TBCategoriesComponent
|
||||||
|
categories: self blog allCategories
|
||||||
|
postsList: self
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : 'initialization' }
|
{ #category : 'initialization' }
|
||||||
TBPostsListComponent >> children [
|
TBPostsListComponent >> children [
|
||||||
^ self postComponents, super children
|
^ self postComponents, super children
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBPostsListComponent >> currentCategory [
|
||||||
|
|
||||||
|
^ currentCategory
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBPostsListComponent >> currentCategory: anObject [
|
||||||
|
|
||||||
|
currentCategory := anObject
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : 'initialization' }
|
{ #category : 'initialization' }
|
||||||
TBPostsListComponent >> initialize [
|
TBPostsListComponent >> initialize [
|
||||||
super initialize.
|
super initialize.
|
||||||
postComponents := OrderedCollection new
|
postComponents := OrderedCollection new
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBPostsListComponent >> postComponentFor: aPost [
|
||||||
|
^ TBPostComponent new post: aPost
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : 'initialization' }
|
{ #category : 'initialization' }
|
||||||
TBPostsListComponent >> postComponents [
|
TBPostsListComponent >> postComponents [
|
||||||
postComponents := self readSelectedPosts
|
postComponents := self readSelectedPosts
|
||||||
collect: [ :each | TBPostComponent new post: each ].
|
collect: [ :each | TBPostComponent new post: each ].
|
||||||
^ postComponents
|
^ postComponents
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : 'initialization' }
|
{ #category : 'initialization' }
|
||||||
TBPostsListComponent >> readSelectedPosts [
|
TBPostsListComponent >> readSelectedPosts [
|
||||||
^ self blog allVisibleBlogPosts
|
^ self currentCategory
|
||||||
|
ifNil: [ self blog allVisibleBlogPosts ]
|
||||||
|
ifNotNil: [ self blog allVisibleBlogPostsFromCategory: self currentCategory ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBPostsListComponent >> renderCategoryColumnOn: html [
|
||||||
|
html column
|
||||||
|
extraSmallSize: 12;
|
||||||
|
smallSize: 2;
|
||||||
|
mediumSize: 4;
|
||||||
|
with: [ self basicRenderCategoriesOn: html ]
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
TBPostsListComponent >> renderContentOn: html [
|
TBPostsListComponent >> renderContentOn: html [
|
||||||
super renderContentOn: html.
|
super renderContentOn: html.
|
||||||
html container: [
|
html container: [
|
||||||
self postComponents do: [ :p |
|
html row
|
||||||
html render: p ] ]
|
with: [
|
||||||
|
html column
|
||||||
|
extraSmallSize: 12;
|
||||||
|
smallSize: 2;
|
||||||
|
mediumSize: 4;
|
||||||
|
with: [ html render: self categoriesComponent ].
|
||||||
|
html column
|
||||||
|
extraSmallSize: 12;
|
||||||
|
smallSize: 10;
|
||||||
|
mediumSize: 8;
|
||||||
|
with: [
|
||||||
|
self postComponents do: [ :p | html render: (self postComponentFor: p) ] ] ] ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBPostsListComponent >> renderPostColumnOn: html [
|
||||||
|
html column
|
||||||
|
extraSmallSize: 12;
|
||||||
|
smallSize: 2;
|
||||||
|
mediumSize: 4;
|
||||||
|
with: [ self basicRenderPostsOn: html ]
|
||||||
]
|
]
|
||||||
|
@@ -4,9 +4,8 @@ Class {
|
|||||||
#instVars : [
|
#instVars : [
|
||||||
'header'
|
'header'
|
||||||
],
|
],
|
||||||
#category : 'TinyBlog-Components-Components',
|
#category : 'TinyBlog-Components',
|
||||||
#package : 'TinyBlog-Components',
|
#package : 'TinyBlog-Components'
|
||||||
#tag : 'Components'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : 'acccessing' }
|
{ #category : 'acccessing' }
|
||||||
|
@@ -8,8 +8,7 @@ Class {
|
|||||||
'previousRepository'
|
'previousRepository'
|
||||||
],
|
],
|
||||||
#category : 'TinyBlog-Tests',
|
#category : 'TinyBlog-Tests',
|
||||||
#package : 'TinyBlog',
|
#package : 'TinyBlog-Tests'
|
||||||
#tag : 'Tests'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : 'running' }
|
{ #category : 'running' }
|
@@ -2,8 +2,7 @@ Class {
|
|||||||
#name : 'TBPostTest',
|
#name : 'TBPostTest',
|
||||||
#superclass : 'TestCase',
|
#superclass : 'TestCase',
|
||||||
#category : 'TinyBlog-Tests',
|
#category : 'TinyBlog-Tests',
|
||||||
#package : 'TinyBlog',
|
#package : 'TinyBlog-Tests'
|
||||||
#tag : 'Tests'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : 'tests' }
|
{ #category : 'tests' }
|
1
src/TinyBlog-Tests/package.st
Normal file
1
src/TinyBlog-Tests/package.st
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Package { #name : 'TinyBlog-Tests' }
|
Reference in New Issue
Block a user