Coder Social home page Coder Social logo

newsfeed's Introduction

NewsFeed

Build Status

This module will allow users to send and receive NewsFeed notifications to any class object, like a user or a company. It comes default with Create, Update, Delete, Send, event types, but these can be customized. There is also an option to specify a custom message.

Usage

message = Message.new
current_user = User.new
recipient = User.new

# Creates a news_feed in the database with text "You have created a Message: Message Title" that is sent to recipient.  
# To get a list of message, just call 'recipient.news_feed_events'.
# The text can be customized, as well as the recipients.
message.insertNewsFeed(:Create, recipient, current_user)

Installation

NewsFeed is developed with Rails 3.2.3. First, include it in your gemfile:

gem 'news_feed'

Run bundle to install it. Then, you will need to run the generator.

rails generate news_feed

In Migration

Add this migration to your application:

def change
  create_table :news_feed_events, :force => true do |t|
    t.text  :text
    t.integer  :event_object_id
    t.string :event_object_type
    t.string :event_type
    t.integer :sender_id
    t.string :sender_type
    t.integer :recipient_id
    t.string :recipient_type
    t.timestamps
  end
end

In Models

Include 'acts_as_news_feedable' in the following models:

  1. Class that you want a list of news_feed_events.
  2. Class that that you want to call news_feed_events on.

Pass in the news_feed_object_name as a separate definition when defining acts_as_news_feedable. The object name will be used to generate the name of the subject, like a user's full name or a message title, per instance.

# In both classes you can call either user.news_feed_events or user.insertNewsFeed
class User
  acts_as_news_feedable
  
  def news_feed_object_name
    "Bob Smith"
  end
  
end

class Message
  acts_as_news_feedable
  
  def news_feed_object_name
    "Message Title"
  end
end

In Controllers

You can get the newsfeed for each acts_as_news_feedable class simply by typing:

@news_feeds = current_user.news_feed_events

In Views

After you set the instance variable, you can use group_by methods and css classes to customize the view and layout of the news feed. For example, you can create a separate icon for each event_type, and use the object_id to generate a link to that object of interest.

Adding custom messages and en_news_feed.yml

You can add define and customize additional event messages in the lib/news_feed/news_feed_events.rb. Editing the messages themselves can be done in config/locales/en.news_feed.rb.

References

  1. Default News Feed Events Samples

  2. Content of latest en_news_feed.yml (0.0.6)

  3. [Content of latest news_feed_events.rb (0.0.6)] (https://github.com/dleung/NewsFeed/wiki/Latest-news_feed_events)

Translating the messages

Simple add the corresponding translation in the locales file.

newsfeed's People

Contributors

dleung avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.