# Rack::Nokogiri [![Build Status](https://secure.travis-ci.org/unindented/rack-nokogiri.png)](http://travis-ci.org/unindented/rack-nokogiri) [![Dependency Status](https://gemnasium.com/unindented/rack-nokogiri.png)](https://gemnasium.com/unindented/rack-nokogiri) Rack Middleware that allows you to manipulate the nodes in your HTML response however you like. ## Installation Add this line to your application's `Gemfile`: ```ruby gem 'rack-nokogiri' ``` And then execute: ```sh $ bundle ``` Or install it yourself as: ```sh $ gem install rack-nokogiri ``` ## Usage ### Adding Rack::Nokogiri to a Rails application To wrap all `
` with class `target` with a `div`, we could do something like this: ```ruby require 'rack/nokogiri' class Application < Rails::Application config.middleware.use Rack::Nokogiri, css: 'p.target' do |nodes| nodes.wrap '
' end end ``` If we wanted to use XPath instead of CSS selectors, we could do this instead: ```ruby require 'rack/nokogiri' class Application < Rails::Application config.middleware.use Rack::Nokogiri, xpath: "//p[@class='target']" do |nodes| nodes.wrap '' end end ``` ### Adding Rack::Nokogiri to a Sinatra application For Sinatra we would do: ```ruby require 'sinatra' require 'rack/nokogiri' use Rack::Nokogiri, css: 'p.target' do |nodes| nodes.wrap '' end get('/') do 'Hello World!
' end ``` ### Adding Rack::Nokogiri to a Rackup application For a Rackup app we would do: ```ruby require 'rack' require 'rack/nokogiri' use Rack::Nokogiri, css: 'p.target' do |nodes| nodes.wrap '' end run lambda { |env| [200, {'Content-Type' => 'text/html'}, ['Hello World!
']] } ``` ## Meta * Code: `git clone git://github.com/unindented/rack-nokogiri.git` * Home: