Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calebhearth/life_signs
https://github.com/calebhearth/life_signs
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/calebhearth/life_signs
- Owner: calebhearth
- License: mit
- Created: 2013-04-03T22:14:57.000Z (over 11 years ago)
- Default Branch: ct-activity
- Last Pushed: 2013-04-03T22:16:20.000Z (over 11 years ago)
- Last Synced: 2024-10-15T19:43:42.174Z (2 months ago)
- Language: Ruby
- Size: 118 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# life_signs
[![Build Status](https://travis-ci.org/calebthompson/life\_signs.png?branch=master)](https://travis-ci.org/calebthompson/life\_signs)
[![Code Climate](https://codeclimate.com/github/calebthompson/life\_signs.png)](https://codeclimate.com/github/calebthompson/life\_signs)Create activity streams in your application which can be easily filtered by
who or what created the activity or by the type of content.BUZZ
(into communicator)
No read-out yet if the air is
breathable... and there seems to be
no sign of intelligent life
anywhere --## Installation
Add life\_signs to your application’s Gemfile and run `bundle install`.
```ruby
gem 'life_signs'
```Make sure the development database exists. Then, run the generator:
```
rails g life_signs:install
```The generator creates an Activity model which includes `LifeSigns::Activity` and
has polymorphic relations to `content` and `actor`.## Usage
The `Activity` model is a glorified scope, so there should never be any need for
`content` to know about `Activity`. For this reason, we push the logic for
creating activities into the controller, with its cousins email generation and
notification creation.### Controllers
Create activities along with your content.
```ruby
class TweetsController < ActionController::Base
respond_to :htmldef create
@tweet = create_tweet
respond_with @tweet
endprivate
def create_tweet
tweet = Tweet.new(tweet_params)
create_activity(tweet)
tweet
enddef tweet_params
params.
require(:tweet).
permit(:body).
merge(user: current_user)
enddef create_activity(tweet)
Activity.create(actor: current_user, content: tweet)
end
end
```Sometimes, the `actor` won’t be a user, but some other
“subscribable” model such as a Forum:```ruby
class PostsController < ActionController::Base
respond_to :htmldef create
@post = create_post
respond_with @post
endprivate
def create_post
post = Post.new(post_params)
create_activity(post)
post
enddef post_params
params.
require(:post).
permit(:body).
merge(forum: forum, user: current_user)
enddef create_activity(post)
Activity.create(actor: current_user, content: tweet)
enddef forum
Forum.find(params[:forum_id])
end
end
```Then scope the Activities by what actors you want:
```ruby
def show
@activities = Activity.actors(forum: subscribed_forums, user: friends)
enddef subscribed_forums
current_user.subscribed_forum_ids
enddef friends
current_user.friend_ids
end
```### Views
Render the activities in your application:
`app/views/activities/_activity`
```haml
= content_tag_for(:li, activity) do
= render activity.content
````app/views/activities/index`
```haml
= render @activities
```