timmyc (owner)

Revisions

gist: 233321 Download_button fork
public
Public Clone URL: git://gist.github.com/233321.git
Embed All Files: show embed
convert_relative_to_absolute.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Extensions #:nodoc:
  module CoreExtensions #:nodoc:
    module StringExtensions #:nodoc:
      
      def convert_relative_to_absolute(domain)
        regexes = [/href="(.*?)"/mis,/src="(.*?)"/mis]
        this = self
        regexes.each do |search|
          results = search.match(this)
          results.captures.each{|found| this = this.gsub(found,"#{domain}#{found}") } if results && results.captures
        end
        return this
      end
      
    end
  end
end