Project

rack-gsub

0.0
No commit activity in last 3 years
No release in over 3 years
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.1.1
 Project Readme

Rack::Gsub¶ ↑

Description¶ ↑

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" => ""

This is the syntax for using within Rails’ config/environment.rb:

config.middleware.use Rack::Gsub, "five" => "three", "the" => ""

Details¶ ↑

You can use regular expressions, too, just like with Ruby’s gsub:

use Rack::Gsub, /five/ => "5"
use Rack::Gsub, /f\w+e/ => "5"

By default, the arguments are case-sensitive. Use the /i regex switch to do a case-insensitive replace:

use Rack::Gsub, /five/i => "5"

Only text within the body of the document is replaced. The following will only replace the word “five” in the body, not in the page’s title:

use Rack::Gsub, "five" => "5"

Rack::Gsub does not replace the text inside form elements.

Rack::Gsub eventually passes the arguments to Ruby’s String.gsub method, so it behaves the same way.

use Rack::Gsub, /five/ => "5"
# gets turned into
string.gsub(/five/, "5")