Rack::Mason

Rack::Mason is © [email protected]. It is licensed under the terms of the MIT License. Substantial parts are based on github.com/techiferous/rack-mason © [email protected]

Description

If you are creating Rack middleware that changes the HTML response, use Rack::Mason to get a head start. Rack::Mason takes care of the boilerplate Rack glue so that you can focus on simply changing the HTML.

Usage

There are two ways you can change the HTML: as a Nokogiri document or as a string. Simply define one of the following methods:

def update_body(doc)
  ... insert code that changes the doc ...
end

Rack::Mason also provides some convenience methods for interacting with Rack and Nokogiri as well as some convenience methods for testing.

Examples

The examples/middlewares directory has examples of writing middleware using Rack::Mason.

Testing

Rack::Mason comes with some test helpers that make it easier for you to write tests for your Rack middleware. Refer to the documentation for MasonTestHelper for more details.

If you want to test Rack::Mason itself, this gem doesn’t come with automated tests, but it provides manual tests. Each of the example middlewares is inserted into a Sinatra, Rails, and Rack test app.

To run the Rails test app:

  • cd examples/railsapp

  • script/server

  • point your browser to localhost:3000

To run the Sinatra test app:

  • cd examples/sinatraapp

  • ruby app.rb

  • point your browser to localhost:4567

To run the Rack test app:

  • cd examples/rackapp

  • rackup config.ru

  • point your browser to localhost:9292