paul_revere 1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +1 -1
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +16 -2
  5. data/MIT-LICENSE +1 -1
  6. data/NEWS.md +8 -0
  7. data/README.md +47 -49
  8. data/Rakefile +12 -9
  9. data/app/assets/javascripts/announcements.js +22 -8
  10. data/app/helpers/announcements_helper.rb +10 -2
  11. data/app/models/announcement.rb +5 -1
  12. data/app/views/announcements/_private_announcement.html.erb +3 -0
  13. data/app/views/announcements/_public_announcement.html.erb +8 -0
  14. data/gemfiles/rails_4.0.0.gemfile +1 -1
  15. data/gemfiles/rails_4.1.0.gemfile +1 -1
  16. data/gemfiles/rails_4.2.0.gemfile +1 -1
  17. data/lib/generators/paul_revere/paul_revere_generator.rb +6 -10
  18. data/lib/generators/paul_revere/templates/migration.rb +2 -6
  19. data/lib/paul_revere.rb +1 -1
  20. data/lib/paul_revere/version.rb +1 -1
  21. data/paul_revere.gemspec +17 -15
  22. data/spec/factories.rb +5 -0
  23. data/spec/fake_app.rb +5 -1
  24. data/spec/helpers/announcements_helper_spec.rb +75 -23
  25. data/spec/javascripts/announcements_spec.js +10 -0
  26. data/spec/javascripts/helpers/.gitkeep +0 -0
  27. data/spec/javascripts/support/jasmine.yml +10 -0
  28. data/spec/javascripts/support/jquery-2.1.3.min.js +4 -0
  29. data/spec/lib/generators/paul_revere/paul_revere_generator_spec.rb +14 -2
  30. data/spec/models/announcement_spec.rb +11 -16
  31. data/spec/paul_revere_spec.rb +1 -1
  32. data/spec/rails_helper.rb +4 -0
  33. data/spec/views/announcements/_email_announcement.erb_spec.rb +1 -1
  34. data/spec/views/announcements/_private_announcement.html.erb_spec.rb +21 -0
  35. data/spec/views/announcements/_public_announcement.html.erb_spec.rb +20 -0
  36. metadata +55 -12
  37. data/app/views/announcements/_announcement.html.erb +0 -1
  38. data/app/views/announcements/_announcement_for_all.html.erb +0 -8
  39. data/lib/generators/paul_revere/USAGE +0 -9
  40. data/shoulda_macros/announcement.rb +0 -18
  41. data/spec/views/announcements/_announcement.html.erb_spec.rb +0 -29
  42. 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: 355afacefa6cf9309f77b784430797fa11dcf8d3
4
- data.tar.gz: 0b6bf869f4f2004f70dea0e5a708ae2f5878848f
3
+ metadata.gz: 4b100f2354a49122ecd4082d4b84b4599571ee5e
4
+ data.tar.gz: 5325d817b43a06b3f72e6991ef259148a53aebd5
5
5
  SHA512:
6
- metadata.gz: 6801cbf8cecdb895ff0364d6bd82eb9a97a4c3dec237f4c6eaf8a102768c67e7f3dac968933a42c3480bceba8d757ab2aafc895f40349cff0647dff065852119
7
- data.tar.gz: 71100c4a13c779ad10c0a6bffdf022a12ed6d7be502483f26857077cd7b6de1ea289f4b03d3c5ac168f1af9fe09292d17c17d4921449e394236608f506a09ef7
6
+ metadata.gz: c12367eb2d4cf6e17ed90bb6a4f4cbb771d71210171aed06ac4fe0463a0b583caefce76213402bafcd47745fcff9e697eced1daaa4148af90610f342dd1d991f
7
+ data.tar.gz: 42d2f556c6e6dd471789bc01c6db199ebf1e9e1bb2192dde54401c5f14a2a9f92d228f778fee99256f2eaafc932efc220a195d1e45ba66256f63c64d4b997542
data/Appraisals CHANGED
@@ -1,4 +1,4 @@
1
- ['4.2.0', '4.1.0', '4.0.0'].each do |rails_version|
1
+ ["4.2.0", "4.1.0", "4.0.0"].each do |rails_version|
2
2
  appraise "rails_#{rails_version}" do
3
3
  gem "rails", "~> #{rails_version}"
4
4
  end
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paul_revere (1.4)
4
+ paul_revere (2.0.0)
5
5
  rails (~> 4.0)
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
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)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2014 thoughtbot, inc
1
+ Copyright (c) 2009 thoughtbot, inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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
- Simple announcement plugin to include "one off" style announcements in Rails web apps.
5
+ This gem enables the inclusion of "one off" announcements in Rails applications.
7
6
 
