No commit activity in last 3 years
No release in over 3 years
Rack middleware for serving alternate content on a given day
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 5.4
~> 0

Runtime

~> 1.4
>= 0.3.29
 Project Readme

Rack::ADayWithout

Build Status Gem Version

Rack::ADayWithout is a middleware for Rack-based web applications, originally built to display alternate content for the Day Without Art. All requests on a given day will be served blank or alternate content.

Installation

Add this line to your application's Gemfile:

gem 'rack-a_day_without', require: 'rack/a_day_without'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-a_day_without

Usage

Use Rack::ADayWithout as a middleware in your Rack (or Rails) application. The first parameter defines the subject of ADayWithout. The on option must be set to the date the middleware should inject the alternate content. on should be either a string that can be parsed by Date.parse or an instance of Date.

use Rack::ADayWithout, 'Art', on: '1/12/2014'

You can also use the alternate syntax which uses child classes to set the subject of ADayWithout. This is equivalent to the above example:

use Rack::ADayWithout::Art, on: '1/12/2014'

The child class is generated dynamically, and doesn't need to be defined beforehand. Thus the following are all valid:

use Rack::ADayWithout::War, on: '1/1/2100'
use Rack::ADayWithout::Pizza, on: '1/2/3456'
use Rack::ADayWithout::Foo, on: '15/7/2020'

Setting Timezone

By default ADayWithout will use GMT dates. You can set the timezone option for the middleware to use a different timezone that tzinfo knows about.

use Rack::ADayWithout::Art, on: '1/12/2014', timezone: 'America/New_York'

Writing Content

By default, the middleware will write an empty content string for all requests on the specified day. If the content or file options are set, the content string or file contents will be written instead.

use Rack::ADayWithout::Art, on: '1/12/2014', content: 'A Day Without Art'
# or...
use Rack::ADayWithout::Art, on: '1/12/2014', file: './public/index.html'

Bypass Routes

The bypass option allows some routes to pass through the middleware without being blocked. This can be useful if you have an admin area that should still be available during the day without. bypass can be set to be a String, a Regexp or an Array of either.

use Rack::ADayWithout::Art, on: '1/12/2014',
  bypass: [/^\/admin/, '/about']

With Rails

Load the rack middleware inside of config/application.rb:

module YourApp
  class Application < Rails::Application
    # ...

    config.middleware.use Rack::ADayWithout::Art, on: '22/11/2014'
  end
end

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