inkwell 1.5.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +7 -0
- data/app/models/inkwell/blog_item.rb +0 -2
- data/app/models/inkwell/blog_item_category.rb +0 -1
- data/app/models/inkwell/comment.rb +1 -2
- data/app/models/inkwell/community_user.rb +0 -2
- data/app/models/inkwell/favorite_item.rb +0 -1
- data/app/models/inkwell/following.rb +0 -2
- data/app/models/inkwell/timeline_item.rb +0 -1
- data/lib/acts_as_inkwell_category/base.rb +0 -1
- data/lib/acts_as_inkwell_community/base.rb +8 -9
- data/lib/acts_as_inkwell_post/base.rb +2 -2
- data/lib/acts_as_inkwell_user/base.rb +1 -1
- data/lib/inkwell/version.rb +1 -1
- data/test/dummy/app/models/category.rb +0 -1
- data/test/dummy/app/models/community.rb +0 -1
- data/test/dummy/app/models/post.rb +0 -1
- data/test/dummy/app/models/user.rb +0 -1
- data/test/dummy/config/application.rb +0 -6
- data/test/dummy/config/environments/development.rb +2 -3
- data/test/dummy/config/environments/test.rb +2 -6
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +64 -64
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy_without_community/app/models/post.rb +0 -1
- data/test/dummy_without_community/app/models/user.rb +0 -1
- data/test/dummy_without_community/config/application.rb +0 -6
- data/test/dummy_without_community/config/environments/development.rb +2 -3
- data/test/dummy_without_community/config/environments/test.rb +2 -6
- metadata +260 -273
- data/README-1.2.0.md +0 -454
- data/test/dummy_without_community/log/test.hello +0 -0
data/README-1.2.0.md
DELETED
@@ -1,454 +0,0 @@
|
|
1
|
-
# Inkwell
|
2
|
-
|
3
|
-
Inkwell provides simple way to add social networking features like comments,
|
4
|
-
reblogs, favorites, following/followers, communities and timelines to your
|
5
|
-
Ruby on Rails application.
|
6
|
-
|
7
|
-
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NYTZGSJD3H3BC)
|
8
|
-
|
9
|
-
Russian translation of README file available
|
10
|
-
[here](https://github.com/salkar/inkwell/blob/master/README_RU.rdoc).
|
11
|
-
|
12
|
-
## Requirements
|
13
|
-
You should have two classes: User and Post or other identical. Between them
|
14
|
-
should be a one-to-many relationship. For example:
|
15
|
-
|
16
|
-
class User < ActiveRecord::Base
|
17
|
-
has_many :posts
|
18
|
-
end
|
19
|
-
|
20
|
-
class Post < ActiveRecord::Base
|
21
|
-
belongs_to :user
|
22
|
-
end
|
23
|
-
|
24
|
-
If you want to use
|
25
|
-
[communities](https://github.com/salkar/inkwell#community-feature), then you
|
26
|
-
need to have `Community` class, too:
|
27
|
-
|
28
|
-
class Community < ActiveRecord::Base
|
29
|
-
end
|
30
|
-
|
31
|
-
## Installation
|
32
|
-
|
33
|
-
Put in `Gemfile`:
|
34
|
-
|
35
|
-
gem 'inkwell'
|
36
|
-
|
37
|
-
to get it from RubyGems or
|
38
|
-
|
39
|
-
gem 'inkwell', :git => 'git://github.com/salkar/inkwell.git'
|
40
|
-
|
41
|
-
to get it from github (This version may contain unfinished new features).
|
42
|
-
|
43
|
-
After it do `bundle install`
|
44
|
-
|
45
|
-
Add to your `User` model `acts_as_inkwell_user` and to your `Post` model
|
46
|
-
`acts_as_inkwell_post`
|
47
|
-
|
48
|
-
class User < ActiveRecord::Base
|
49
|
-
has_many :posts
|
50
|
-
acts_as_inkwell_user
|
51
|
-
end
|
52
|
-
|
53
|
-
class Post < ActiveRecord::Base
|
54
|
-
belongs_to :user
|
55
|
-
acts_as_inkwell_post
|
56
|
-
end
|
57
|
-
|
58
|
-
If you want to use communities, then add to your `Community` model
|
59
|
-
`acts_as_inkwell_community`:
|
60
|
-
|
61
|
-
class Community < ActiveRecord::Base
|
62
|
-
acts_as_inkwell_community
|
63
|
-
end
|
64
|
-
|
65
|
-
Create `inkwell.rb` file in `config/initializers` and put in it your names of
|
66
|
-
`User` and `Post` tables (or other identical). Put in it name of `Community`
|
67
|
-
table if you want to use it:
|
68
|
-
|
69
|
-
module Inkwell
|
70
|
-
class Engine < Rails::Engine
|
71
|
-
config.post_table = :posts
|
72
|
-
config.user_table = :users
|
73
|
-
config.community_table = :communities #if you want to use communities
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
Next, get gem migrations:
|
78
|
-
|
79
|
-
rake inkwell:install:migrations
|
80
|
-
|
81
|
-
and `db:migrate` it.
|
82
|
-
|
83
|
-
## Upgrading
|
84
|
-
|
85
|
-
After upgrading gem do not forget to get new migrations and migrate it.
|
86
|
-
|
87
|
-
rake inkwell:install:migrations
|
88
|
-
db:migrate
|
89
|
-
|
90
|
-
## Usage
|
91
|
-
|
92
|
-
### Favorite features
|
93
|
-
|
94
|
-
User is able to favorite posts/comments:
|
95
|
-
|
96
|
-
@user.favorite @post
|
97
|
-
@user.favorite @comment
|
98
|
-
|
99
|
-
To delete post/comment from favorites:
|
100
|
-
|
101
|
-
@user.unfavorite @post
|
102
|
-
|
103
|
-
To check that post/comment enters in favorites:
|
104
|
-
|
105
|
-
@user.favorite? @post
|
106
|
-
|
107
|
-
To return favorite line, consisting of favorited posts and comments:
|
108
|
-
|
109
|
-
@user.favoriteline(:last_shown_obj_id => nil, :limit => 10, :for_user => nil)
|
110
|
-
|
111
|
-
where
|
112
|
-
* `last_shown_obj_id` - id of the last item in favorite line shown to the
|
113
|
-
user. Get it from the `item_id_in_line` property of last item from
|
114
|
-
previous `favoriteline` calls. This parameter is used for pagination and
|
115
|
-
separation of the timeline.
|
116
|
-
|
117
|
-
fline = @user.favoriteline #get first 10 items from @user favorite line
|
118
|
-
last_shown_obj_id = fline.last.item_id_in_line
|
119
|
-
fline_next_page = @user.favoriteline :last_shown_obj_id => last_shown_obj_id #get next 10 items from @user favorite line
|
120
|
-
|
121
|
-
* `limit` - defines the count of favorited items to return.
|
122
|
-
|
123
|
-
fline = @user.favoriteline :limit => 20 #return first 20 items from @user favorite line
|
124
|
-
|
125
|
-
* `for_user` - `User`, who looks this favorite line. For him `is_reblogged`
|
126
|
-
and `is_favorited` properties will been formed.
|
127
|
-
|
128
|
-
@user.favorite @another_user_post
|
129
|
-
@user.reblog @another_user_post
|
130
|
-
|
131
|
-
fline_for_unknown_user = @another_user.favoriteline
|
132
|
-
# For example, fline_for_unknown_user.first == @another_user_post
|
133
|
-
fline_for_unknown_user.first.is_reblogged # => false
|
134
|
-
fline_for_unknown_user.first.is_favorited # => false
|
135
|
-
|
136
|
-
fline_for_user_who_reblog_and_favorite_another_user_post = @another_user.favoriteline :for_user => @user
|
137
|
-
# For example, fline_for_user_who_reblog_and_favorite_another_user_post.first == @another_user_post
|
138
|
-
fline_for_user_who_reblog_and_favorite_another_user_post.first.is_reblogged # => true
|
139
|
-
fline_for_user_who_reblog_and_favorite_another_user_post.first.is_favorited # => true
|
140
|
-
|
141
|
-
|
142
|
-
More examples you can find in this
|
143
|
-
[spec](https://github.com/salkar/inkwell/blob/master/test/dummy/spec/functional/favorite_spec.rb).
|
144
|
-
|
145
|
-
### Reblog features
|
146
|
-
|
147
|
-
Reblog means that reblogged post will be added to user's blogline and to
|
148
|
-
timelines of his followers. Thus, the behavior of reblogged object is similar
|
149
|
-
to the post of the user who made this reblog. User is able to reblog
|
150
|
-
posts/comments:
|
151
|
-
|
152
|
-
@user.reblog @post
|
153
|
-
@user.reblog @comment
|
154
|
-
|
155
|
-
To delete post/comment from reblogs:
|
156
|
-
|
157
|
-
@user.unreblog @post
|
158
|
-
|
159
|
-
To check that post/comment enters in reblogs:
|
160
|
-
|
161
|
-
@user.reblog? @post
|
162
|
-
|
163
|
-
Reblogs don't have their own line and are contained in user's blogline.
|
164
|
-
|
165
|
-
More examples you can find in this
|
166
|
-
[spec](https://github.com/salkar/inkwell/blob/master/test/dummy/spec/functional/reblog_spec.rb).
|
167
|
-
|
168
|
-
### Comment features
|
169
|
-
|
170
|
-
User is able to create comments for post or other comment. If you want to
|
171
|
-
comment the post:
|
172
|
-
|
173
|
-
@user.create_comment :for_object => @post, :body => "comment_body"
|
174
|
-
|
175
|
-
If you want to comment other comment you should add `parent_comment_id` of parent
|
176
|
-
comment:
|
177
|
-
|
178
|
-
@user.create_comment :for_object => @parent_post, :body => "comment_body", :parent_comment_id => @parent_comment.id
|
179
|
-
|
180
|
-
To delete comment you should use `destroy` method:
|
181
|
-
|
182
|
-
@comment.destroy
|
183
|
-
|
184
|
-
You are able to get comment line for post or comment. It consists of comments
|
185
|
-
for this object in reverse chronological order.
|
186
|
-
|
187
|
-
*Notice: returned array will have back order to simplify the use. Last comment
|
188
|
-
is at the bottom usually.*
|
189
|
-
|
190
|
-
To get comment line:
|
191
|
-
|
192
|
-
commentline(:last_shown_comment_id => nil, :limit => 10, :for_user => nil)
|
193
|
-
|
194
|
-
where `last_shown_comment_id` is id of last shown comment from previous
|
195
|
-
commentline results. For example:
|
196
|
-
|
197
|
-
cline = @post.commentline #get last 10 comments for @post
|
198
|
-
last_shown_comment_id = cline.first.id # First element is taken due to reverse order. In fact, it is the oldest of these comments.
|
199
|
-
cline_next_page = @post.commentline :last_shown_comment_id => last_shown_comment_id
|
200
|
-
|
201
|
-
`Limit` and `for_user` mean the same thing as in the
|
202
|
-
[favoriteline](https://github.com/salkar/inkwell#favorite-features).
|
203
|
-
|
204
|
-
More examples you can find in this
|
205
|
-
[spec](https://github.com/salkar/inkwell/blob/master/test/dummy/spec/functional/comments_spec.rb).
|
206
|
-
|
207
|
-
### Follow features
|
208
|
-
|
209
|
-
User is able to follow another users. It allows him to get followed user's
|
210
|
-
blogline in his timeline.
|
211
|
-
|
212
|
-
To follow user:
|
213
|
-
|
214
|
-
@user.follow @another_user
|
215
|
-
|
216
|
-
After it last 10 `@another_user` blogline's items will be transferred to
|
217
|
-
`@user` timeline. And each new `@another_user` blogline item will be added to
|
218
|
-
`@user` timeline.
|
219
|
-
|
220
|
-
To unfollow user:
|
221
|
-
|
222
|
-
@user.unfollow @another_user
|
223
|
-
|
224
|
-
To check that user is follower of another user:
|
225
|
-
|
226
|
-
@user.follow? @another_user
|
227
|
-
|
228
|
-
To get followers ids for user and ids of users, which he follow:
|
229
|
-
|
230
|
-
@user.followers_row
|
231
|
-
@user.followings_row
|
232
|
-
|
233
|
-
Both methods return arrays of ids.
|
234
|
-
|
235
|
-
More examples you can find in this
|
236
|
-
[spec](https://github.com/salkar/inkwell/blob/master/test/dummy/spec/functional/following_spec.rb).
|
237
|
-
|
238
|
-
### Blogline feature
|
239
|
-
|
240
|
-
User blogline is consists of his posts and his reblogs. To get it:
|
241
|
-
|
242
|
-
@user.blogline(:last_shown_obj_id => nil, :limit => 10, :for_user => nil)
|
243
|
-
|
244
|
-
where parameters are similar with described
|
245
|
-
[above](https://github.com/salkar/inkwell#favorite-features) favoriteline
|
246
|
-
parameters.
|
247
|
-
|
248
|
-
More examples you can find in this
|
249
|
-
[spec](https://github.com/salkar/inkwell/blob/master/test/dummy/spec/functional/blogline_spec.rb).
|
250
|
-
|
251
|
-
### Timeline feature
|
252
|
-
|
253
|
-
User timeline is consists of items from bloglines of users he follows. To get
|
254
|
-
it:
|
255
|
-
|
256
|
-
@user.timeline(:last_shown_obj_id => nil, :limit => 10, :for_user => nil)
|
257
|
-
|
258
|
-
where parameters are similar with described
|
259
|
-
[above](https://github.com/salkar/inkwell#favorite-features) favoriteline
|
260
|
-
parameters.
|
261
|
-
|
262
|
-
More examples you can find in this
|
263
|
-
[spec](https://github.com/salkar/inkwell/blob/master/test/dummy/spec/functional/timeline_spec.rb).
|
264
|
-
|
265
|
-
### Community feature
|
266
|
-
|
267
|
-
Community is association of users. It has own blogline, consisting of posts of
|
268
|
-
its members. Community member can send his post to the community blogline.
|
269
|
-
Then this post is added to the timelines of other community users.
|
270
|
-
|
271
|
-
There are two types of community: private and public. Users can join public community when they want - no one controls this process (They should not be banned in it).
|
272
|
-
The user should leave the invitation request to join the private community. Then the admin will review it and add the user to the community or reject the request.
|
273
|
-
|
274
|
-
When you create community you need to pass `owner_id`. To create public community:
|
275
|
-
|
276
|
-
@community = Community.create :name => "Community", :owner_id => @user.id
|
277
|
-
|
278
|
-
To create private community you need to pass `:public => false` in addition to the rest:
|
279
|
-
|
280
|
-
@private_community = Community.create :name => "Private Community", :owner_id => @user.id, :public => false
|
281
|
-
|
282
|
-
User with the passed id (`owner_id`) will be the first administrator of created community
|
283
|
-
and will be added to it.
|
284
|
-
|
285
|
-
To add a user to the public community:
|
286
|
-
|
287
|
-
@user.join @community
|
288
|
-
|
289
|
-
After it last 10 `@community` blogline's items will be transferred to `@user`
|
290
|
-
timeline. And each new `@community` blogline item will be added to `@user`
|
291
|
-
timeline. Moreover `@user` will be able to add their posts in community
|
292
|
-
blogline.
|
293
|
-
|
294
|
-
To send invitation request to the private community:
|
295
|
-
|
296
|
-
@user.request_invitation @private_community
|
297
|
-
|
298
|
-
To accept invitation request:
|
299
|
-
|
300
|
-
@admin.approve_invitation_request :user => @user, :community => @private_community
|
301
|
-
|
302
|
-
To reject invitation request:
|
303
|
-
|
304
|
-
@admin.reject_invitation_request :user => @user, :community => @private_community
|
305
|
-
|
306
|
-
To prevent invitation requests spam you are able to ban spamming users.
|
307
|
-
|
308
|
-
To remove a user from community:
|
309
|
-
|
310
|
-
@admin.kick :user => @user, :from_community => @community
|
311
|
-
|
312
|
-
where `admin` is community administrator and `@user` is deleted user.
|
313
|
-
|
314
|
-
If user leave community:
|
315
|
-
|
316
|
-
@user.leave @community
|
317
|
-
|
318
|
-
After leaving the community (both methods) its blogline items will be removed
|
319
|
-
from the user timeline.
|
320
|
-
|
321
|
-
To send post to the community blogline:
|
322
|
-
|
323
|
-
@user.send_post_to_community :post => @user_post, :to_community => @community
|
324
|
-
|
325
|
-
Preferably check the possibility of sending a post by `@user` before using `send_post_to_community`. To check user permissions for post sending:
|
326
|
-
|
327
|
-
@user.send_post_to_community :post => @user_post, :to_community => @community
|
328
|
-
if @user.can_send_post_to_community? @community
|
329
|
-
|
330
|
-
Sent post will be added to timelines of community members. A post can be sent
|
331
|
-
to the community only by its owner.
|
332
|
-
|
333
|
-
To remove post from community blogline:
|
334
|
-
|
335
|
-
@user.remove_post_from_community :post => @user_post, :from_community => @community
|
336
|
-
|
337
|
-
or
|
338
|
-
|
339
|
-
@admin.remove_post_from_community :post => @user_post, :from_community => @community
|
340
|
-
|
341
|
-
Only post owner or administrator of community can remove the post from the
|
342
|
-
community blogline.
|
343
|
-
|
344
|
-
To check that the user is a member of the community:
|
345
|
-
|
346
|
-
@community.include_user? @user
|
347
|
-
|
348
|
-
To check that the user is an admin of the community:
|
349
|
-
|
350
|
-
@community.include_admin? @user
|
351
|
-
|
352
|
-
Each administrator has the access level. Community owner has access level 0.
|
353
|
-
Administrators, to whom he granted admin permissions, have access level 1 and
|
354
|
-
so on. Thus the lower the access level, the more permissions. For example,
|
355
|
-
admin with access level 0 can delete admin with access level 1 but not vice
|
356
|
-
versa.
|
357
|
-
|
358
|
-
To grant admin permissions:
|
359
|
-
|
360
|
-
@admin.grant_admin_permissions :to_user => @new_admin, :in_community => @community
|
361
|
-
|
362
|
-
To revoke admin permissions:
|
363
|
-
|
364
|
-
@admin.revoke_admin_permissions :user => @admin_who_is_removed, :in_community => @community
|
365
|
-
|
366
|
-
To get admin's access level:
|
367
|
-
|
368
|
-
@community.admin_level_of @admin
|
369
|
-
|
370
|
-
To get communities ids in which there is this post:
|
371
|
-
|
372
|
-
@post.communities_row
|
373
|
-
|
374
|
-
To get ids of community members:
|
375
|
-
|
376
|
-
@community.users_row
|
377
|
-
|
378
|
-
To get ids of community administrators:
|
379
|
-
|
380
|
-
@community.admins_row
|
381
|
-
|
382
|
-
To get ids of communities to which the user has joined:
|
383
|
-
|
384
|
-
@user.communities_row
|
385
|
-
|
386
|
-
Admin of community is able to mute or ban user. Muted users is not able to send posts to community, but they are still in it.
|
387
|
-
Banned users are not in community and are not able to join it or send invite in it.
|
388
|
-
|
389
|
-
To mute user:
|
390
|
-
|
391
|
-
@admin.mute :user => @user, :in_community => @community
|
392
|
-
|
393
|
-
To unmute user:
|
394
|
-
|
395
|
-
@admin.unmute :user => @user, :in_community => @community
|
396
|
-
|
397
|
-
To check that user is muted:
|
398
|
-
|
399
|
-
@community.include_muted_user? @user
|
400
|
-
|
401
|
-
To ban user:
|
402
|
-
|
403
|
-
@admin.ban :user => @user, :in_community => @community
|
404
|
-
|
405
|
-
To unban user:
|
406
|
-
|
407
|
-
@admin.unban :user => @user, :in_community => @community
|
408
|
-
|
409
|
-
To check that user is banned:
|
410
|
-
|
411
|
-
@community.include_banned_user? @user
|
412
|
-
|
413
|
-
Community's users can have different types of access to community - some of them can send post to it, other can not.
|
414
|
-
This applies to both types of community - private and public. By default all new users can send posts to the community (except for the muted users).
|
415
|
-
*Notice: do not forget to check the admin rights for operations with Read/Write community access*
|
416
|
-
|
417
|
-
To set default access for new users to read (does not affect users who are already in the community):
|
418
|
-
|
419
|
-
@community.change_default_access_to_read
|
420
|
-
|
421
|
-
To set default access for new users to write (does not affect users who are already in the community):
|
422
|
-
|
423
|
-
@community.change_default_access_to_write
|
424
|
-
|
425
|
-
To set write access for users who are already in the community:
|
426
|
-
|
427
|
-
@community.set_write_access [@user.id, @another_user.id]
|
428
|
-
|
429
|
-
To set read access for users who are already in the community:
|
430
|
-
|
431
|
-
@community.set_read_access [@user.id, @another_user.id]
|
432
|
-
|
433
|
-
To get ids of users with write access (result could include muted users ids):
|
434
|
-
|
435
|
-
@community.writers_row
|
436
|
-
|
437
|
-
Community blogline is consists of the posts of members that have added to it.
|
438
|
-
|
439
|
-
To get it:
|
440
|
-
|
441
|
-
@community.blogline(:last_shown_obj_id => nil, :limit => 10, :for_user => nil)
|
442
|
-
|
443
|
-
where parameters are similar with described
|
444
|
-
[above](https://github.com/salkar/inkwell#favorite-features) favoriteline
|
445
|
-
parameters.
|
446
|
-
|
447
|
-
More examples you can find in this
|
448
|
-
[spec](https://github.com/salkar/inkwell/blob/master/lib/acts_as_inkwell_community/base.rb)
|
449
|
-
|
450
|
-
## License
|
451
|
-
Inkwell is Copyright © 2013 Sergey Sokolov. It is free software, and may be
|
452
|
-
redistributed under the terms specified in the MIT-LICENSE file.
|
453
|
-
|
454
|
-
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/ca9e83bea0d6c79d5909780eb805e944 "githalytics.com")](http://githalytics.com/salkar/inkwell)
|