public_service_announcement 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +115 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +30 -0
- data/app/controllers/psas_controller.rb +29 -0
- data/app/models/psa.rb +18 -0
- data/app/views/psas/_form.html.erb +9 -0
- data/app/views/psas/edit.html.erb +1 -0
- data/app/views/psas/index.html.erb +32 -0
- data/app/views/psas/new.html.erb +1 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20101224024926_create_psas.rb +18 -0
- data/lib/extensions/action_controller/base.rb +32 -0
- data/lib/public_service_announcement.rb +6 -0
- data/lib/public_service_announcement/engine.rb +9 -0
- data/lib/public_service_announcement/exceptions.rb +12 -0
- data/lib/tasks/public_service_announcement.rake +15 -0
- data/public_service_announcement.gemspec +16 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/welcome_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +19 -0
- data/test/dummy/app/views/welcome/index.html.erb +0 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/db/migrate/20101224024926_create_psas.rb +18 -0
- data/test/dummy/db/schema.rb +22 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +175 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/factories/psa_factory.rb +20 -0
- data/test/integration/navigation_test.rb +90 -0
- data/test/integration/psa_helper_test.rb +36 -0
- data/test/public_service_announcement_test.rb +7 -0
- data/test/support/integration_case.rb +9 -0
- data/test/test_helper.rb +25 -0
- data/test/unit/psa_test.rb +25 -0
- metadata +165 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rails", "3.0.3"
|
4
|
+
gem "inherited_resources"
|
5
|
+
gem "simple_form"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "capybara", ">= 0.4.0"
|
9
|
+
gem "sqlite3-ruby", :require => "sqlite3"
|
10
|
+
gem "factory_girl"
|
11
|
+
gem "launchy"
|
12
|
+
end
|
13
|
+
|
14
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
15
|
+
# gem 'ruby-debug'
|
16
|
+
# gem 'ruby-debug19'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.3)
|
6
|
+
actionpack (= 3.0.3)
|
7
|
+
mail (~> 2.2.9)
|
8
|
+
actionpack (3.0.3)
|
9
|
+
activemodel (= 3.0.3)
|
10
|
+
activesupport (= 3.0.3)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.13)
|
16
|
+
rack-test (~> 0.5.6)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.3)
|
19
|
+
activesupport (= 3.0.3)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4)
|
22
|
+
activerecord (3.0.3)
|
23
|
+
activemodel (= 3.0.3)
|
24
|
+
activesupport (= 3.0.3)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.3)
|
28
|
+
activemodel (= 3.0.3)
|
29
|
+
activesupport (= 3.0.3)
|
30
|
+
activesupport (3.0.3)
|
31
|
+
arel (2.0.6)
|
32
|
+
builder (2.1.2)
|
33
|
+
capybara (0.4.0)
|
34
|
+
celerity (>= 0.7.9)
|
35
|
+
culerity (>= 0.2.4)
|
36
|
+
mime-types (>= 1.16)
|
37
|
+
nokogiri (>= 1.3.3)
|
38
|
+
rack (>= 1.0.0)
|
39
|
+
rack-test (>= 0.5.4)
|
40
|
+
selenium-webdriver (>= 0.0.27)
|
41
|
+
xpath (~> 0.1.2)
|
42
|
+
celerity (0.8.6)
|
43
|
+
childprocess (0.1.6)
|
44
|
+
ffi (~> 0.6.3)
|
45
|
+
configuration (1.2.0)
|
46
|
+
culerity (0.2.13)
|
47
|
+
erubis (2.6.6)
|
48
|
+
abstract (>= 1.0.0)
|
49
|
+
factory_girl (1.3.2)
|
50
|
+
ffi (0.6.3)
|
51
|
+
rake (>= 0.8.7)
|
52
|
+
has_scope (0.5.0)
|
53
|
+
i18n (0.5.0)
|
54
|
+
inherited_resources (1.1.2)
|
55
|
+
has_scope (~> 0.5.0)
|
56
|
+
responders (~> 0.6.0)
|
57
|
+
json_pure (1.4.6)
|
58
|
+
launchy (0.3.7)
|
59
|
+
configuration (>= 0.0.5)
|
60
|
+
rake (>= 0.8.1)
|
61
|
+
mail (2.2.13)
|
62
|
+
activesupport (>= 2.3.6)
|
63
|
+
i18n (>= 0.4.0)
|
64
|
+
mime-types (~> 1.16)
|
65
|
+
treetop (~> 1.4.8)
|
66
|
+
mime-types (1.16)
|
67
|
+
nokogiri (1.4.4)
|
68
|
+
polyglot (0.3.1)
|
69
|
+
rack (1.2.1)
|
70
|
+
rack-mount (0.6.13)
|
71
|
+
rack (>= 1.0.0)
|
72
|
+
rack-test (0.5.6)
|
73
|
+
rack (>= 1.0)
|
74
|
+
rails (3.0.3)
|
75
|
+
actionmailer (= 3.0.3)
|
76
|
+
actionpack (= 3.0.3)
|
77
|
+
activerecord (= 3.0.3)
|
78
|
+
activeresource (= 3.0.3)
|
79
|
+
activesupport (= 3.0.3)
|
80
|
+
bundler (~> 1.0)
|
81
|
+
railties (= 3.0.3)
|
82
|
+
railties (3.0.3)
|
83
|
+
actionpack (= 3.0.3)
|
84
|
+
activesupport (= 3.0.3)
|
85
|
+
rake (>= 0.8.7)
|
86
|
+
thor (~> 0.14.4)
|
87
|
+
rake (0.8.7)
|
88
|
+
responders (0.6.2)
|
89
|
+
rubyzip (0.9.4)
|
90
|
+
selenium-webdriver (0.1.2)
|
91
|
+
childprocess (~> 0.1.5)
|
92
|
+
ffi (~> 0.6.3)
|
93
|
+
json_pure
|
94
|
+
rubyzip
|
95
|
+
simple_form (1.3.0)
|
96
|
+
rails (~> 3.0.0)
|
97
|
+
sqlite3-ruby (1.3.2)
|
98
|
+
thor (0.14.6)
|
99
|
+
treetop (1.4.9)
|
100
|
+
polyglot (>= 0.3.1)
|
101
|
+
tzinfo (0.3.23)
|
102
|
+
xpath (0.1.2)
|
103
|
+
nokogiri (~> 1.3)
|
104
|
+
|
105
|
+
PLATFORMS
|
106
|
+
ruby
|
107
|
+
|
108
|
+
DEPENDENCIES
|
109
|
+
capybara (>= 0.4.0)
|
110
|
+
factory_girl
|
111
|
+
inherited_resources
|
112
|
+
launchy
|
113
|
+
rails (= 3.0.3)
|
114
|
+
simple_form
|
115
|
+
sqlite3-ruby
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2010 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/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
|
14
|
+
|
15
|
+
Rake::TestTask.new(:test) do |t|
|
16
|
+
t.libs << 'lib'
|
17
|
+
t.libs << 'test'
|
18
|
+
t.pattern = 'test/**/*_test.rb'
|
19
|
+
t.verbose = false
|
20
|
+
end
|
21
|
+
|
22
|
+
task :default => :test
|
23
|
+
|
24
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
25
|
+
rdoc.rdoc_dir = 'rdoc'
|
26
|
+
rdoc.title = 'PublicServiceAnnouncement'
|
27
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
28
|
+
rdoc.rdoc_files.include('README.rdoc')
|
29
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class PsasController < InheritedResources::Base
|
2
|
+
include InheritedResources::DSL
|
3
|
+
actions :all, :except => :show
|
4
|
+
|
5
|
+
before_filter do
|
6
|
+
if respond_to? :can_manage_psas?
|
7
|
+
throw PublicSeriviceAnnouncement::AccessDenied.new unless can_manage_psas?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
create! do |success,failure|
|
12
|
+
success.html{ redirect_to psas_path }
|
13
|
+
end
|
14
|
+
|
15
|
+
update! do |success,failure|
|
16
|
+
success.html{ redirect_to psas_path }
|
17
|
+
end
|
18
|
+
|
19
|
+
def lapsed
|
20
|
+
@psas = Psa.lapsed
|
21
|
+
@status = 'lapsed'
|
22
|
+
render 'index'
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def collection
|
27
|
+
@psas ||= Psa.active
|
28
|
+
end
|
29
|
+
end
|
data/app/models/psa.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Psa < ActiveRecord::Base
|
2
|
+
scope :active, where('end_date is ? or end_date >= ?', nil, DateTime.now)
|
3
|
+
scope :lapsed, where('not end_date is ? and end_date < ?',nil, DateTime.now)
|
4
|
+
|
5
|
+
|
6
|
+
def route=(val)
|
7
|
+
unless val.nil? || val.empty? || val =~ /^\^/ || val =~ /\$$/
|
8
|
+
val = "^#{val}$"
|
9
|
+
end
|
10
|
+
val = nil if val.empty?
|
11
|
+
write_attribute :route, val
|
12
|
+
end
|
13
|
+
|
14
|
+
def user_agent=(val)
|
15
|
+
val = nil if val.empty?
|
16
|
+
write_attribute :user_agent, val
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%= simple_form_for(@psa) do |f| %>
|
2
|
+
<%= f.input :message %>
|
3
|
+
<%= f.input :start_date %>
|
4
|
+
<%= f.input :end_date, :default => DateTime.now + 10.years, :start_year => Date.today.year - 1 %>
|
5
|
+
<%= f.input :max_views %>
|
6
|
+
<%= f.input :route %>
|
7
|
+
<%= f.input :user_agent %>
|
8
|
+
<%= f.submit 'Save' %>
|
9
|
+
<%- end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'form' %>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<p>Showing <strong><%= @status || 'active' %></strong> announcements. Show <%= @status == "lapsed" ? link_to('active',psas_path) : link_to('lapsed', lapsed_psas_path) %> announcements.</p>
|
2
|
+
|
3
|
+
<%= link_to "New", new_psa_path %>
|
4
|
+
|
5
|
+
<table id="psas">
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th></th>
|
9
|
+
<th>Message</th>
|
10
|
+
<th>Max Views</th>
|
11
|
+
<th>Start Date</th>
|
12
|
+
<th>End Date</th>
|
13
|
+
<th>Route</th>
|
14
|
+
<th>User Agent</th>
|
15
|
+
</tr>
|
16
|
+
</thead>
|
17
|
+
<tbody>
|
18
|
+
<% @psas.each do |psa| %>
|
19
|
+
<tr class="<%= cycle('odd','even') %>">
|
20
|
+
<td><%= link_to "Delete", psa, :method => :delete %> | <%= link_to "Edit", edit_psa_path(psa) %></td>
|
21
|
+
<td><%= psa.message %></td>
|
22
|
+
<td><%= psa.max_views %></td>
|
23
|
+
<td><%= psa.start_date %></td>
|
24
|
+
<td><%= psa.end_date %></td>
|
25
|
+
<td><%= psa.route %></td>
|
26
|
+
<td><%= psa.user_agent %></td>
|
27
|
+
</tr>
|
28
|
+
<% end %>
|
29
|
+
</tbody>
|
30
|
+
</table>
|
31
|
+
|
32
|
+
<%= link_to "New", new_psa_path %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'form' %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreatePsas < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :psas do |t|
|
4
|
+
t.datetime :start_date
|
5
|
+
t.datetime :end_date
|
6
|
+
t.integer :max_views
|
7
|
+
t.string :route
|
8
|
+
t.string :user_agent
|
9
|
+
t.text :message
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :psas
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ActionController::Base
|
2
|
+
|
3
|
+
helper_method :public_service_announcements
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def public_service_announcements
|
8
|
+
return [] if request.url =~ /^#{psas_url}/
|
9
|
+
psas = Psa.active.all.select { |psa|
|
10
|
+
#filter based on max views
|
11
|
+
request.session["psa_#{psa.id}"].nil? ||
|
12
|
+
psa.max_views.nil? ||
|
13
|
+
request.session["psa_#{psa.id}"] < psa.max_views
|
14
|
+
}.select { |psa|
|
15
|
+
#filter based on route
|
16
|
+
psa.route.nil? ||
|
17
|
+
Regexp.new(psa.route).match(request.url)
|
18
|
+
}.select { |psa|
|
19
|
+
#filter based on user-agent
|
20
|
+
agent = request.headers["User-Agent"]
|
21
|
+
psa.user_agent.nil? ||
|
22
|
+
Regexp.new(psa.user_agent).match(agent)
|
23
|
+
}
|
24
|
+
|
25
|
+
psas.each do |psa|
|
26
|
+
request.session["psa_#{psa.id}"] ||= 0
|
27
|
+
request.session["psa_#{psa.id}"] += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
psas
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'FileUtils'
|
2
|
+
|
3
|
+
namespace 'psa' do
|
4
|
+
namespace :migrations do
|
5
|
+
desc 'copy all migrations'
|
6
|
+
task :copy do
|
7
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'db','migrate')
|
8
|
+
destination = File.join(Rails.root, 'db', 'migrate')
|
9
|
+
Dir.mkdir(destination) unless Dir.exists? destination
|
10
|
+
Dir.entries(source).reject{ |s| s =~ %r(^\.+$) }.each do |file|
|
11
|
+
FileUtils.cp File.join(source,file), destination
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Provide a simple gemspec so you can easily use your enginex
|
2
|
+
# project in your rails apps through git.
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.author = "Gabe Anzelini"
|
5
|
+
s.email = "me@gabeanzelini.com"
|
6
|
+
s.homepage = "http://github.com/gabeanzelini/public_service_announcement"
|
7
|
+
s.name = "public_service_announcement"
|
8
|
+
s.summary = "Insert PublicServiceAnnouncement summary."
|
9
|
+
s.description = "Insert PublicServiceAnnouncement description."
|
10
|
+
s.add_dependency "rails", "3.0.3"
|
11
|
+
s.add_dependency "inherited_resources"
|
12
|
+
s.add_dependency "simple_form"
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.version = "0.1.0"
|
16
|
+
end
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|