paul_revere 1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +16 -2
- data/MIT-LICENSE +1 -1
- data/NEWS.md +8 -0
- data/README.md +47 -49
- data/Rakefile +12 -9
- data/app/assets/javascripts/announcements.js +22 -8
- data/app/helpers/announcements_helper.rb +10 -2
- data/app/models/announcement.rb +5 -1
- data/app/views/announcements/_private_announcement.html.erb +3 -0
- data/app/views/announcements/_public_announcement.html.erb +8 -0
- data/gemfiles/rails_4.0.0.gemfile +1 -1
- data/gemfiles/rails_4.1.0.gemfile +1 -1
- data/gemfiles/rails_4.2.0.gemfile +1 -1
- data/lib/generators/paul_revere/paul_revere_generator.rb +6 -10
- data/lib/generators/paul_revere/templates/migration.rb +2 -6
- data/lib/paul_revere.rb +1 -1
- data/lib/paul_revere/version.rb +1 -1
- data/paul_revere.gemspec +17 -15
- data/spec/factories.rb +5 -0
- data/spec/fake_app.rb +5 -1
- data/spec/helpers/announcements_helper_spec.rb +75 -23
- data/spec/javascripts/announcements_spec.js +10 -0
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/support/jasmine.yml +10 -0
- data/spec/javascripts/support/jquery-2.1.3.min.js +4 -0
- data/spec/lib/generators/paul_revere/paul_revere_generator_spec.rb +14 -2
- data/spec/models/announcement_spec.rb +11 -16
- data/spec/paul_revere_spec.rb +1 -1
- data/spec/rails_helper.rb +4 -0
- data/spec/views/announcements/_email_announcement.erb_spec.rb +1 -1
- data/spec/views/announcements/_private_announcement.html.erb_spec.rb +21 -0
- data/spec/views/announcements/_public_announcement.html.erb_spec.rb +20 -0
- metadata +55 -12
- data/app/views/announcements/_announcement.html.erb +0 -1
- data/app/views/announcements/_announcement_for_all.html.erb +0 -8
- data/lib/generators/paul_revere/USAGE +0 -9
- data/shoulda_macros/announcement.rb +0 -18
- data/spec/views/announcements/_announcement.html.erb_spec.rb +0 -29
- data/spec/views/announcements/_announcement_for_all.html.erb_spec.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b100f2354a49122ecd4082d4b84b4599571ee5e
|
4
|
+
data.tar.gz: 5325d817b43a06b3f72e6991ef259148a53aebd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c12367eb2d4cf6e17ed90bb6a4f4cbb771d71210171aed06ac4fe0463a0b583caefce76213402bafcd47745fcff9e697eced1daaa4148af90610f342dd1d991f
|
7
|
+
data.tar.gz: 42d2f556c6e6dd471789bc01c6db199ebf1e9e1bb2192dde54401c5f14a2a9f92d228f778fee99256f2eaafc932efc220a195d1e45ba66256f63c64d4b997542
|
data/Appraisals
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
paul_revere (
|
4
|
+
paul_revere (2.0.0)
|
5
5
|
rails (~> 4.0)
|
6
6
|
|
7
7
|
GEM
|
8
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
actionmailer (4.2.0)
|
11
11
|
actionpack (= 4.2.0)
|
@@ -50,6 +50,11 @@ GEM
|
|
50
50
|
builder (3.2.2)
|
51
51
|
diff-lcs (1.2.5)
|
52
52
|
erubis (2.7.0)
|
53
|
+
factory_girl (4.5.0)
|
54
|
+
activesupport (>= 3.0.0)
|
55
|
+
factory_girl_rails (4.5.0)
|
56
|
+
factory_girl (~> 4.5.0)
|
57
|
+
railties (>= 3.0.0)
|
53
58
|
generator_spec (0.9.3)
|
54
59
|
activesupport (>= 3.0.0)
|
55
60
|
railties (>= 3.0.0)
|
@@ -57,6 +62,12 @@ GEM
|
|
57
62
|
activesupport (>= 4.1.0)
|
58
63
|
hike (1.2.3)
|
59
64
|
i18n (0.7.0)
|
65
|
+
jasmine (2.2.0)
|
66
|
+
jasmine-core (~> 2.2)
|
67
|
+
phantomjs
|
68
|
+
rack (>= 1.2.1)
|
69
|
+
rake
|
70
|
+
jasmine-core (2.2.0)
|
60
71
|
json (1.8.2)
|
61
72
|
loofah (2.0.1)
|
62
73
|
nokogiri (>= 1.5.9)
|
@@ -68,6 +79,7 @@ GEM
|
|
68
79
|
multi_json (1.10.1)
|
69
80
|
nokogiri (1.6.6.2)
|
70
81
|
mini_portile (~> 0.6.0)
|
82
|
+
phantomjs (1.9.8.0)
|
71
83
|
rack (1.6.0)
|
72
84
|
rack-test (0.6.3)
|
73
85
|
rack (>= 1.0)
|
@@ -133,7 +145,9 @@ PLATFORMS
|
|
133
145
|
|
134
146
|
DEPENDENCIES
|
135
147
|
appraisal (~> 1.0)
|
148
|
+
factory_girl_rails (~> 4.5)
|
136
149
|
generator_spec (~> 0.9)
|
150
|
+
jasmine (~> 2.2)
|
137
151
|
paul_revere!
|
138
152
|
rspec-rails (~> 3.1)
|
139
153
|
sqlite3 (~> 1.3)
|
data/MIT-LICENSE
CHANGED
data/NEWS.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
New in 2.0.0:
|
2
|
+
|
3
|
+
* Remove deprecated should macros
|
4
|
+
* Switch to using `change` in generated Rails migrations
|
5
|
+
* Clean up the README and installation instructions
|
6
|
+
* Install the javascripts into vendor/assets
|
7
|
+
* Rename helper methods and view partials
|
8
|
+
|
1
9
|
New in 1.4:
|
2
10
|
|
3
11
|
* Reference the MIT license from the gemspec
|
data/README.md
CHANGED
@@ -1,75 +1,73 @@
|
|
1
|
-
Paul Revere
|
2
|
-
===========
|
1
|
+
# Paul Revere
|
3
2
|
|
4
3
|
[![Build Status](https://travis-ci.org/thoughtbot/paul_revere.svg?branch=master)](https://travis-ci.org/thoughtbot/paul_revere)
|
5
4
|
|
6
|
-
|
5
|
+
This gem enables the inclusion of "one off" announcements in Rails applications.
|
7
6
|
|
8
|
-
|
9
|
-
Ride](http://f.cl.ly/items/2u260D0Y2j2T3O3o4017/Screen%20Shot%202013-01-23%20at%2010.46.06%20AM.png)](http://poetry.eserver.org/paul-revere.html)
|
7
|
+
## Installation
|
10
8
|
|
11
|
-
|
12
|
-
--------------------------------------------------------------------
|
9
|
+
First, include the gem as normal in your Gemfile:
|
13
10
|
|
14
|
-
|
11
|
+
gem "paul_revere"
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
Run the generator to create the migration:
|
13
|
+
Then, run the generator to create the migration and copy the javascript.
|
19
14
|
|
20
15
|
rails generate paul_revere
|
21
16
|
|
22
|
-
|
17
|
+
The announcements JS will be installed into vendor/assets/javascripts.
|
18
|
+
You can add the announcement JS to `app/assets/javascripts/application.js`:
|
23
19
|
|
24
20
|
//= require announcements
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
rake db:migrate && rake db:migrate:redo
|
29
|
-
|
30
|
-
Install without the asset pipeline (Rails 3.0 or asset pipeline disabled)
|
31
|
-
---------------------------------------------------------------------------
|
32
|
-
|
33
|
-
Install as normal in your Gemfile:
|
34
|
-
|
35
|
-
gem 'paul_revere'
|
22
|
+
This will include the javascript into the `application.js` for the entire site.
|
36
23
|
|
37
|
-
|
24
|
+
Finally, create the announcements table by running the migration:
|
38
25
|
|
39
|
-
|
40
|
-
|
41
|
-
Add the announcement JS to your layout, such as `app/views/layouts/application.html.erb`:
|
42
|
-
|
43
|
-
<%= javascript_include_tag 'announcements' %>
|
26
|
+
rake db:migrate
|
44
27
|
|
45
|
-
|
28
|
+
## Background
|
46
29
|
|
47
|
-
|
30
|
+
Paul Revere provides...
|
48
31
|
|
49
|
-
|
50
|
-
|
32
|
+
* A model called `Announcement`, which has timestamps and a "body" text column.
|
33
|
+
* A `current` class method on `Announcement` which returns the latest
|
34
|
+
`Announcement`, or a new unsaved instance.
|
35
|
+
* A view helper called `#current_announcement`, which will return that latest
|
36
|
+
`Announcement` record.
|
37
|
+
* A view partial called `_public_announcement`, which is intended to be shown to
|
38
|
+
all site users.
|
39
|
+
* A view partial called `_private_announcement`, which is intended to be shown
|
40
|
+
only to logged in users. Note that this merely wraps the rendering of the
|
41
|
+
public announcement with a call to a helper which checks that a user is signed
|
42
|
+
in. There is only one type of Announcement.
|
43
|
+
* A view partial called `_email_announcement`, which is intended to be used in
|
44
|
+
site emails which are sent out and need to include announcements.
|
51
45
|
|
52
|
-
|
46
|
+
## Usage
|
53
47
|
|
54
|
-
*
|
55
|
-
*
|
56
|
-
|
57
|
-
* A view partial called `_announcement`, which is intended to be shown only to logged in users.
|
58
|
-
* A view partial called `_email_announcement`, which is intended to be used in site emails which are sent out.
|
48
|
+
* Install the gem, run the migration, ensure the javascript can be accessed.
|
49
|
+
* Use those partials in the correct places in your view code and mailer view
|
50
|
+
code where you want announcements to show up.
|
59
51
|
|
60
|
-
|
52
|
+
For example, to include the latest announcement for all site users:
|
61
53
|
|
62
|
-
|
63
|
-
|
54
|
+
```
|
55
|
+
<%= render "announcements/public_announcement" %>
|
56
|
+
```
|
64
57
|
|
65
|
-
|
58
|
+
To make an announcement, use the Rails console to create a new record:
|
66
59
|
|
67
|
-
|
60
|
+
```
|
61
|
+
Announcement.create!(body: "Free ice cream on Monday!")
|
62
|
+
```
|
68
63
|
|
69
|
-
|
64
|
+
There is a helper method called `announcement_visibility_allowed?`, which is
|
65
|
+
what the `private_announcement` partial calls to determine whether to allow the
|
66
|
+
current session to view announcements. The built-in implementation just checks
|
67
|
+
that `current_user` is truth-y. Override that helper method if you want to do
|
68
|
+
something more interesting as a check here.
|
70
69
|
|
71
|
-
Credits
|
72
|
-
-------
|
70
|
+
## Credits
|
73
71
|
|
74
72
|
![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
|
75
73
|
|
@@ -79,7 +77,7 @@ Thank you to all [the contributors](https://github.com/thoughtbot/paul_revere/co
|
|
79
77
|
|
80
78
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
81
79
|
|
82
|
-
License
|
83
|
-
-------
|
80
|
+
## License
|
84
81
|
|
85
|
-
Paul Revere is Copyright © 2009
|
82
|
+
Paul Revere is Copyright © 2009 thoughtbot, inc. It is free software, and may be
|
83
|
+
redistributed under the terms specified in the MIT-LICENSE file.
|
data/Rakefile
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "bundler/setup"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "appraisal"
|
4
4
|
|
5
|
-
require
|
5
|
+
require "rspec/core/rake_task"
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
+
require "jasmine"
|
9
|
+
load "jasmine/tasks/jasmine.rake"
|
10
|
+
|
8
11
|
task :default do |t|
|
9
|
-
if ENV[
|
10
|
-
exec
|
12
|
+
if ENV["BUNDLE_GEMFILE"] =~ /gemfiles/
|
13
|
+
exec "rake spec jasmine:ci"
|
11
14
|
else
|
12
|
-
Rake::Task[
|
15
|
+
Rake::Task["appraise"].execute
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
task :appraise => [
|
17
|
-
exec
|
19
|
+
task :appraise => ["appraisal:install"] do |t|
|
20
|
+
exec "rake appraisal"
|
18
21
|
end
|
@@ -1,15 +1,29 @@
|
|
1
|
-
function hideAnnouncement(
|
2
|
-
createCookie(
|
1
|
+
function hideAnnouncement(announcement_key) {
|
2
|
+
createCookie(announcement_key, "hidden", 365);
|
3
3
|
$("#announcement").slideUp();
|
4
4
|
}
|
5
5
|
|
6
|
-
// http://www.quirksmode.org/js/cookies.html
|
7
|
-
function createCookie(name,value,days) {
|
6
|
+
// Utility scripts from http://www.quirksmode.org/js/cookies.html
|
7
|
+
function createCookie(name, value, days) {
|
8
8
|
if (days) {
|
9
9
|
var date = new Date();
|
10
|
-
date.setTime(date.getTime()+(days*24*60*60*1000));
|
11
|
-
var expires = "; expires="+date.toGMTString();
|
10
|
+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
11
|
+
var expires = "; expires=" + date.toGMTString();
|
12
|
+
} else var expires = "";
|
13
|
+
document.cookie = name + "=" + value + expires + "; path=/";
|
14
|
+
}
|
15
|
+
|
16
|
+
function readCookie(name) {
|
17
|
+
var nameEQ = name + "=";
|
18
|
+
var ca = document.cookie.split(';');
|
19
|
+
for (var i = 0; i < ca.length; i++) {
|
20
|
+
var c = ca[i];
|
21
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
22
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
12
23
|
}
|
13
|
-
|
14
|
-
|
24
|
+
return null;
|
25
|
+
}
|
26
|
+
|
27
|
+
function eraseCookie(name) {
|
28
|
+
createCookie(name, "", -1);
|
15
29
|
}
|
@@ -1,9 +1,17 @@
|
|
1
1
|
module AnnouncementsHelper
|
2
|
-
def
|
3
|
-
|
2
|
+
def announcement_visible?(announcement)
|
3
|
+
announcement.exists? && announcement_unread?(announcement)
|
4
|
+
end
|
5
|
+
|
6
|
+
def announcement_unread?(announcement)
|
7
|
+
cookies[announcement.to_cookie_key] != "hidden"
|
4
8
|
end
|
5
9
|
|
6
10
|
def current_announcement
|
7
11
|
@current_announcement ||= Announcement.current
|
8
12
|
end
|
13
|
+
|
14
|
+
def announcement_visibility_allowed?
|
15
|
+
!! current_user
|
16
|
+
end
|
9
17
|
end
|
data/app/models/announcement.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
class Announcement < ActiveRecord::Base
|
2
2
|
def self.current
|
3
|
-
order(
|
3
|
+
order("created_at desc").first || new
|
4
4
|
end
|
5
5
|
|
6
6
|
def exists?
|
7
7
|
!new_record?
|
8
8
|
end
|
9
|
+
|
10
|
+
def to_cookie_key
|
11
|
+
"#{self.class.name.downcase}_#{created_at.iso8601}"
|
12
|
+
end
|
9
13
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% if announcement_visible?(current_announcement) %>
|
2
|
+
<div id="announcement">
|
3
|
+
<span><%= current_announcement.body.html_safe %></span>
|
4
|
+
<span class="hide">
|
5
|
+
<%= link_to "hide", "#", onclick: "hideAnnouncement('#{current_announcement.to_cookie_key}')" %>
|
6
|
+
</span>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
@@ -1,32 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/active_record"
|
2
2
|
|
3
3
|
class PaulRevereGenerator < Rails::Generators::Base
|
4
4
|
include Rails::Generators::Migration
|
5
5
|
|
6
|
-
desc "
|
6
|
+
desc "Copy the PaulRevere JavaScript and announcements migration"
|
7
7
|
source_root File.join(File.dirname(__FILE__), "templates")
|
8
8
|
|
9
9
|
def install
|
10
|
-
copy_javascript
|
10
|
+
copy_javascript
|
11
11
|
migration_template "migration.rb", "db/migrate/create_announcements.rb"
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def copy_javascript
|
17
|
-
copy_file File.join(javascript_path,
|
17
|
+
copy_file File.join(javascript_path, "announcements.js"), javascript_destination
|
18
18
|
end
|
19
19
|
|
20
20
|
def javascript_path
|
21
21
|
File.join(%w(.. .. .. .. app assets javascripts))
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def js_destination
|
29
|
-
'public/javascripts/announcements.js'
|
24
|
+
def javascript_destination
|
25
|
+
"vendor/assets/javascripts/announcements.js"
|
30
26
|
end
|
31
27
|
|
32
28
|
def self.next_migration_number(dirname)
|
@@ -1,12 +1,8 @@
|
|
1
1
|
class CreateAnnouncements < ActiveRecord::Migration
|
2
|
-
def
|
2
|
+
def change
|
3
3
|
create_table :announcements do |t|
|
4
4
|
t.text :body
|
5
|
-
t.timestamps :
|
5
|
+
t.timestamps null: false
|
6
6
|
end
|
7
7
|
end
|
8
|
-
|
9
|
-
def self.down
|
10
|
-
drop_table :announcements
|
11
|
-
end
|
12
8
|
end
|
data/lib/paul_revere.rb
CHANGED
data/lib/paul_revere/version.rb
CHANGED