rack-ermahgerd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-ermahgerd.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Daniel Westendorf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Rack::Ermahgerd
2
+
3
+ Translate the text of a Rack application's web response to ERMAHGERD-ish with this piece of Rack Middleware. It modifies the response, so newer versions of Rails will not work with it. I've tested it to be working with Sinatra and plain rack apps.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rack-ermahgerd'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rack-ermahgerd
18
+
19
+ ## Usage
20
+
21
+ Use it as middleware in your rack based application. In your Sinatra app or Rackup file add the following:
22
+
23
+ require 'rack-ermahgerd'
24
+ use Rack::Ermahgerd
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/*.rb']
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Ermahgerd
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,54 @@
1
+ require "rack-ermahgerd/version"
2
+ require 'nokogiri'
3
+
4
+ module Rack
5
+ class Ermahgerd
6
+ def initialize(app, options={})
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ status, headers, response = @app.call(env)
12
+
13
+ return [status, headers, response] if response.class != Array
14
+ response.each_with_index do |res, i|
15
+ response[i] = translate(res) if res.class == String
16
+ end
17
+ headers["Content-Length"] = Rack::Utils.bytesize(response.to_s).to_s
18
+ [status, headers, response]
19
+ end
20
+
21
+ def translate(html)
22
+ doc = Nokogiri::HTML(html)
23
+ doc.traverse do |x|
24
+ if x.text?
25
+ x.content = ermahgerd_it(x.content)
26
+ end
27
+ end
28
+ doc.serialize(encoding: 'UTF-8')
29
+ end
30
+
31
+ def ermahgerd_it(text)
32
+ text.upcase!
33
+ text.gsub!(/[AEIOUY]r(?! )/i, 'E')
34
+ text.gsub!(/AA/i, 'A')
35
+ text.gsub!(/EE/i, 'E')
36
+ text.gsub!(/II/i, 'I')
37
+ text.gsub!(/OO/i, 'O')
38
+ text.gsub!(/UU/i, 'U')
39
+ text.gsub!(/YY/i, 'Y')
40
+ text.gsub!(/[AEIOUY]{2,}/i, 'E')
41
+ text.gsub!(/[AEIOUY](?! )/i, 'ER')
42
+ text.gsub!(/[Y]/i, 'ER')
43
+ text.gsub!(/ERH/i, 'ER')
44
+ text.gsub!(/ERR/i, 'ER')
45
+ text.gsub!(/MER/i, 'MAH')
46
+ text.gsub!('ERWERSERMAH', 'ERSUM')
47
+ text.gsub!('ERWERSERME', 'ERSUM')
48
+ text.gsub!('GERSERBERMPS', 'GERSBERMS')
49
+ text.gsub!('MAHMAH', 'MERM')
50
+ text.gsub!('MAHME', 'MERM')
51
+ text
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack-ermahgerd/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rack-ermahgerd"
8
+ gem.version = Rack::Ermahgerd::VERSION
9
+ gem.authors = ["Daniel Westendorf"]
10
+ gem.email = ["daniel@prowestech.com"]
11
+ gem.description = "Rack::Ermahgerd is a simple Rack middleware that translates the content of a web page into Ermahgerd-ish"
12
+ gem.summary = "Translate your web content to ERMAHGERD-ish"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency 'nokogiri'
20
+
21
+ gem.add_development_dependency "bundler"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "test-unit"
24
+ gem.add_development_dependency "shoulda"
25
+ gem.add_development_dependency "rack"
26
+ gem.add_development_dependency "rack-test"
27
+ end
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require 'rack/mock'
4
+ require 'rack/test'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+
9
+ require 'rack-ermahgerd'
10
+
11
+ class TestRackErmahgerd < Test::Unit::TestCase
12
+ include Rack::Test::Methods
13
+
14
+ def app
15
+ app = Proc.new {|env| [200, {'Content-Type' => 'text/plain'}, ['<div>Goosebumps!</div>']]}
16
+ builder = Rack::Builder.new
17
+ builder.use Rack::Ermahgerd
18
+ builder.run app
19
+ builder.to_app
20
+ end
21
+
22
+ should 'should provide a response' do
23
+ get '/'
24
+ assert_equal 200, last_response.status
25
+ end
26
+
27
+ should "ERMAHGERD-IFY the response" do
28
+ get '/'
29
+ assert_match /GERSBERMS!/, last_response.body
30
+ end
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-ermahgerd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Westendorf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: test-unit
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: shoulda
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rack
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rack-test
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Rack::Ermahgerd is a simple Rack middleware that translates the content
127
+ of a web page into Ermahgerd-ish
128
+ email:
129
+ - daniel@prowestech.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - lib/rack-ermahgerd.rb
140
+ - lib/rack-ermahgerd/version.rb
141
+ - rack-ermahgerd.gemspec
142
+ - test/rack-ermahgerd_test.rb
143
+ homepage:
144
+ licenses: []
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 1.8.23
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Translate your web content to ERMAHGERD-ish
167
+ test_files:
168
+ - test/rack-ermahgerd_test.rb
169
+ has_rdoc: