diff --git a/ticketee/config/application.rb b/ticketee/config/application.rb index 503f3d6..cfc3004 100644 --- a/ticketee/config/application.rb +++ b/ticketee/config/application.rb @@ -22,5 +22,8 @@ class Application < Rails::Application # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true + + #require "link_jumbler" + #config.middleware.use LinkJumbler, { "e" => "a" } end end diff --git a/ticketee/lib/link_jumbler.rb b/ticketee/lib/link_jumbler.rb new file mode 100644 index 0000000..e48fb9d --- /dev/null +++ b/ticketee/lib/link_jumbler.rb @@ -0,0 +1,24 @@ +require "nokogiri" + +class LinkJumbler + def initialize(app, letters) + @app = app + @letters = letters + end + + def call(env) + status, headers, response = @app.call(env) + if headers['Content-Type'].include?("text/html") + body = Nokogiri::HTML(response.body) + body.css("a").each do |a| + @letters.each do |find, replace| + a.content = a.content.gsub(find.to_s, replace.to_s) + end + end + else + body = response.body + end + + [status, headers, Rack::Response.new(body.to_s)] + end +end