site_announcements 1.3

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 (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/BSD-LICENSE +24 -0
  4. data/Gemfile +3 -0
  5. data/README.rdoc +13 -0
  6. data/Rakefile +23 -0
  7. data/app/controllers/site_announcements_controller.rb +119 -0
  8. data/app/helpers/site_announcements_helper.rb +25 -0
  9. data/app/models/notifiee_info.rb +18 -0
  10. data/app/models/site_announcement.rb +35 -0
  11. data/app/models/site_announcement_category.rb +4 -0
  12. data/app/views/site_announcements/_feed_announcement.html.erb +11 -0
  13. data/app/views/site_announcements/_feed_announcements.html.erb +11 -0
  14. data/app/views/site_announcements/_form.html.erb +46 -0
  15. data/app/views/site_announcements/_headline_announcement.erb +6 -0
  16. data/app/views/site_announcements/_site_announcement.html.erb +21 -0
  17. data/app/views/site_announcements/edit.html.erb +15 -0
  18. data/app/views/site_announcements/feed.atom.builder +22 -0
  19. data/app/views/site_announcements/index.html.erb +3 -0
  20. data/app/views/site_announcements/new.html.erb +8 -0
  21. data/app/views/site_announcements/notification_settings.html.erb +18 -0
  22. data/app/views/site_announcements/show.html.erb +3 -0
  23. data/config/routes.rb +11 -0
  24. data/generators/site_announcements/USAGE +8 -0
  25. data/generators/site_announcements/site_announcements_generator.rb +7 -0
  26. data/generators/site_announcements/templates/migration.rb +40 -0
  27. data/install.rb +1 -0
  28. data/lib/site_announcements.rb +44 -0
  29. data/lib/site_announcements/engine.rb +5 -0
  30. data/lib/tasks/site_announcements_tasks.rake +4 -0
  31. data/site_announcements.gemspec +12 -0
  32. data/test/database.yml +3 -0
  33. data/test/fixtures/site_announcements.yml +25 -0
  34. data/test/functional/site_announcements_controller_test.rb +18 -0
  35. data/test/schema.rb +31 -0
  36. data/test/test_helper.rb +40 -0
  37. data/test/unit/notifiee_info_test.rb +49 -0
  38. data/test/unit/site_announcements_test.rb +59 -0
  39. data/uninstall.rb +1 -0
  40. metadata +95 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 71ab6594ab5984ab674a4ad0cd16d413096142e9
4
+ data.tar.gz: 241473e50508528b6271ee824d09fb72dbb07d1c
5
+ SHA512:
6
+ metadata.gz: 38e693ab003c3289f4eb9a3e7571ab506ab63b284a014b8a7740b95bac94e43b66c7de6b964e263ecd203fb082e387fd50f503c66981cc1e21a04296c0c11365
7
+ data.tar.gz: ac2966d9b65ed2d2e68367bbad7aa93955cca4341434e37975cf684d90dc652c5b066de63bfb9ab778153778a348ea8c77fa22ce7ee519c2ef57d75b942fd0df
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *~
2
+ .idea
3
+ Gemfile.lock
data/BSD-LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2009, University of Manchester & HITS gGmbH
2
+ All rights reserved.
3
+
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
9
+ and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
12
+ * Neither the name of the University of Manchester or EML Research gGmbH,
13
+ nor the names of its contributors may be used to endorse or promote products
14
+ derived from this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'uuid','~>2.3'
data/README.rdoc ADDED
@@ -0,0 +1,13 @@
1
+ = site_announcements Gem
2
+ == Install
3
+ Put this line into Gemfile:
4
+ gem 'site_announcements', :git => 'git://github.com/quyen/site_announcements.git'
5
+
6
+ == Introduction
7
+ Introduction goes here.
8
+
9
+ == Usage
10
+ Usage goes here.
11
+
12
+
13
+ Copyright (c) 2010 [name of plugin creator], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the site_announcements plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the site_announcements plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'SiteAnnouncements'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
@@ -0,0 +1,119 @@
1
+ class SiteAnnouncementsController < ApplicationController
2
+ before_filter :login_required, :except=>[:feed,:notification_settings,:update_notification_settings]
3
+
4
+ before_filter :check_manage_announcements,:only=>[:new,:create,:edit,:update,:destroy]
5
+
6
+ def feed
7
+ limit=params[:limit]
8
+ limit||=10
9
+ @site_announcements=SiteAnnouncement.feed_announcements :limit=>limit
10
+ respond_to do |format|
11
+ format.atom
12
+ end
13
+ end
14
+
15
+ def update_notification_settings
16
+ receive_notifications = params[:receive_notifications]
17
+ receive_notifications ||= false
18
+ @info = NotifieeInfo.find_by_unique_key(params[:key])
19
+ @info.receive_notifications = receive_notifications unless @info.nil?
20
+ respond_to do |format|
21
+ if @info && @info.save
22
+ flash[:notice]="Email announcement setting updated. You will now #{"not " if !@info.receive_notifications?}receive notification emails."
23
+ format.html { redirect_to(root_url) }
24
+ else
25
+ flash[:error]="Unable to update your settings"
26
+ flash[:error]+=", the key presented wasn't recognised."
27
+ format.html { render :action => :notification_settings}
28
+ end
29
+ end
30
+ end
31
+
32
+ def destroy
33
+ @site_announcement=SiteAnnouncement.find(params[:id])
34
+
35
+ respond_to do |format|
36
+ if @site_announcement.destroy
37
+ flash[:notice]="Announcement destroyed"
38
+ format.html {redirect_to site_announcements_path}
39
+ else
40
+ flash[:error]="There was a problem destroying the announcement"
41
+ format.html { render :action=>:edit }
42
+ end
43
+ end
44
+ end
45
+
46
+ def notification_settings
47
+
48
+ @info=NotifieeInfo.find_by_unique_key(params[:key])
49
+
50
+ respond_to do |format|
51
+ if @info.nil?
52
+ flash[:error]="Invalid Key"
53
+ format.html{ redirect_to root_url }
54
+ else
55
+ format.html
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ def new
62
+ @site_announcement=SiteAnnouncement.new
63
+ end
64
+
65
+ def create
66
+ @site_announcement=SiteAnnouncement.new(params[:site_announcement])
67
+ @site_announcement.announcer = current_person
68
+
69
+ respond_to do |format|
70
+ if @site_announcement.save
71
+ flash[:notice] = 'The Announcement was successfully announced.'
72
+ format.html { redirect_to(@site_announcement) }
73
+ format.xml { render :xml => @site_announcement, :status => :created, :location => @site_announcement }
74
+ else
75
+ format.html { render :action => "new" }
76
+ format.xml { render :xml => @site_announcement.errors, :status => :unprocessable_entity }
77
+ end
78
+ end
79
+ end
80
+
81
+ def edit
82
+ @site_announcement=SiteAnnouncement.find(params[:id])
83
+ end
84
+
85
+ def update
86
+ @site_announcement=SiteAnnouncement.find(params[:id])
87
+
88
+ respond_to do |format|
89
+ if @site_announcement.update_attributes(params[:site_announcement])
90
+ flash[:notice] = 'Announcement was successfully updated.'
91
+ format.html { redirect_to(@site_announcement) }
92
+ format.xml { head :ok }
93
+ else
94
+ format.html { render :action => "edit" }
95
+ format.xml { render :xml => @site_announcement.errors, :status => :unprocessable_entity }
96
+ end
97
+ end
98
+ end
99
+
100
+ def show
101
+ @site_announcement=SiteAnnouncement.find(params[:id])
102
+ end
103
+
104
+ def index
105
+ if params[:feed_only]
106
+ @site_announcements=SiteAnnouncement.feed_announcements(:limit=>1000)
107
+ else
108
+ @site_announcements=SiteAnnouncement.order("created_at DESC")
109
+ end
110
+ end
111
+
112
+ def check_manage_announcements
113
+ if !can_manage_announcements?
114
+ flash[:error] = "Admin rights required"
115
+ redirect_to root_url
116
+ end
117
+ end
118
+
119
+ end
@@ -0,0 +1,25 @@
1
+
2
+
3
+ module SiteAnnouncementsHelper
4
+
5
+ def site_annoucements_headline
6
+ headline = SiteAnnouncement.headline_announcement
7
+ return "" unless headline #return empty string if there is no announcement
8
+ return render :partial=>"site_announcements/headline_announcement",:object=>headline
9
+ end
10
+
11
+ def site_announcements_feed options
12
+ options[:limit]||=5
13
+ announcements = SiteAnnouncement.feed_announcements :limit=>options[:limit]
14
+ return render :partial=>"site_announcements/feed_announcements",:object=>announcements,:locals=>{:truncate_length=>options[:truncate_length],:limit=>options[:limit]}
15
+ end
16
+
17
+ def site_announcement_attributes announcement
18
+ attr=[]
19
+ attr << "show in feed" if announcement.show_in_feed?
20
+ attr << "headline" if announcement.is_headline?
21
+ attr << "mail" if announcement.email_notification?
22
+ attr
23
+ end
24
+
25
+ end
@@ -0,0 +1,18 @@
1
+ require 'uuid'
2
+
3
+ class NotifieeInfo < ActiveRecord::Base
4
+ belongs_to :notifiee,:polymorphic=>true
5
+ validates_presence_of :notifiee
6
+
7
+
8
+ before_save :check_unique_key
9
+
10
+ private
11
+
12
+ def check_unique_key
13
+ if self.unique_key.nil? || self.unique_key.blank?
14
+ self.unique_key = UUID.generate
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,35 @@
1
+ class SiteAnnouncement < ActiveRecord::Base
2
+
3
+ class BodyHelper
4
+ include ActionView::Helpers::TextHelper
5
+ include ActionView::Helpers::TagHelper
6
+ include ActionView::Helpers::UrlHelper
7
+ end
8
+
9
+ belongs_to :site_announcement_category
10
+ belongs_to :announcer,:polymorphic=>true
11
+
12
+ scope :headline_announcements,:conditions=>(["is_headline = ? and expires_at > ? ",true,Time.now]),:order=>"created_at DESC",:limit=>1
13
+
14
+ validates_presence_of :title
15
+
16
+ def self.headline_announcement
17
+ self.headline_announcements.first
18
+ end
19
+
20
+ def self.feed_announcements options={}
21
+ options[:limit] ||= 5
22
+ self.where(["show_in_feed = ?",true]).order("created_at DESC").limit(options[:limit])
23
+ end
24
+
25
+ def body_html
26
+ helper.simple_format(helper.auto_link(body,:sanitize=>true),{},:sanitize=>true).html_safe
27
+ end
28
+
29
+ private
30
+
31
+ def helper
32
+ @helper ||= BodyHelper.new
33
+ end
34
+
35
+ end
@@ -0,0 +1,4 @@
1
+ class SiteAnnouncementCategory < ActiveRecord::Base
2
+ has_many :site_announcements
3
+ end
4
+
@@ -0,0 +1,11 @@
1
+ <%
2
+ show_seperator||=false
3
+ %>
4
+ <li class="feed_announcement">
5
+ <span class="announcement_title"><%= link_to(h(feed_announcement.title),feed_announcement) -%></span>
6
+ <span class="announcement_date"><%= time_ago_in_words(feed_announcement.created_at)+" ago" -%></span>
7
+ <span class="announcement_announcer"> by <%= link_to h(feed_announcement.announcer.name), feed_announcement.announcer -%></span>
8
+ <% if show_seperator -%>
9
+ <div class="announcement_seperator"></div>
10
+ <% end -%>
11
+ </li>
@@ -0,0 +1,11 @@
1
+
2
+ <ul class="feed_announcement_list">
3
+ <%= render :partial => "site_announcements/feed_announcement",:collection=>feed_announcements,:locals=>{:truncate_length=>truncate_length,:show_seperator=>true} %>
4
+ <li class="feed_announcement">
5
+ <% if SiteAnnouncement.count > limit -%>
6
+ <center>
7
+ <span class="announcement_title"><%= link_to "See all",site_announcements_path(:feed_only=>true) -%></span>
8
+ </center>
9
+ <% end -%>
10
+ </li>
11
+ </ul>
@@ -0,0 +1,46 @@
1
+ <%= f.error_messages -%>
2
+ <p>
3
+ <%= f.label :title -%>
4
+ <br/>
5
+ <%= f.text_field :title,:size=>75 -%>
6
+ </p>
7
+ <p>
8
+ <%= f.label :body -%>
9
+ <br/>
10
+ <%= f.text_area :body, :rows=>20,:cols=>75 -%>
11
+ </p>
12
+ <p>
13
+ <%= f.label :show_in_feed -%>
14
+ <%= f.check_box :show_in_feed -%>
15
+ </p>
16
+ <p>
17
+ <%= f.label :is_headline,"Headline announcement" -%>
18
+ <%= f.check_box :is_headline,{:onchange=>"toggle_expires_at();"} -%>
19
+ <div id="announcement_expires" style="display: none;">
20
+ <%= f.label :expires,"Expires at" -%>
21
+ <br/>
22
+ <%= datetime_select "site_announcement","expires_at" -%>
23
+ <br/>
24
+ <span class="headline_announcement_date">( Current server time is <%= Time.now.utc -%> )</span>
25
+ </div>
26
+ </p>
27
+ <p>
28
+ <%= f.label :email_notification -%>
29
+ <% if edit -%>
30
+ <%= f.check_box :email_notification, :disabled=>true -%>
31
+ <% else -%>
32
+ <%= f.check_box :email_notification -%>
33
+ <% end -%>
34
+ </p>
35
+ <script type="text/javascript">
36
+ function toggle_expires_at(){
37
+ if ($("site_announcement_is_headline").checked) {
38
+ Effect.Appear("announcement_expires");
39
+ }
40
+ else {
41
+ Effect.Fade("announcement_expires")
42
+ }
43
+ }
44
+
45
+ toggle_expires_at();
46
+ </script>
@@ -0,0 +1,6 @@
1
+ <% if can_manage_announcements? -%>
2
+ <span class="headline_announcement_edit"><%= link_to "Edit",edit_site_announcement_path(headline_announcement) -%></span>
3
+ <% end -%>
4
+ <span class="headline_announcement_title"><%= h(headline_announcement.title) -%></span><br/>
5
+ <span class="headline_announcement_date"><%= time_ago_in_words(headline_announcement.created_at)+" ago" -%></span><br/>
6
+ <span class="headline_announcement_body"><%= headline_announcement.body_html.html_safe -%></span>
@@ -0,0 +1,21 @@
1
+ <%
2
+ show_seperator||=false
3
+ %>
4
+ <li class="announcement">
5
+ <span class="announcement_title"><%= h(site_announcement.title) -%></span>
6
+ <span class="announcement_date"><%= site_announcement.created_at.strftime('%d/%m/%Y @ %H:%M:%S') -%></span>
7
+ <span class="announcement_announcer"> by <%= link_to h(site_announcement.announcer.name), site_announcement.announcer -%></span>
8
+ <span class="announcement_body"><%= site_announcement.body_html -%></span>
9
+ <% if can_manage_announcements? -%>
10
+ <%
11
+ attributes=site_announcement_attributes(site_announcement)
12
+ unless attributes.empty?
13
+ %>
14
+ <span class="announcement_attributes"><%= "("+attributes.join(", ") + ")" -%></span>
15
+ <% end -%>
16
+ <span class="announcement_edit"><%= link_to "Edit",edit_site_announcement_path(site_announcement) -%></span>
17
+ <% end %>
18
+ <% if show_seperator -%>
19
+ <div class="announcement_seperator"></div>
20
+ <% end -%>
21
+ </li>
@@ -0,0 +1,15 @@
1
+ <div id="announcement_form">
2
+ <h1>Editing the announcement '<%= h(@site_announcement.title) -%>'</h1>
3
+
4
+ <p>
5
+ <%= link_to "Destroy announcement", site_announcement_path(@site_announcement), :method=>:delete, :confirm=>"Are you sure you wish to delete this announcement?" -%>
6
+ <% if @site_announcement.email_notification? -%>
7
+ <br/><span class="comment">(This announcement included an email notification, so you may not want to delete)</span>
8
+ <% end -%>
9
+ </p>
10
+ <%= form_for @site_announcement do |f| -%>
11
+ <%= render :partial=>"form",:locals=>{:f=>f,:edit=>true} %>
12
+ <br/>
13
+ <%= f.submit "Update" -%>
14
+ <% end -%>
15
+ </div>
@@ -0,0 +1,22 @@
1
+ atom_feed(:url => site_announcements_url(:format => :atom),
2
+ :root_url => site_announcements_url,
3
+ :schema_date => "2009") do |feed|
4
+
5
+ feed.title("SEEK Announcements")
6
+ if @site_announcements.empty?
7
+ feed.updated Time.now
8
+ else
9
+ feed.updated @site_announcements.first.updated_at
10
+ end
11
+
12
+ for announcement in @site_announcements
13
+ next if announcement.updated_at.blank?
14
+ feed.entry(announcement) do |entry|
15
+ entry.title(announcement.title)
16
+ entry.content(announcement.body_html, :type =>'html')
17
+ entry.author do |author|
18
+ author.name(announcement.announcer.name)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ <ul class="announcement_list">
2
+ <%= render :partial=>"site_announcement",:collection=>@site_announcements,:locals=>{:show_seperator=>true} %>
3
+ </ul>
@@ -0,0 +1,8 @@
1
+ <div id="announcement_form">
2
+ <h1>New announcement</h1>
3
+ <%= form_for @site_announcement do |f| -%>
4
+ <%= render :partial=>"form",:locals=>{:f=>f,:edit=>false} %>
5
+ <br/>
6
+ <%= f.submit "Create" -%>
7
+ <% end -%>
8
+ </div>
@@ -0,0 +1,18 @@
1
+ <% text=@info.receive_notifications? ? " are currently receiving " : " are currently <b>not</b> receiving " -%>
2
+ <div id="notification_setttings">
3
+ <p>
4
+ You have been identified as <b><%= h(@info.notifiee.name) -%></b>, and you <%= text -%>announcements through email.
5
+ </p>
6
+ <p>
7
+ Please change the setting below to your preferred setting:
8
+ </p>
9
+ <%= form_tag update_notification_settings_site_announcements_path do -%>
10
+ <%= hidden_field_tag :key, @info.unique_key -%>
11
+ <p>
12
+ Receive site annoucement emails: <%= check_box_tag(:receive_notifications, value="true", checked=@info.receive_notifications?, options = {}) -%>
13
+ </p>
14
+ <p>
15
+ <%= submit_tag "Update" %>
16
+ </p>
17
+ <% end -%>
18
+ </div>
@@ -0,0 +1,3 @@
1
+ <ul class="announcement">
2
+ <%= render :partial=>"site_announcement",:object=>@site_announcement -%>
3
+ </ul>
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ Rails.application.routes.draw do
2
+
3
+ resources :site_announcements do
4
+ collection do
5
+ get :feed
6
+ get :notification_settings
7
+ post :update_notification_settings
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates the migration required to use the site_announcements plugin
3
+
4
+ Example:
5
+ ./script/generate site_announcements_migration
6
+
7
+ This will create:
8
+ the migration for SiteAnnouncement and SiteAnnouncementCategory
@@ -0,0 +1,7 @@
1
+ class SiteAnnouncementsGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "site_announcements_migration"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ class SiteAnnouncementsMigration < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :site_announcements do |t|
4
+ t.column :announcer_id,:integer
5
+ t.column :announcer_type,:string
6
+ t.column :title, :string
7
+ t.column :body,:text
8
+ t.column :site_announcement_category_id,:integer
9
+ t.column :is_headline,:boolean,:default=>false
10
+ t.column :expires_at,:datetime
11
+ t.column :show_in_feed,:boolean,:default=>true
12
+ t.column :email_notification,:boolean,:default=>false
13
+
14
+ t.timestamps
15
+ end
16
+
17
+ create_table :site_announcement_categories do |t|
18
+ t.column :title, :string
19
+ t.column :icon_key,:string
20
+
21
+ t.timestamps
22
+ end
23
+
24
+ create_table :notifiee_infos do |t|
25
+ t.column :notifiee_id,:integer
26
+ t.column :notifiee_type,:string
27
+ t.column :unique_key,:string
28
+ t.column :receive_notifications,:boolean,:default=>true
29
+
30
+ t.timestamps
31
+ end
32
+
33
+ end
34
+
35
+ def self.down
36
+ drop_table :site_announcements
37
+ drop_table :site_announcement_categories
38
+ drop_table :notifiee_infos
39
+ end
40
+ end
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,44 @@
1
+ module SiteAnnouncements
2
+
3
+ require 'site_announcements/engine' if defined?(Rails)
4
+
5
+ module Acts
6
+ def self.included(mod)
7
+ mod.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def acts_as_notifiee(options = {}, &extension)
12
+
13
+ has_one :notifiee_info,:dependent=>:destroy,:as=>:notifiee
14
+
15
+ before_save :check_for_notifiee_info
16
+
17
+ extend SiteAnnouncements::Acts::SingletonMethods
18
+ include SiteAnnouncements::Acts::InstanceMethods
19
+ end
20
+ end
21
+
22
+ module SingletonMethods
23
+
24
+ end
25
+
26
+ module InstanceMethods
27
+
28
+ def check_for_notifiee_info
29
+ if (self.notifiee_info.nil?)
30
+ n=NotifieeInfo.new
31
+ self.notifiee_info=n
32
+ end
33
+ end
34
+
35
+ def receive_notifications?
36
+ self.notifiee_info.try:receive_notifications?
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
43
+
44
+ ActiveRecord::Base.send(:include,SiteAnnouncements::Acts)
@@ -0,0 +1,5 @@
1
+ module SiteAnnouncements
2
+ class Engine < ::Rails::Engine
3
+
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :site_announcements do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'site_announcements'
3
+ s.version = '1.3'
4
+ s.date = '2015-02-16'
5
+ s.summary = "Site announcements"
6
+ s.authors = ["Stuart Owen","Quyen Nguyen"]
7
+ s.email = 'nttqa22001@yahoo.com'
8
+ s.files = `git ls-files`.split("\n")
9
+ s.homepage = 'https://github.com/SysMO-DB/site_announcements'
10
+ s.require_paths = ["lib"]
11
+ s.add_runtime_dependency "uuid", "~> 2.3"
12
+ end
data/test/database.yml ADDED
@@ -0,0 +1,3 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :dbfile: vendor/plugins/yaffle/test/test.db
@@ -0,0 +1,25 @@
1
+ headline:
2
+ title: This is a headline and feed announcement
3
+ body: the body
4
+ is_headline: true
5
+ expires_at: 2050-04-03 11:09:18
6
+ created_at: 2010_01_03
7
+ show_in_feed: true
8
+
9
+ basic:
10
+ title: This is a basic announcement
11
+ body: the body
12
+ is_headline: false
13
+ expires_at: 2050-04-03 11:09:18
14
+ created_at: 2010_01_02
15
+ show_in_feed: true
16
+
17
+ headline_no_feed:
18
+ title: This is a headline only announcement
19
+ body: the body
20
+ is_headline: true
21
+ expires_at: 2050-04-03 11:09:18
22
+ created_at: 2010_01_01
23
+ show_in_feed: false
24
+
25
+
@@ -0,0 +1,18 @@
1
+ require 'test_helper.rb'
2
+ require 'app/controllers/application'
3
+ require 'app/controllers/site_announcements_controller'
4
+ require 'action_controller/test_process'
5
+
6
+ class SiteAnnouncementsController; def rescue_action(e) raise e end; end
7
+
8
+ class SiteAnnouncementsController; def can_manage_announcements?() true end; end
9
+ class SiteAnnouncementsController; def login_required() true end; end
10
+
11
+ class SiteAnnouncementsControllerTest < ActionController::TestCase
12
+ load_schema
13
+
14
+ def test_new
15
+ get :new
16
+ assert_response :success
17
+ end
18
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,31 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table "site_announcement_categories", :force => true do |t|
3
+ t.string "title"
4
+ t.string "icon_key"
5
+ t.datetime "created_at"
6
+ t.datetime "updated_at"
7
+ end
8
+
9
+ create_table "site_announcements", :force => true do |t|
10
+ t.integer "announcer_id"
11
+ t.string "announcer_type"
12
+ t.string "title"
13
+ t.text "body"
14
+ t.integer "site_announcement_category_id"
15
+ t.boolean "is_headline", :default => false
16
+ t.datetime "expires_at"
17
+ t.boolean "show_in_feed", :default => true
18
+ t.boolean "email_notification", :default => false
19
+ t.datetime "created_at"
20
+ t.datetime "updated_at"
21
+ end
22
+
23
+ create_table "notifiee_infos", :force=>true do |t|
24
+ t.column :notifiee_id,:integer
25
+ t.column :notifiee_type,:string
26
+ t.column :unique_key,:string
27
+ t.column :receive_notifications,:boolean,:default=>true
28
+
29
+ t.timestamps
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
4
+ require 'active_record'
5
+ require 'active_record/fixtures'
6
+
7
+ ENV['RAILS_ENV'] = 'test'
8
+ ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
9
+
10
+ require 'test/unit'
11
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
12
+
13
+ def load_schema
14
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
15
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
16
+
17
+ db_adapter = ENV['DB']
18
+
19
+ # no db passed, try one of these fine config-free DBs before bombing.
20
+ db_adapter ||=
21
+ begin
22
+ require 'rubygems'
23
+ require 'sqlite'
24
+ 'sqlite'
25
+ rescue MissingSourceFile
26
+ begin
27
+ require 'sqlite3'
28
+ 'sqlite3'
29
+ rescue MissingSourceFile
30
+ end
31
+ end
32
+
33
+ if db_adapter.nil?
34
+ raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
35
+ end
36
+
37
+ ActiveRecord::Base.establish_connection(config[db_adapter])
38
+ load(File.dirname(__FILE__) + "/schema.rb")
39
+ #require File.dirname(__FILE__) + '/../rails/init.rb'
40
+ end
@@ -0,0 +1,49 @@
1
+ class NotifieeInfoTest < ActiveSupport::TestCase
2
+
3
+ def setup
4
+ load_schema
5
+ Fixtures.create_fixtures(File.join(File.dirname(__FILE__), '../fixtures'),"site_announcements")
6
+ end
7
+
8
+ def test_unique_key_generation
9
+
10
+ #the SiteAnnouncementCategory is used as a dummy notifiee
11
+ c=SiteAnnouncementCategory.new
12
+ c.save!
13
+
14
+ n=NotifieeInfo.new(:notifiee=>c)
15
+ assert_nil n.unique_key
16
+ n.save!
17
+ assert_not_nil n.unique_key
18
+ end
19
+
20
+ # def test_notifiee_info_is_deleted_when_notifiee_is
21
+ # c=SiteAnnouncementCategory.new
22
+ # c.save!
23
+ #
24
+ # n=NotifieeInfo.new(:notifiee=>c)
25
+ # n.save!
26
+ #
27
+ # assert_difference("NotifieeInfo.count",-1) do
28
+ # assert_difference("SiteAnnouncementCategory.count",-1) do
29
+ # c.destroy
30
+ # end
31
+ # end
32
+ #
33
+ # assert_nil NotifieeInfo.find_by_id(n.id)
34
+ # end
35
+
36
+ # def test_notifiee_isnt_deleted_when_notifiee_info_is
37
+ # c=SiteAnnouncementCategory.new
38
+ # c.save!
39
+ #
40
+ # n=NotifieeInfo.new(:notifiee=>c)
41
+ # n.save!
42
+ #
43
+ # assert_no_difference("SiteAnnouncementCategory.count") do
44
+ # n.destroy
45
+ # end
46
+ #
47
+ # assert_not_nil SiteAnnouncementCategory.find_by_id(c.id)
48
+ # end
49
+ #end
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+
3
+ class SiteAnnouncementsTest < ActiveSupport::TestCase
4
+
5
+
6
+
7
+ def setup
8
+ load_schema
9
+ Fixtures.create_fixtures(File.join(File.dirname(__FILE__), '../fixtures'),"site_announcements")
10
+ end
11
+
12
+ test "using fixtures" do
13
+ assert_not_nil SiteAnnouncement.find(:first)
14
+ end
15
+
16
+ test "headline" do
17
+ hl=SiteAnnouncement.headline_announcement
18
+ assert_not_nil hl
19
+ assert_equal "This is a headline and feed announcement",hl.title
20
+
21
+ hl.expires_at = Time.now - 1.hour
22
+ hl.save!
23
+
24
+ hl=SiteAnnouncement.headline_announcement
25
+ assert_not_nil hl
26
+ assert_equal "This is a headline only announcement",hl.title
27
+
28
+ hl.expires_at = Time.now - 1.hour
29
+ hl.save!
30
+
31
+ assert_nil SiteAnnouncement.headline_announcement
32
+ end
33
+
34
+ test "new headline comes out top" do
35
+ hl=SiteAnnouncement.headline_announcement
36
+ assert_not_nil hl
37
+ assert_equal "This is a headline and feed announcement",hl.title
38
+
39
+ ann=SiteAnnouncement.new(:title=>"brand new",:expires_at=>Time.now + 1.day,:is_headline=>true)
40
+ ann.save!
41
+
42
+ hl=SiteAnnouncement.headline_announcement
43
+ assert_not_nil hl
44
+ assert_equal "brand new",hl.title
45
+ end
46
+
47
+ test "feed" do
48
+ list = SiteAnnouncement.feed_announcements
49
+ assert_equal 2,list.size
50
+ assert_equal "This is a headline and feed announcement",list[0].title
51
+ assert_equal "This is a basic announcement",list[1].title
52
+
53
+ list = SiteAnnouncement.feed_announcements :limit=>1
54
+ assert_equal 1,list.size
55
+ assert_equal "This is a headline and feed announcement",list[0].title
56
+ end
57
+
58
+
59
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: site_announcements
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.3'
5
+ platform: ruby
6
+ authors:
7
+ - Stuart Owen
8
+ - Quyen Nguyen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: uuid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.3'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.3'
28
+ description:
29
+ email: nttqa22001@yahoo.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - BSD-LICENSE
36
+ - Gemfile
37
+ - README.rdoc
38
+ - Rakefile
39
+ - app/controllers/site_announcements_controller.rb
40
+ - app/helpers/site_announcements_helper.rb
41
+ - app/models/notifiee_info.rb
42
+ - app/models/site_announcement.rb
43
+ - app/models/site_announcement_category.rb
44
+ - app/views/site_announcements/_feed_announcement.html.erb
45
+ - app/views/site_announcements/_feed_announcements.html.erb
46
+ - app/views/site_announcements/_form.html.erb
47
+ - app/views/site_announcements/_headline_announcement.erb
48
+ - app/views/site_announcements/_site_announcement.html.erb
49
+ - app/views/site_announcements/edit.html.erb
50
+ - app/views/site_announcements/feed.atom.builder
51
+ - app/views/site_announcements/index.html.erb
52
+ - app/views/site_announcements/new.html.erb
53
+ - app/views/site_announcements/notification_settings.html.erb
54
+ - app/views/site_announcements/show.html.erb
55
+ - config/routes.rb
56
+ - generators/site_announcements/USAGE
57
+ - generators/site_announcements/site_announcements_generator.rb
58
+ - generators/site_announcements/templates/migration.rb
59
+ - install.rb
60
+ - lib/site_announcements.rb
61
+ - lib/site_announcements/engine.rb
62
+ - lib/tasks/site_announcements_tasks.rake
63
+ - site_announcements.gemspec
64
+ - test/database.yml
65
+ - test/fixtures/site_announcements.yml
66
+ - test/functional/site_announcements_controller_test.rb
67
+ - test/schema.rb
68
+ - test/test_helper.rb
69
+ - test/unit/notifiee_info_test.rb
70
+ - test/unit/site_announcements_test.rb
71
+ - uninstall.rb
72
+ homepage: https://github.com/SysMO-DB/site_announcements
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.8
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Site announcements
95
+ test_files: []