rack-dev-mark

Gem Version Build Status Coverage Status Code Climate

Differentiate development environment from production. You can choose themes to differentiate the page.

Screenshot

screenshot development

On Development Env

screenshot development

On Production Env

screenshot production

Installation

Add the rack-dev-mark gem to your Gemfile.

gem "rack-dev-mark"

And run bundle install.

For Rack App

require 'rack/dev-mark'
use Rack::DevMark::Middleware
run MyApp

For Rails App

In config/environments/development.rb

MyApp::Application.configure do
  config.rack_dev_mark.enable = true
end

Or In config/application.rb

module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.enable = !Rails.env.production?
  end
end

Or Alternatively, use generator

bundle exec rails g rack:dev-mark:install

The middleware sets title and github_fork_ribbon themes as default.

Exclude Multiple Environments in Rails

Show the dev mark except env1, env2, env3.

In config/application.rb

module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.enable = !%w(env1 env2 env3).include?(Rails.env)
  end
end

Heroku

Since Heroku uses production env for staging. You can use this settings instead.

module MyApp
  class Application < Rails::Application
    Rack::DevMark.env = ENV['RACK_DEV_MARK']
    config.rack_dev_mark.enable = !Rails.env.production? || ENV['RACK_DEV_MARK']
  end
end

And set the environment variable.

heroku config:set RACK_DEV_MARK=staging

Custom Theme

Although the default themes are title and github_fork_ribbon, you can create your own themes inheriting Rack::DevMark::Theme::Base.

require 'rack/dev-mark/theme/base'

class NewTheme < Rack::DevMark::Theme::Base
  def insert_into(html)
    # Do something for your theme
    html
  end
end

class AnotherTheme < Rack::DevMark::Theme::Base
  def insert_into(html)
    # Do something for your theme
    html
  end
end

Then, insert them in your app.

For Rack App

use Rack::DevMark::Middleware, [NewTheme.new, AnotherTheme.new]

For Rails App

In config/application.rb

module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.theme = [NewTheme.new, AnotherTheme.new]
  end
end

You can add any combination of themes. See more about themes.

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

Copyright (c) 2014 Daisuke Taniwaki. See LICENSE for details.