0.0
No release in over 3 years
Low commit activity in last 3 years
Provides an easy way to create Rack Middleware that injects things into the response body. Extracted from rack-insight.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.9
~> 0.10
~> 0.6
~> 10.0
~> 3.2
 Project Readme

Rack::Toolbar

Allows you to create simple Rack Middleware that will insert HTML (or whatever!) into responses at specific points.

This gem was extracted from Rack::Insight.

Project Rack::Toolbar
gem name rack-toolbar
license MIT
expert support Get help on Codementor
download rank Total Downloads
version Gem Version
dependencies Dependency Status
code quality Code Climate
inline documenation Inline docs
continuous integration Build Status
test coverage Coverage Status
homepage on Github.com
documentation on Rdoc.info
live chat Join the chat at https://gitter.im/pboling/rack-toolbar
Spread ♡ⓛⓞⓥⓔ♡ on Coderbits, on Coderwall

NOTE: As it goes with all middleware that modifies the response, not compatible with Rails' streaming responses because it modifies the response.

Installation

Add this line to your application's Gemfile:

gem 'rack-toolbar'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-toolbar

Usage

If your app is delivering a response like:

<html>
  <head></head>
  <body>
    <h1>Important</h1>
  </body>
</html>

Simple Setup

You want to inject something into the response!

Configure your app to use Rack::Toolbar

use Rack::Toolbar, {snippet: "<div>More Important!</div>", insertion_point: "<body>", insertion_method: :after}

The div specified will be injected :after the <body tag.

<html>
  <head></head>
  <body>
    <div>More Important!</div>
    <h1>Important</h1>
  </body>
</html>

Easy Setup

You want to build a Middleware that will deliver a custom response based on whatever.

Create your middleware to inherit from Rack::Toolbar, and define a render method:

class CustomMiddleware < Rack::Toolbar
  def render
    "<script>javascript:void(0)</script>"
  end
end

Configure your app to use your CustomMiddleware. You can still use the :insertion_* options, but :snippet will be ignored.

use CustomMiddleware, {insertion_point: "</head>", insertion_method: :before}

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/destination_errors/fork )
  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. Make sure to add tests!
  6. Create a new Pull Request

Contributors

See the Network View

Alternatives

Other projects which will allow you to build Middleware to inject stuff into responses: