social_stream 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +117 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +63 -0
  5. data/Rakefile +43 -0
  6. data/app/controllers/home_controller.rb +3 -0
  7. data/app/helpers/activities_helper.rb +10 -0
  8. data/app/models/activity.rb +75 -0
  9. data/app/models/activity_object.rb +18 -0
  10. data/app/models/activity_object_activity.rb +4 -0
  11. data/app/models/activity_verb.rb +14 -0
  12. data/app/models/actor.rb +31 -0
  13. data/app/models/permission.rb +4 -0
  14. data/app/models/relation.rb +73 -0
  15. data/app/models/relation_permission.rb +4 -0
  16. data/app/models/tie.rb +207 -0
  17. data/app/models/user.rb +82 -0
  18. data/app/views/activities/_activity.html.erb +5 -0
  19. data/app/views/activities/_activity_options.html.erb +8 -0
  20. data/app/views/activities/_jquery.html.erb +52 -0
  21. data/app/views/activities/_new.html.erb +13 -0
  22. data/app/views/activities/_root_activity.html.erb +44 -0
  23. data/app/views/activities/_subactivity.html.erb +23 -0
  24. data/app/views/activities/_subactivity_options.html.erb +7 -0
  25. data/app/views/devise/registrations/new.html.erb +21 -0
  26. data/app/views/home/_activities.html.erb +19 -0
  27. data/app/views/home/_location.html.erb +3 -0
  28. data/app/views/home/index.html.erb +4 -0
  29. data/app/views/ties/_pending.html.erb +33 -0
  30. data/config/locales/en.yml +29 -0
  31. data/lib/generators/social_stream/USAGE +9 -0
  32. data/lib/generators/social_stream/install_generator.rb +30 -0
  33. data/lib/generators/social_stream/templates/initializer.rb +14 -0
  34. data/lib/generators/social_stream/templates/migration.rb +131 -0
  35. data/lib/generators/social_stream/templates/seeds.yml +29 -0
  36. data/lib/social_stream.rb +49 -0
  37. data/lib/social_stream/models/activity_object.rb +59 -0
  38. data/lib/social_stream/models/actor.rb +30 -0
  39. data/lib/social_stream/models/supertype.rb +41 -0
  40. data/lib/social_stream/rails.rb +13 -0
  41. data/lib/social_stream/rails/common.rb +34 -0
  42. data/lib/social_stream/rails/engine.rb +7 -0
  43. data/lib/social_stream/rails/railtie.rb +7 -0
  44. data/lib/social_stream/rails/routes.rb +17 -0
  45. data/lib/social_stream/seed.rb +47 -0
  46. data/lib/social_stream/version.rb +3 -0
  47. metadata +144 -0
