starburst 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +12 -0
- data/app/assets/javascripts/starburst/application.js +13 -0
- data/app/assets/javascripts/starburst/starburst.js +19 -0
- data/app/assets/stylesheets/starburst/application.css +15 -0
- data/app/controllers/starburst/announcements_controller.rb +16 -0
- data/app/controllers/starburst/application_controller.rb +4 -0
- data/app/helpers/starburst/announcements_helper.rb +11 -0
- data/app/models/starburst/announcement.rb +53 -0
- data/app/models/starburst/announcement_view.rb +7 -0
- data/app/views/announcements/starburst/_announcement.html.erb +6 -0
- data/app/views/announcements/starburst/_announcement_bootstrap.html.erb +8 -0
- data/app/views/announcements/starburst/_announcement_foundation.html.erb +6 -0
- data/app/views/layouts/starburst/application.html.erb +14 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20141004214002_create_announcement_tables.rb +17 -0
- data/lib/helpers/starburst/configuration.rb +21 -0
- data/lib/starburst.rb +9 -0
- data/lib/starburst/engine.rb +13 -0
- data/lib/starburst/version.rb +3 -0
- data/lib/tasks/starburst_tasks.rake +4 -0
- data/spec/controllers/starburst/announcements_controller_spec.rb +34 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +6 -0
- data/spec/dummy/app/controllers/pages_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +5 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/pages/home.html.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +60 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20141004231338_create_users.rb +8 -0
- data/spec/dummy/db/schema.rb +39 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1427 -0
- data/spec/dummy/log/test.log +27180 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/factories/announcements.rb +5 -0
- data/spec/factories/users.rb +5 -0
- data/spec/features/announcements_spec.rb +36 -0
- data/spec/models/starburst/announcement_spec.rb +155 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/wait_for_ajax.rb +15 -0
- metadata +274 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 975b7fa2f564bb391ef812d9b6718742853633c3
|
4
|
+
data.tar.gz: 81ca5b5b5cafed342dd0cf37ac4932c8871e130a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 056edfee84823ac0e79e5428e9b9dbf3f13e8d81a282db243e1592bbae5737038e400dddbe06007ab9d1643182545bb6916b4218b99e83ad14c03355c9f41d35
|
7
|
+
data.tar.gz: 8e172552778facca39c43400f620658fa883b7bdb56547a3b9a5e5c4c63f1ebba57b055933e1671b11c705965e8468e32d9657adb850495a3b9ff704b39717aa
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'appraisal'
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
task :default => ['appraisal:install']
|
9
|
+
|
10
|
+
task :appraise => ['appraisal:install'] do |t|
|
11
|
+
exec 'rake appraisal'
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,19 @@
|
|
1
|
+
function ready(fn) {
|
2
|
+
if (document.addEventListener) {
|
3
|
+
document.addEventListener('DOMContentLoaded', fn);
|
4
|
+
} else {
|
5
|
+
document.attachEvent('onreadystatechange', function() {
|
6
|
+
if (document.readyState === 'interactive')
|
7
|
+
fn();
|
8
|
+
});
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
ready(function addOneTimeMessagesCallbacks() {
|
13
|
+
var closeButton = document.getElementById('starburst-close');
|
14
|
+
if (closeButton !== null) {
|
15
|
+
closeButton.addEventListener('click', function() {
|
16
|
+
document.getElementById('starburst-announcement').style.display = 'none';
|
17
|
+
});
|
18
|
+
}
|
19
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Starburst
|
2
|
+
class AnnouncementsController < ApplicationController
|
3
|
+
def mark_as_read
|
4
|
+
announcement = Announcement.find(params[:id].to_i)
|
5
|
+
if respond_to?(Starburst.current_user_method) && send(Starburst.current_user_method) && announcement
|
6
|
+
if AnnouncementView.create(:user => send(Starburst.current_user_method), :announcement => announcement)
|
7
|
+
render :json => :ok
|
8
|
+
else
|
9
|
+
render json: nil, :status => :unprocessable_entity
|
10
|
+
end
|
11
|
+
else
|
12
|
+
render json: nil, :status => :unprocessable_entity
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Starburst
|
2
|
+
class Announcement < ActiveRecord::Base
|
3
|
+
serialize :limit_to_users
|
4
|
+
|
5
|
+
if Rails::VERSION::MAJOR < 4
|
6
|
+
attr_accessible(:title, :body, :start_delivering_at, :stop_delivering_at, :limit_to_users)
|
7
|
+
end
|
8
|
+
|
9
|
+
scope :ready_for_delivery, lambda {
|
10
|
+
where("(start_delivering_at < ? OR start_delivering_at IS NULL)
|
11
|
+
AND (stop_delivering_at > ? OR stop_delivering_at IS NULL)", Time.now, Time.now)
|
12
|
+
}
|
13
|
+
|
14
|
+
scope :unread_by, lambda {|current_user|
|
15
|
+
joins("LEFT JOIN starburst_announcement_views ON
|
16
|
+
starburst_announcement_views.announcement_id = starburst_announcements.id AND
|
17
|
+
starburst_announcement_views.user_id = #{Announcement.sanitize(current_user.id)}")
|
18
|
+
.where("starburst_announcement_views.announcement_id IS NULL AND starburst_announcement_views.user_id IS NULL")
|
19
|
+
}
|
20
|
+
|
21
|
+
scope :in_delivery_order, lambda { order("start_delivering_at ASC")}
|
22
|
+
|
23
|
+
def self.current(current_user = nil)
|
24
|
+
if current_user
|
25
|
+
find_announcement_for_current_user(ready_for_delivery.unread_by(current_user).in_delivery_order, current_user)
|
26
|
+
else
|
27
|
+
ready_for_delivery.in_delivery_order.first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find_announcement_for_current_user(announcements, user)
|
32
|
+
user_as_array = user.serializable_hash(methods: Starburst.user_instance_methods)
|
33
|
+
announcements.each do |announcement|
|
34
|
+
if user_matches_conditions(user_as_array, announcement.limit_to_users)
|
35
|
+
return announcement
|
36
|
+
end
|
37
|
+
end
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.user_matches_conditions(user, conditions = nil)
|
42
|
+
if conditions
|
43
|
+
conditions.each do |condition|
|
44
|
+
if user[condition[:field]] != condition[:value]
|
45
|
+
return false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% if current_announcement %>
|
2
|
+
<div id="starburst-announcement">
|
3
|
+
<p><%= current_announcement.body.html_safe %></p>
|
4
|
+
<%= link_to "Close", starburst.mark_as_read_path(current_announcement.id), :method => :post, :remote => true, :id => "starburst-close" %>
|
5
|
+
</div>
|
6
|
+
<% end %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% if current_announcement %>
|
2
|
+
<%= form_tag starburst.mark_as_read_path(current_announcement.id), :remote => true do %>
|
3
|
+
<div class="alert alert-info" id="starburst-announcement" role="alert">
|
4
|
+
<button name="commit" type="submit" class="close" id="starburst-close"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
5
|
+
<p><%= current_announcement.body.html_safe %></p>
|
6
|
+
</div>
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% if current_announcement %>
|
2
|
+
<div data-alert class="alert-box">
|
3
|
+
<p><%= current_announcement.body.html_safe %></p>
|
4
|
+
<%= link_to "×".html_safe, starburst.mark_as_read_path(current_announcement.id), :method => :post, :remote => true, :class => "close" %>
|
5
|
+
</div>
|
6
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Starburst</title>
|
5
|
+
<%= stylesheet_link_tag "starburst/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "starburst/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateAnnouncementTables < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :starburst_announcement_views do |t|
|
4
|
+
t.integer :user_id
|
5
|
+
t.integer :announcement_id
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
create_table :starburst_announcements do |t|
|
9
|
+
t.text :title
|
10
|
+
t.text :body
|
11
|
+
t.datetime :start_delivering_at
|
12
|
+
t.datetime :stop_delivering_at
|
13
|
+
t.text :limit_to_users
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# http://viget.com/extend/easy-gem-configuration-variables-with-defaults
|
2
|
+
module Configuration
|
3
|
+
def configuration
|
4
|
+
yield self
|
5
|
+
end
|
6
|
+
def define_setting(name, default = nil)
|
7
|
+
class_variable_set("@@#{name}", default)
|
8
|
+
define_class_method "#{name}=" do |value|
|
9
|
+
class_variable_set("@@#{name}", value)
|
10
|
+
end
|
11
|
+
define_class_method name do
|
12
|
+
class_variable_get("@@#{name}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
private
|
16
|
+
def define_class_method(name, &block)
|
17
|
+
(class << self; self; end).instance_eval do
|
18
|
+
define_method name, &block
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/starburst.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Starburst
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Starburst
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :rspec, :fixture => false
|
7
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
8
|
+
g.assets false
|
9
|
+
g.helper false
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Starburst
|
4
|
+
|
5
|
+
describe AnnouncementsController do
|
6
|
+
|
7
|
+
routes { Starburst::Engine.routes } # http://pivotallabs.com/writing-rails-engine-rspec-controller-tests/
|
8
|
+
|
9
|
+
it "marks an announcement as read" do
|
10
|
+
@current_user = mock_model(User, :id => 10)
|
11
|
+
controller.stub(:current_user).and_return(@current_user)
|
12
|
+
announcement = FactoryGirl.create(:announcement)
|
13
|
+
post :mark_as_read, :id => announcement.id
|
14
|
+
expect(response.status).to eq 200
|
15
|
+
expect(AnnouncementView.last.user_id).to eq 10
|
16
|
+
expect(AnnouncementView.all.length).to eq 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not mark an announcement as read if no one is logged in" do
|
20
|
+
#@current_user = mock_model(User, :id => 10)
|
21
|
+
controller.stub(:current_user).and_return(nil)
|
22
|
+
announcement = FactoryGirl.create(:announcement)
|
23
|
+
post :mark_as_read, :id => announcement.id
|
24
|
+
expect(response.status).to eq 422
|
25
|
+
expect(AnnouncementView.all.length).to eq 0
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has a helper path for mark as read" do
|
29
|
+
expect(mark_as_read_path(1)).to eq "/starburst/announcements/1/mark_as_read"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|