8
- [![Paul Revere's
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
- Install with the asset pipeline (Rails 3.1+, asset pipeline enabled)
12
- --------------------------------------------------------------------
9
+ First, include the gem as normal in your Gemfile:
13
10
 
14
- Install as normal in your Gemfile:
11
+ gem "paul_revere"
15
12
 
16
- gem 'paul_revere'
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
- Add the announcement JS to `app/assets/javascripts/application.js`:
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
- Run the migration:
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
- Run the generator to create the migration and copy the JavaScript file into public:
24
+ Finally, create the announcements table by running the migration:
38
25
 
39
- rails generate paul_revere
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
- Run the migration:
28
+ ## Background
46
29
 
47
- rake db:migrate && rake db:migrate:redo
30
+ Paul Revere provides...
48
31
 
49
- Usage
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
- Paul Revere provides...
46
+ ## Usage
53
47
 
54
- * A model called `Announcement`, which has nothing more than timestamps and a "body" column (text column). We view the most recent `Announcement` as the "current" announcement, and will select that to show on the site.
55
- * A helper called `#current_announcement`, which will return that latest `Announcement` record.
56
- * A view partial called `_announcement_for_all`, which is intended to be shown to all site users.
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
- So the flow would be...
52
+ For example, to include the latest announcement for all site users:
61
53
 
62
- * Install the gem
63
- * Use those partials in the correct places in your view code and mailer view code where you want announcements to show up:
54
+ ```
55
+ <%= render "announcements/public_announcement" %>
56
+ ```
64
57
 
65
- <%= render 'announcements/announcement_for_all' %>
58
+ To make an announcement, use the Rails console to create a new record:
66
59
 
67
- * When you want to make an announcement, use the Rails console to create a new `Announcement` record:
60
+ ```
61
+ Announcement.create!(body: "Free ice cream on Monday!")
62
+ ```
68
63
 
69
- Announcement.create!(body: 'This Web site is shutting down because you refuse to pay')
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-2014 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
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 'bundler/setup'
2
- require 'bundler/gem_tasks'
3
- require 'appraisal'
1
+ require "bundler/setup"
2
+ require "bundler/gem_tasks"
3
+ require "appraisal"
4
4
 
5
- require 'rspec/core/rake_task'
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['BUNDLE_GEMFILE'] =~ /gemfiles/
10
- exec 'rake spec'
12
+ if ENV["BUNDLE_GEMFILE"] =~ /gemfiles/
13
+ exec "rake spec jasmine:ci"
11
14
  else
12
- Rake::Task['appraise'].execute
15
+ Rake::Task["appraise"].execute
13
16
  end
14
17
  end
15
18
 
16
- task :appraise => ['appraisal:install'] do |t|
17
- exec 'rake appraisal'
19
+ task :appraise => ["appraisal:install"] do |t|
20
+ exec "rake appraisal"
18
21
  end
@@ -1,15 +1,29 @@
1
- function hideAnnouncement(announcement_created_at) {
2
- createCookie(announcement_created_at, 'hidden', 365);
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
- else var expires = "";
14
- document.cookie = name+"="+value+expires+"; path=/";
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 announcement_hidden?(announcement)
3
- cookies["announcement_#{announcement.created_at}"] == "hidden"
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
@@ -1,9 +1,13 @@
1
1
  class Announcement < ActiveRecord::Base
2
2
  def self.current
3
- order('created_at desc').first || new
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,3 @@
1
+ <% if announcement_visibility_allowed? -%>
2
+ <%= render "announcements/public_announcement" %>
3
+ <% 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,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "http://rubygems.org"
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.0.0"
6
6
 
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "http://rubygems.org"
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.1.0"
6
6
 
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "http://rubygems.org"
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
6
 
@@ -1,32 +1,28 @@
1
- require 'rails/generators/active_record'
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 "Put the JavaScript and migration in place"
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 if needs_js_copied?
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, 'announcements.js'), js_destination
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 needs_js_copied?
25
- !::Rails.application.config.assets.enabled
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 self.up
2
+ def change
3
3
  create_table :announcements do |t|
4
4
  t.text :body
5
- t.timestamps :null => false
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
@@ -1,4 +1,4 @@
1
- require 'paul_revere/version'
1
+ require "paul_revere/version"
2
2
 
3
3
  module PaulRevere
4
4
  class Engine < Rails::Engine
@@ -1,3 +1,3 @@
1
1
  module PaulRevere
2
- VERSION = '1.4'.freeze
2
+ VERSION = "2.0.0".freeze
3
3
  end