@@ -0,0 +1,7 @@
1
+ <div class="activity_options">
2
+ <ul class="activity_options" >
3
+ <li><div class="post_time_ago"><%= t('time.ago', :time => time_ago_in_words(activity.created_at)) %></div></li>
4
+ <li><div class="verb_like" id="like_<%= dom_id(activity) %>"> · <%= like_activity(activity)%></div></li>
5
+ <li><div class="verb_delete"> · <%= link_to t('activity.delete'), activity.direct_object , :confirm => t('activity.confirm_delete'), :method => :delete, :remote => true %> </div></li>
6
+ </ul>
7
+ </div>
@@ -0,0 +1,21 @@
1
+ <h2>Sign up</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :name %><br />
7
+ <%= f.text_field :name %></p>
8
+
9
+ <p><%= f.label :email %><br />
10
+ <%= f.text_field :email %></p>
11
+
12
+ <p><%= f.label :password %><br />
13
+ <%= f.password_field :password %></p>
14
+
15
+ <p><%= f.label :password_confirmation %><br />
16
+ <%= f.password_field :password_confirmation %></p>
17
+
18
+ <p><%= f.submit "Sign up" %></p>
19
+ <% end %>
20
+
21
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,19 @@
1
+ <%= content_for :head, stylesheet_link_tag("activities", :media => "screen, projection") %>
2
+ <%= content_for :javascript do %>
3
+ <%= render :partial => 'activities/jquery' %>
4
+ <% end -%>
5
+
6
+ <div id="wrapper_activities">
7
+ <div id="wrapper_activities_header">
8
+ <div id="activities_title" class="content_size">
9
+ <%= image_tag("buttons/btn_activities.png") %> <%=t('activity.other')%>
10
+ </div>
11
+
12
+ <%= render :partial => 'activities/new' %>
13
+ </div>
14
+ <div id="wall">
15
+ <% if current_user.wall.any? %>
16
+ <%= render current_user.wall %>
17
+ <% end %>
18
+ </div>
19
+ </div>
@@ -0,0 +1,3 @@
1
+ <div id="map_location" class="content_size">
2
+ <%= t('location.message', :location => "#{ image_tag('buttons/btn_home.png' , :class => 'btn_config') } #{ t('home.one') }: <span class=\"name_group\">#{ sanitize current_user.name }</span>").html_safe %>
3
+ </div>
@@ -0,0 +1,4 @@
1
+ <%= render :partial => 'home/location' %>
2
+
3
+ <%= render :partial => "home/activities" %>
4
+
@@ -0,0 +1,33 @@
1
+ <% if actor.ties.pending.any? %>
2
+ <div class="middle_box">
3
+ <div class="middle_box_header">
4
+ <%= image_tag('notifications.png', :class => "middle_box_picture_icon") %>
5
+ <div class="middle_box_text_header"><%= t 'tie.pending.other' %></div>
6
+ <div class="title_righ">
7
+ <a href="#"><%= t 'tie.pending.see_all' %></a>
8
+ </div>
9
+ </div>
10
+ <% actor.ties.pending.each do |tie| %>
11
+ <div class="middle_box_content">
12
+ <div class="actor_logo">
13
+ <%= link_to(image_tag(tie.sender_subject.logo, :size => "55x40"),
14
+ tie.sender_subject.name) %>
15
+ </div>
16
+ <div class="middle_box_description">
17
+ <div class="middle_box_link">
18
+ <%= link_to(tie.sender_subject.name, tie.sender_subject) %>
19
+ </div>
20
+ <div class="middle_box_brief">
21
+ 18 contacts in common
22
+ </div>
23
+ <%= link_to t('new', :scope => tie.relation.granted.name),
24
+ new_tie_path("tie[sender_id]" => current_user.actor.id,
25
+ "tie[receiver_id]" => tie.sender.id,
26
+ "tie[relation_name]" => tie.relation.granted.name),
27
+ :remote => true %>
28
+ </div>
29
+ </div>
30
+ <% end %>
31
+ </div>
32
+ <% end -%>
33
+
@@ -0,0 +1,29 @@
1
+ en:
2
+ activity:
3
+ one: "Activity"
4
+ other: "Activities"
5
+ input: "What do you do?"
6
+ confirm_delete: "Delete activity?"
7
+ delete: "Delete"
8
+ to_comment: "Comment"
9
+ like: I like
10
+ unlike: Already I do not like
11
+ comment:
12
+ input: "Write a comment..."
13
+ home:
14
+ one: "Home"
15
+ location:
16
+ message: "You are here > %{location}"
17
+ tie:
18
+ pending:
19
+ other: Pending requests
20
+ see_all: See all
21
+ time:
22
+ ago: "%{time} ago"
23
+ days: Days
24
+ delete:
25
+ confirm: Delete %{element}}?
26
+ socialstream: "SocialStream"
27
+ ask:
28
+ add_friend: "¿Add %{name} as friend?"
29
+ all_rights_reserved: All rights reserved
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Initial migration and configuration
3
+
4
+ Example:
5
+ rails generate social_stream:install
6
+
7
+ This will create:
8
+ config/initializers/social_stream.rb
9
+ db/migrate/social_stream.rb migration
@@ -0,0 +1,30 @@
1
+ class SocialStream::InstallGenerator < Rails::Generators::Base #:nodoc:
2
+ include Rails::Generators::Migration
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def create_initializer_file
7
+ copy_file 'initializer.rb', 'config/initializers/social_stream.rb'
8
+ end
9
+
10
+ def create_config_file
11
+ copy_file 'seeds.yml', 'db/seeds/social_stream.yml'
12
+ end
13
+
14
+ # TODO: hook_for :orm
15
+ require 'rails/generators/active_record'
16
+
17
+ def self.next_migration_number(dirname)
18
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
19
+ end
20
+
21
+ def create_migration_file
22
+ migration_template 'migration.rb', 'db/migrate/create_social_stream.rb'
23
+ end
24
+
25
+ def add_social_stream_routes
26
+ route "social_stream"
27
+ end
28
+
29
+ hook_for :authentication
30
+ end
@@ -0,0 +1,14 @@
1
+ SocialStream.setup do |config|
2
+ # List the models that are social entities. These will have ties between them.
3
+ #
4
+ # Remember you must add an "actor_id" foreign key column to your migration!
5
+ #
6
+ config.actors = [:user ]
7
+
8
+ # Contents managed by actors
9
+ #
10
+ # Remember you must add an "activity_object_id" foreign key column to your migration!
11
+ #
12
+ # Example: config.activity_objects = [ :post, :comment, :photo ]
13
+ config.activity_objects = []
14
+ end
@@ -0,0 +1,131 @@
1
+ class CreateSocialStream < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "activities", :force => true do |t|
4
+ t.integer "activity_verb_id"
5
+ t.integer "tie_id"
6
+ t.datetime "created_at"
7
+ t.datetime "updated_at"
8
+ t.string "ancestry"
9
+ end
10
+
11
+ add_index "activities", ["activity_verb_id"], :name => "fk_activity_verb"
12
+ add_index "activities", ["tie_id"], :name => "fk_activities_tie"
13
+
14
+ create_table "activity_object_activities", :force => true do |t|
15
+ t.integer "activity_id"
16
+ t.integer "activity_object_id"
17
+ t.datetime "created_at"
18
+ t.datetime "updated_at"
19
+ t.string "type", :limit => 45
20
+ end
21
+
22
+ add_index "activity_object_activities", ["activity_id"], :name => "fk_activity_object_activities_1"
23
+ add_index "activity_object_activities", ["activity_object_id"], :name => "fk_activity_object_activities_2"
24
+
25
+ create_table "activity_objects", :force => true do |t|
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ t.string "object_type", :limit => 45
29
+ end
30
+
31
+ create_table "activity_verbs", :force => true do |t|
32
+ t.string "name", :limit => 45
33
+ t.datetime "created_at"
34
+ t.datetime "updated_at"
35
+ end
36
+
37
+ create_table "actors", :force => true do |t|
38
+ t.string "name", :limit => 45
39
+ t.string "email", :default => "", :null => false
40
+ t.string "permalink", :limit => 45
41
+ t.boolean "disabled", :default => false
42
+ t.datetime "created_at"
43
+ t.datetime "updated_at"
44
+ t.integer "activity_object_id"
45
+ end
46
+
47
+ add_index "actors", ["activity_object_id"], :name => "fk_actors_activity_object"
48
+ add_index "actors", ["email"], :name => "index_actors_on_email"
49
+ add_index "actors", ["permalink"], :name => "index_actors_on_permalink", :unique => true
50
+
51
+ create_table "permissions", :force => true do |t|
52
+ t.string "action"
53
+ t.string "object"
54
+ t.string "parameter"
55
+ t.datetime "created_at"
56
+ t.datetime "updated_at"
57
+ end
58
+
59
+ create_table "relation_permissions", :force => true do |t|
60
+ t.integer "relation_id"
61
+ t.integer "permission_id"
62
+ t.datetime "created_at"
63
+ t.datetime "updated_at"
64
+ t.integer "relation_id"
65
+ end
66
+
67
+ add_index "relation_permissions", ["relation_id"], :name => "fk_relation_permissions_relation"
68
+ add_index "relation_permissions", ["permission_id"], :name => "fk_relation_permissions_permission"
69
+
70
+ create_table "relations", :force => true do |t|
71
+ t.string "name", :limit => 45
72
+ t.datetime "created_at"
73
+ t.datetime "updated_at"
74
+ t.string "sender_type"
75
+ t.string "receiver_type"
76
+ t.string "ancestry"
77
+ t.integer "inverse_id"
78
+ t.integer "granted_id"
79
+ end
80
+
81
+ add_index "relations", ["ancestry"]
82
+
83
+ create_table "tags", :force => true do |t|
84
+ t.string "name", :limit => 45
85
+ t.datetime "created_at"
86
+ t.datetime "updated_at"
87
+ end
88
+
89
+ create_table "tags_activity_objects", :force => true do |t|
90
+ t.integer "tag_id"
91
+ t.integer "activity_object_id"
92
+ end
93
+
94
+ add_index "tags_activity_objects", ["activity_object_id"], :name => "fk_tags_activity_objects_2"
95
+ add_index "tags_activity_objects", ["tag_id"], :name => "fk_tags_activity_objects_1"
96
+
97
+ create_table "ties", :force => true do |t|
98
+ t.integer "sender_id"
99
+ t.integer "receiver_id"
100
+ t.integer "relation_id"
101
+ t.datetime "created_at"
102
+ t.datetime "updated_at"
103
+ end
104
+
105
+ add_index "ties", ["receiver_id"], :name => "fk_tie_receiver"
106
+ add_index "ties", ["relation_id"], :name => "fk_tie_relation"
107
+ add_index "ties", ["sender_id"], :name => "fk_tie_sender"
108
+
109
+ create_table "users", :force => true do |t|
110
+ t.database_authenticatable :null => false
111
+ t.recoverable
112
+ t.rememberable
113
+ t.trackable
114
+
115
+ # t.confirmable
116
+ # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
117
+ # t.token_authenticatable
118
+
119
+ t.timestamps
120
+ t.integer "actor_id"
121
+ end
122
+
123
+ add_index "users", ["actor_id"], :name => "fk_users_actors"
124
+ add_index "users", :reset_password_token, :unique => true
125
+ # add_index :users, :confirmation_token, :unique => true
126
+ # add_index :users, :unlock_token, :unique => true
127
+ end
128
+
129
+ def self.down
130
+ end
131
+ end
@@ -0,0 +1,29 @@
1
+ # Seed configuration for Social Stream
2
+ #
3
+ # Define your relations and add SocialStream.seed! to db/seeds.rb
4
+ #
5
+ # Example
6
+ # relations:
7
+ # user-friend:
8
+ # sender_type: User
9
+ # receiver_type: User
10
+ # name: friend
11
+ # permissions:
12
+ # - [ create, resources, weak_set ]
13
+ # - [ read, resources, group_set ]
14
+ # - [ update, resources, weak_set ]
15
+ # - [ destroy, resources, weak_set ]
16
+ # user-fof:
17
+ # sender_type: User
18
+ # receiver_type: User
19
+ # name: friend_of_friend
20
+ # parent: user-friend
21
+ # permissions:
22
+ # - [ read, resources, group_set ]
23
+ # user-public:
24
+ # sender_type: User
25
+ # receiver_type: User
26
+ # name: public
27
+ # parent: user-fof
28
+ # permissions:
29
+ # - [ read, resources, group_set ]
@@ -0,0 +1,49 @@
1
+ # Provides your Rails application with social network and activity stream support
2
+ module SocialStream
3
+ autoload :Seed, 'social_stream/seed'
4
+
5
+ module Models
6
+ autoload :Supertype, 'social_stream/models/supertype'
7
+ autoload :Actor, 'social_stream/models/actor'
8
+ autoload :ActivityObject, 'social_stream/models/activity_object'
9
+ end
10
+
11
+ mattr_accessor :actors
12
+ @@actors = []
13
+
14
+ mattr_accessor :activity_objects
15
+ @@activity_objects = []
16
+
17
+ class << self
18
+ def setup
19
+ yield self
20
+ end
21
+
22
+ def seed!
23
+ Seed.new(File.join(::Rails.root, 'db', 'seeds', 'social_stream.yml'))
24
+ end
25
+
26
+ # Load models for rewrite in application
27
+ #
28
+ # Use this method when you want to reopen some model in SocialStream in order
29
+ # to add or modify functionality
30
+ #
31
+ # Example, in app/models/user.rb
32
+ # SocialStream.require_model('user')
33
+ #
34
+ # class User
35
+ # some_new_functionality
36
+ # end
37
+ #
38
+ # Maybe Rails provides some method to do this, in this case, please tell!!
39
+ def require_model(m)
40
+ path = $:.find{ |f| f =~ Regexp.new(File.join('social_stream', 'app', 'models')) }
41
+
42
+ raise "Can't find social_stream path" if path.blank?
43
+
44
+ require_dependency File.join(path, m)
45
+ end
46
+ end
47
+ end
48
+
49
+ require 'social_stream/rails'
@@ -0,0 +1,59 @@
1
+ require 'active_support/concern'
2
+
3
+ module SocialStream
4
+ module Models
5
+ # Additional features for models that are Activity Objects
6
+ module ActivityObject
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ attr_accessor :_activity_tie_id
11
+ attr_accessor :_activity_parent_id
12
+
13
+ belongs_to :activity_object, :dependent => :destroy
14
+ has_many :activity_object_activities, :through => :activity_object
15
+
16
+ delegate :post_activity, :to => :activity_object
17
+
18
+ alias_method_chain :create_activity_object, :type
19
+ before_create :create_activity_object
20
+
21
+ before_create :create_post_activity
22
+ before_update :create_update_activity
23
+
24
+ validates_presence_of :_activity_tie
25
+ end
26
+
27
+ module InstanceMethods
28
+ def activities
29
+ activity_object_activities.includes(:activity).map(&:activity).uniq
30
+ end
31
+
32
+ # Create corresponding ActivityObject including this class type
33
+ def create_activity_object_with_type(attributes = {}) #:nodoc:
34
+ create_activity_object_without_type attributes.update(:object_type => self.class.to_s)
35
+ end
36
+
37
+ def _activity_tie
38
+ @_activity_tie ||= Tie.find(_activity_tie_id)
39
+ end
40
+
41
+ private
42
+
43
+ def create_post_activity
44
+ create_activity "post"
45
+ end
46
+
47
+ def create_update_activity
48
+ create_activity "update"
49
+ end
50
+
51
+ def create_activity(verb)
52
+ activity_object.activities.create! :verb => verb,
53
+ :tie => _activity_tie,
54
+ :parent_id => _activity_parent_id
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end