summaryrefslogtreecommitdiff
path: root/pharo-mooc/tiny-blog/src/TinyBlog
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-11-21 22:20:10 +0100
committerEugen Wissner <belka@caraus.de>2025-11-21 22:20:10 +0100
commitc03c9f8b886c0e8eca5a701c0ca941e05e0b6285 (patch)
tree5f27293563caa042b182de97fe59b22e2cbd533a /pharo-mooc/tiny-blog/src/TinyBlog
parentc0336dac8effb57c04221f23b72bff70170933c5 (diff)
downloadbook-exercises-c03c9f8b886c0e8eca5a701c0ca941e05e0b6285.tar.gz
Add pharo tiny blog
Diffstat (limited to 'pharo-mooc/tiny-blog/src/TinyBlog')
-rw-r--r--pharo-mooc/tiny-blog/src/TinyBlog/TBAdministrator.class.st42
-rw-r--r--pharo-mooc/tiny-blog/src/TinyBlog/TBBlog.class.st133
-rw-r--r--pharo-mooc/tiny-blog/src/TinyBlog/TBPost.class.st121
-rw-r--r--pharo-mooc/tiny-blog/src/TinyBlog/package.st1
4 files changed, 297 insertions, 0 deletions
diff --git a/pharo-mooc/tiny-blog/src/TinyBlog/TBAdministrator.class.st b/pharo-mooc/tiny-blog/src/TinyBlog/TBAdministrator.class.st
new file mode 100644
index 0000000..e1266ce
--- /dev/null
+++ b/pharo-mooc/tiny-blog/src/TinyBlog/TBAdministrator.class.st
@@ -0,0 +1,42 @@
+Class {
+ #name : 'TBAdministrator',
+ #superclass : 'Object',
+ #instVars : [
+ 'login',
+ 'password'
+ ],
+ #category : 'TinyBlog',
+ #package : 'TinyBlog'
+}
+
+{ #category : 'as yet unclassified' }
+TBAdministrator class >> login: login password: password [
+ ^ self new
+ login: login;
+ password: password;
+ yourself
+]
+
+{ #category : 'accessing' }
+TBAdministrator >> login [
+
+ ^ login
+]
+
+{ #category : 'accessing' }
+TBAdministrator >> login: anObject [
+
+ login := anObject
+]
+
+{ #category : 'accessing' }
+TBAdministrator >> password [
+
+ ^ password
+]
+
+{ #category : 'accessing' }
+TBAdministrator >> password: anObject [
+
+ password := SHA256 hashMessage: anObject
+]
diff --git a/pharo-mooc/tiny-blog/src/TinyBlog/TBBlog.class.st b/pharo-mooc/tiny-blog/src/TinyBlog/TBBlog.class.st
new file mode 100644
index 0000000..d3c9eca
--- /dev/null
+++ b/pharo-mooc/tiny-blog/src/TinyBlog/TBBlog.class.st
@@ -0,0 +1,133 @@
+Class {
+ #name : 'TBBlog',
+ #superclass : 'Object',
+ #instVars : [
+ 'posts',
+ 'adminUser'
+ ],
+ #category : 'TinyBlog',
+ #package : 'TinyBlog'
+}
+
+{ #category : 'demos' }
+TBBlog class >> createDemoPosts [
+ "TBBlog createDemoPosts"
+ self current
+ writeBlogPost: ((TBPost title: 'Welcome in TinyBlog' text: 'TinyBlog is a small blog engine made with Pharo.' category: 'TinyBlog') visible: true);
+ writeBlogPost: ((TBPost
+ title: 'Report Pharo Sprint'
+ text: 'Friday, June 12 there was a Pharo sprint / Moose dojo. It was a nice event with more than 15 motivated sprinters. With the help of candies, cakes and chocolate, huge work has been done'
+ category: 'Pharo') visible: true);
+ writeBlogPost: ((TBPost
+ title: 'Brick on top of Bloc - Preview'
+ text: 'We are happy to announce the first preview version of Brick, a new widget set created from scratch on top of Bloc. Brick is being developed primarily by Alex Syrel (together with Alain Plantec, Andrei Chis and myself), and the work is sponsored by ESUG. Brick is part of the Glamorous Toolkit effort and will provide the basis for the new versions of the development tools.'
+ category: 'Pharo') visible: true);
+ writeBlogPost: ((TBPost
+ title: 'The sad story of unclassified blog posts'
+ text: 'So sad that I can read this.') visible: true);
+ writeBlogPost: ((TBPost
+ title: 'Working with Pharo on the Raspberry Pi'
+ text: 'Hardware is getting cheaper and many new small devices like the famous Raspberry Pi provide new computation power that was one once only available on regular desktop computers.'
+ category: 'Pharo') visible: true)
+]
+
+{ #category : 'initialization' }
+TBBlog class >> current [
+ "answer the instance of the TBRepository"
+ ^ self selectAll
+ ifNotEmpty: [ :x | x anyOne ]
+ ifEmpty: [ self new save ]
+]
+
+{ #category : 'as yet unclassified' }
+TBBlog class >> defaultAdminLogin [
+ ^ 'admin'
+]
+
+{ #category : 'as yet unclassified' }
+TBBlog class >> defaultAdminPassword [
+ ^ 'topsecret'
+]
+
+{ #category : 'initialization' }
+TBBlog class >> initialize [
+ self reset
+]
+
+{ #category : 'reading' }
+TBBlog class >> initializeVoyageOnMemoryDB [
+ VOMemoryRepository new enableSingleton
+]
+
+{ #category : 'reading' }
+TBBlog class >> isVoyageRoot [
+ "Indicates that instances of this class are top level documents in noSQL databases"
+ ^ true
+]
+
+{ #category : 'initialization' }
+TBBlog class >> reset [
+ self initializeVoyageOnMemoryDB.
+]
+
+{ #category : 'as yet unclassified' }
+TBBlog >> administrator [
+ ^ adminUser
+]
+
+{ #category : 'reading' }
+TBBlog >> allBlogPosts [
+ ^ posts
+]
+
+{ #category : 'reading' }
+TBBlog >> allBlogPostsFromCategory: aCategory [
+ ^ posts select: [ :p | p category = aCategory ]
+]
+
+{ #category : 'reading' }
+TBBlog >> allCategories [
+ ^ (self allBlogPosts collect: [ :p | p category ]) asSet
+]
+
+{ #category : 'reading' }
+TBBlog >> allVisibleBlogPosts [
+ ^ posts select: [ :p | p isVisible ]
+]
+
+{ #category : 'reading' }
+TBBlog >> allVisibleBlogPostsFromCategory: aCategory [
+ ^ posts select: [ :p | p category = aCategory and: [ p isVisible ] ]
+]
+
+{ #category : 'as yet unclassified' }
+TBBlog >> createAdministrator [
+ ^ TBAdministrator
+ login: self class defaultAdminLogin
+ password: self class defaultAdminPassword
+]
+
+{ #category : 'initialization' }
+TBBlog >> initialize [
+ super initialize.
+ posts := OrderedCollection new.
+ adminUser := self createAdministrator
+]
+
+{ #category : 'deleting' }
+TBBlog >> removeAllPosts [
+ posts := OrderedCollection new.
+ self save
+]
+
+{ #category : 'initialization' }
+TBBlog >> size [
+ ^ posts size
+]
+
+{ #category : 'writing' }
+TBBlog >> writeBlogPost: aPost [
+ "Add the blog post in database."
+ self allBlogPosts add: aPost.
+ self save
+]
diff --git a/pharo-mooc/tiny-blog/src/TinyBlog/TBPost.class.st b/pharo-mooc/tiny-blog/src/TinyBlog/TBPost.class.st
new file mode 100644
index 0000000..08e8247
--- /dev/null
+++ b/pharo-mooc/tiny-blog/src/TinyBlog/TBPost.class.st
@@ -0,0 +1,121 @@
+Class {
+ #name : 'TBPost',
+ #superclass : 'Object',
+ #instVars : [
+ 'title',
+ 'text',
+ 'date',
+ 'category',
+ 'visible'
+ ],
+ #category : 'TinyBlog',
+ #package : 'TinyBlog'
+}
+
+{ #category : 'instance creation' }
+TBPost class >> title: aTitle text: aText [
+ ^ self new
+ title: aTitle;
+ text: aText;
+ yourself
+]
+
+{ #category : 'instance creation' }
+TBPost class >> title: aTitle text: aText category: aCategory [
+ ^ (self title: aTitle text: aText)
+ category: aCategory;
+ yourself
+]
+
+{ #category : 'as yet unclassified' }
+TBPost class >> unclassifiedTag [
+ ^ 'Unclassified'
+]
+
+{ #category : 'action' }
+TBPost >> beVisible [
+ self visible: true
+]
+
+{ #category : 'accessing' }
+TBPost >> category [
+
+ ^ category
+]
+
+{ #category : 'accessing' }
+TBPost >> category: anObject [
+
+ category := anObject
+]
+
+{ #category : 'accessing' }
+TBPost >> date [
+
+ ^ date
+]
+
+{ #category : 'accessing' }
+TBPost >> date: anObject [
+
+ date := anObject
+]
+
+{ #category : 'initialization' }
+TBPost >> initialize [
+ super initialize.
+ self category: self class unclassifiedTag.
+ self date: Date today.
+ self notVisible.
+]
+
+{ #category : 'testing' }
+TBPost >> isUnclassified [
+ ^ self category = self class unclassifiedTag
+]
+
+{ #category : 'testing' }
+TBPost >> isVisible [
+ ^ self visible
+]
+
+{ #category : 'action' }
+TBPost >> notVisible [
+ self visible: false
+]
+
+{ #category : 'accessing' }
+TBPost >> text [
+
+ ^ text
+]
+
+{ #category : 'accessing' }
+TBPost >> text: anObject [
+
+ text := anObject
+]
+
+{ #category : 'accessing' }
+TBPost >> title [
+
+ ^ title
+]
+
+{ #category : 'accessing' }
+TBPost >> title: anObject [
+
+ title := anObject
+]
+
+{ #category : 'accessing' }
+TBPost >> visible [
+
+ ^ visible
+]
+
+{ #category : 'accessing' }
+TBPost >> visible: anObject [
+
+ visible := anObject
+]
diff --git a/pharo-mooc/tiny-blog/src/TinyBlog/package.st b/pharo-mooc/tiny-blog/src/TinyBlog/package.st
new file mode 100644
index 0000000..c007567
--- /dev/null
+++ b/pharo-mooc/tiny-blog/src/TinyBlog/package.st
@@ -0,0 +1 @@
+Package { #name : 'TinyBlog' }