• Stars
    star
    353
  • Rank 120,322 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Show dev mark on development env

rack-dev-mark

Gem Version Download Dependency Status Build Status Coverage Status Code Climate

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

The running sample is available.

You can also try this gem on Heroku.

Deploy

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

Middleman

Add the settings in config.rb.

require 'rack/dev-mark'
Rack::DevMark.env = "Your Env"
use Rack::DevMark::Middleware

For Rails App

In config/environments/development.rb

Rails.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

Rails on Heroku

Since Heroku uses production env for staging. You can't use the settings above. However, the gem provide an easier way to set it up on Heroku. Just set the environment variable on the environment in which you want to show the mark.

heroku config:set RACK_DEV_MARK_ENV=staging

That's it!

Custom Rack Middleware Order

rack-dev-mark should be inserted before ActionDispatch::ShowExceptions becase we want to show the dev mark on the error pages as well. However, it does not work well if it's inserted by incorrect order with some other rack middlewares. So, it provides the setting of inserted place.

module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.insert_before SomeOtherMiddleware
  end
end

config.rack_dev_mark.insert_after is also available to insert rack-dev-mark after a middleware.

Here is the compatibility list which many people often ask.

Custom env string

Set the custom env string maually.

module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.env = 'foo'
  end
end

Temporarily disable the dev mark

skip_rack_dev_mark controller helper works like around_filter.

class FooController < ApplicationController
  skip_rack_dev_mark only: [:iframe]

  def index
    # Do something
  end

  def iframe
    # Do something
  end
end

In this case, only index action will insert the dev mark.

I18n Support

Get i18n string with rack_dev_mark locale strings.

e.g. In config/locale/rack_dev_mark.ja.yml

ja:
  rack_dev_mark:
    development: '้–‹็™บไธญ'
    staging: 'ใ‚นใƒ†ใƒผใ‚ธใƒณใ‚ฐ'

Then, you will get translated string on the pages!

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, env, params = {})
    # Do something for your theme
    html
  end
end

class AnotherTheme < Rack::DevMark::Theme::Base
  def insert_into(html, env, params = {})
    # 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

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

More Repositories

1

mandriller

Mandrill SMTP API integration for ActionMailer
Ruby
125
star
2

acts_as_hashids

Use Youtube-Like ID in ActiveRecord seamlessly.
Ruby
85
star
3

rack-secure-upload

Upload files securely
Ruby
75
star
4

activerecord-time-scope

Time-Related Scope for ActiveRecord
Ruby
35
star
5

hubot-alias

Action alias for hubot
CoffeeScript
21
star
6

akka-pusher

Pusher meets Akka
Scala
19
star
7

hubot-tabelog

Pick up a restaurant to go
CoffeeScript
19
star
8

paperclip-deflater

Deflate Processor for Paperclip
Ruby
17
star
9

issue-checker-for-github

Chrome Extension to check github issues assigned to you
CoffeeScript
14
star
10

hubot-privilege

Hubot is so smart! He can ignore you and your friends.
CoffeeScript
9
star
11

cron-hpa

"Cron"HorizontalPodAutoscaler
Go
8
star
12

activerecord-after-transaction

Execute Procs After Transaction
Ruby
8
star
13

ucrspawner

JupyterHub spawner for Marathon Universal Containerizer Runtime (UCR)
Python
7
star
14

e2e-tester

Open source End-to-End test service
Ruby
7
star
15

wordpress-client

Wordpress API Wrapper
Ruby
7
star
16

git-kustomize-diff

Diff tool for Kustomize
Go
7
star
17

fluent-plugin-fork

Fork output by separating values for fluentd
Ruby
4
star
18

cluster-lending-manager

Lending Manager of Kubernetes Cluster
Go
4
star
19

node-custom-console

Custom Console for Node.js
CoffeeScript
4
star
20

url_regexp

Generate regular expression for URL
Ruby
4
star
21

node-env-switcher

Switch env per request
JavaScript
2
star
22

chainer-watchdog

Watchdog extension for Chainer
Python
2
star
23

jupyter-env-whitelist

Hide Confidential Environment Variables from Notebooks in JupyterHub.
Python
2
star
24

k8s-virtual-device-plugin

Virtual Device Plugin for Kubernetes
Go
2
star
25

browserstack-screenshot-task

A sample task of browserstack screenshot API
Ruby
2
star
26

jquery-sticky

Make any element sticky in the container
JavaScript
2
star
27

bugsnag-ruby-ext

Extension of Bugsnag Ruby Client
Ruby
2
star
28

jquery-inserter

Chrome Extension to insert any version of jQuery to any page
JavaScript
1
star
29

faraday_middleware-retry_proxy

Retry with proxy in Faraday
Ruby
1
star
30

paperclip_rotation

Rotation Processor For Paperclip
Ruby
1
star
31

terraform-codepipeline-run-task

Terraform module to run a task in codepipeline
Python
1
star
32

capistrano-misc

Useful tools for Capistrano 2
Ruby
1
star
33

akka-pusher-play-app

Play application for akka pusher
Scala
1
star