Countdowner

Countdown announcer for site maintenance etc.

Build Status

Molly with Kylie

Synopsis

Scenario

Your site is undergoing infrastructure changes which require downtime. Wouldn't it be great to warn users of impending doom well in advance.

Solution

Simply create a message:

Countdowner::Message.create! message: "Site closing for maintenance {{target}}",
                             start_at: Time.parse("9pm").utc,
                             target: Time.parse("10pm").utc,
                             end_at: Time.parse("10:01pm").utc

From 9pm users will see something like:

Site closing for maintenance 1 hour from now

Features

  • human readable time remaining
  • updated via Javascript, so it's always up-to-date
  • when Javascript is disabled, users will see UTC time
  • timezone agnostic
  • unaffected by caching

Installation

Add this line to your application's Gemfile:

gem 'countdowner'

And then execute:

$ bundle

Rails 3.1 and above

# application.js
//= require jquery.timeago
//= require jquery.countdowner

# Install migrations and migrate
$ rake countdowner_engine:install:migrations db:migrate

Rails 3.0 and below

TODO: generators

For now, copy these files into your app (paths are relative to gem).

  • vendor/assets/javascripts/jquery.timeago.js
  • lib/assets/javascripts/jquery.countdowner.js
  • db/migrations/20121018090014_create_countdowners.rb

Then, include the Javascript files and migrate the database (for rails 2 you'll need to split change migration method into self.up and self.down).

All versions

Add this to your layout:

# application.html.erb (after opening body tag)
<%= countdowner %>

Style it, eg:

# countdowner.css
#countdowner { background:#900; color:white; font-size:1.25em; padding:1em 2em; text-align:center; }

Optional configuration

If you're not fussed about non-Javascript users, you can prevent the UTC time appearing before the DOM loads.

# application.html.erb
<%= countdowner(hidden_initially: true) %>

If you're site cops a lot of traffic, cache it!

# application.html.erb (note that `expires_in` only works with memcache)
<% cache('countdowner', expires_in: 5.minutes) do %>
  <%= countdowner %>
<% end %>

Requirements

  • rails (>= 2.3)
  • jQuery

Acknowledgments

This gem uses the excellent timeago jQuery plugin.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

MIT License

Copyright 2012 Zubin Henner

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.