Rack::Gsub

Added by techiferous at November 15, 2009 06:58 Star_small_grayStar_small_grayStar_small_grayStar_small_grayStar_small_gray
GitHub stats:
Magnifier watcher(s)
Arrow_branch fork(s)
Wrench

About

This is a Rack middleware wrapper for gsub. You can replace text on your web page without worrying about accidentally modifying the HTML tags themselves.

Usage

This will replace all occurrences of "five" with "three" and will remove all occurrences of "the":

use Rack::Gsub, "five" => "three", "the" => ""

Note that you can use regular expressions, too, just like with Ruby's gsub. This is the syntax for using within Rails' config/environment.rb:

config.middleware.use Rack::Gsub, "five" => "three", "the" => ""
blog comments powered by Disqus