Awesome
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 | |
download rank | |
version | |
dependencies | |
code quality | |
inline documenation | |
continuous integration | |
test coverage | |
homepage | on Github.com |
documentation | on Rdoc.info |
live chat | |
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
- Fork it ( https://github.com/[my-github-username]/destination_errors/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Make sure to add tests!
- 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: