rack-gsub 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/LICENSE +21 -0
- data/README.rdoc +19 -0
- data/Rakefile +33 -0
- data/lib/rack-gsub.rb +18 -0
- data/test/rackapp/app.rb +105 -0
- data/test/rackapp/config.ru +6 -0
- metadata +71 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Wyatt M. Greene
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= Rack::Gsub
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
This is a Rack middleware wrapper for gsub. You can replace text on your
|
6
|
+
web page without worrying about accidentally modifying the HTML tags
|
7
|
+
themselves.
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
This will replace all occurrences of "five" with "three" and will remove all
|
12
|
+
occurrences of "the":
|
13
|
+
|
14
|
+
use Rack::Gsub, "five" => "three", "the" => ""
|
15
|
+
|
16
|
+
Note that you can use regular expressions, too, just like with Ruby's gsub.
|
17
|
+
This is the syntax for using within Rails' config/environment.rb:
|
18
|
+
|
19
|
+
config.middleware.use Rack::Gsub, "five" => "three", "the" => ""
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |s|
|
7
|
+
s.name = "rack-gsub"
|
8
|
+
s.version = "0.0.0"
|
9
|
+
s.add_dependency 'rack-plastic', '>= 0.0.3'
|
10
|
+
s.author = "Wyatt Greene"
|
11
|
+
s.email = "techiferous@gmail.com"
|
12
|
+
s.summary = "Rack middleware wrapper for gsub."
|
13
|
+
s.description = %Q{
|
14
|
+
This is a Rack middleware wrapper for gsub. You can replace text on your
|
15
|
+
web page without worrying about accidentally modifying the HTML tags
|
16
|
+
themselves.
|
17
|
+
}
|
18
|
+
s.require_path = "lib"
|
19
|
+
s.files = []
|
20
|
+
s.files << "README.rdoc"
|
21
|
+
s.files << "LICENSE"
|
22
|
+
s.files << "CHANGELOG"
|
23
|
+
s.files << "Rakefile"
|
24
|
+
s.files += Dir.glob("lib/**/*")
|
25
|
+
s.files += Dir.glob("test/**/*")
|
26
|
+
s.homepage = "http://github.com/techiferous/rack-gsub"
|
27
|
+
s.requirements << "none"
|
28
|
+
s.has_rdoc = false
|
29
|
+
end
|
30
|
+
Jeweler::GemcutterTasks.new
|
31
|
+
rescue LoadError
|
32
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
33
|
+
end
|
data/lib/rack-gsub.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rack-plastic'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class Gsub < Plastic
|
5
|
+
|
6
|
+
def change_nokogiri_doc(doc)
|
7
|
+
doc.at_css("body").traverse do |node|
|
8
|
+
if node.text?
|
9
|
+
options.each do |pattern, replacement|
|
10
|
+
update_text(node, node.content.gsub(pattern, replacement))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
doc
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/test/rackapp/app.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
class App
|
2
|
+
|
3
|
+
def call(env)
|
4
|
+
response = Rack::Response.new
|
5
|
+
request = Rack::Request.new(env)
|
6
|
+
response['Content-Type'] = 'text/html'
|
7
|
+
if request.path =~ /more/
|
8
|
+
response.write more
|
9
|
+
else
|
10
|
+
response.write front_page
|
11
|
+
end
|
12
|
+
response.finish
|
13
|
+
end
|
14
|
+
|
15
|
+
def front_page
|
16
|
+
%Q{
|
17
|
+
<!DOCTYPE html
|
18
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
19
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
20
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
21
|
+
<head>
|
22
|
+
<title>The Greatest Movie of All Time</title>
|
23
|
+
</head>
|
24
|
+
<body>
|
25
|
+
<div id="container">
|
26
|
+
<p>
|
27
|
+
What my associate is trying to say is that our new brake pads are really cool.
|
28
|
+
You're not even gonna believe it.
|
29
|
+
</p>
|
30
|
+
<p>
|
31
|
+
Like, um, let's say you're driving along
|
32
|
+
the road, with your family.<br />
|
33
|
+
And you're driving along...la de da...woo...<br />
|
34
|
+
And then all of a sudden
|
35
|
+
there's a truck tire
|
36
|
+
in the middle of the road
|
37
|
+
and you hit the brakes.<br />
|
38
|
+
Screeeee!
|
39
|
+
</p>
|
40
|
+
<p>
|
41
|
+
Woah, that was close.
|
42
|
+
</p>
|
43
|
+
<p>
|
44
|
+
Now let's see what happens when you're
|
45
|
+
driving with "the other guy's brake pads".
|
46
|
+
</p>
|
47
|
+
<p>
|
48
|
+
You're driving along,<br />
|
49
|
+
you're driving along,<br />
|
50
|
+
and all of a sudden your kids are
|
51
|
+
yelling from the back seat:<br />
|
52
|
+
"I gotta go to the bathroom, daddy!"<br />
|
53
|
+
"Not now, dammit!"<br />
|
54
|
+
"Truck tire! I can't stop! Aaaaa! Help!"<br />
|
55
|
+
"There's a cliff! Aaaaa!"<br />
|
56
|
+
And your family screaming:<br />
|
57
|
+
"Oh my God, we're burning alive!"<br />
|
58
|
+
"No! I can't feel my legs!"<br />
|
59
|
+
Here comes the meat-wagon! Woo woo woo!<br />
|
60
|
+
And the medic gets out and says:<br />
|
61
|
+
"Oh! My! God!"<br />
|
62
|
+
New guy's in the corner puking his guts out:<br />
|
63
|
+
Blllleeeeeeeaaaaaaaaaaah!<br />
|
64
|
+
Blllleeeeeeeaaaaaaaaaaah!<br />
|
65
|
+
</p>
|
66
|
+
<p>
|
67
|
+
All because you wanna save a coupla extra pennies.
|
68
|
+
</p>
|
69
|
+
<a href="/more">« inflict me with more »</a>
|
70
|
+
</div>
|
71
|
+
</body>
|
72
|
+
</html>
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def more
|
77
|
+
%Q{
|
78
|
+
<!DOCTYPE html
|
79
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
80
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
81
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
82
|
+
<head>
|
83
|
+
<title>More of the Greatest Movie of All Time</title>
|
84
|
+
</head>
|
85
|
+
<body>
|
86
|
+
<div id="container">
|
87
|
+
<p>
|
88
|
+
D+? Oh my God! I passed! I passed! Oh, man i got a D+! I'm gonna graduate!
|
89
|
+
I'm gonna graduate! D+!
|
90
|
+
</p>
|
91
|
+
<p>
|
92
|
+
Hey guys, do i look different now that i'm a college grad?
|
93
|
+
</p>
|
94
|
+
<p>
|
95
|
+
Apparently they give a lot fewer D+'s than D-'s.
|
96
|
+
It's not a grade they like to give out, i'll tell ya that right now.
|
97
|
+
</p>
|
98
|
+
<a href="/">« take me back »</a>
|
99
|
+
</div>
|
100
|
+
</body>
|
101
|
+
</html>
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-gsub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wyatt Greene
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-03 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack-plastic
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.3
|
24
|
+
version:
|
25
|
+
description: "\n This is a Rack middleware wrapper for gsub. You can replace text on your\n web page without worrying about accidentally modifying the HTML tags\n themselves.\n "
|
26
|
+
email: techiferous@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- CHANGELOG
|
36
|
+
- LICENSE
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile
|
39
|
+
- lib/rack-gsub.rb
|
40
|
+
- test/rackapp/app.rb
|
41
|
+
- test/rackapp/config.ru
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/techiferous/rack-gsub
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements:
|
64
|
+
- none
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Rack middleware wrapper for gsub.
|
70
|
+
test_files:
|
71
|
+
- test/rackapp/app.rb
|