Class RewriteLinks
In: lib/nukumi2/rewritelinks.rb
Parent: Object

Methods

new   relative_to  

Public Class methods

[Source]

    # File lib/nukumi2/rewritelinks.rb, line 25
25:   def initialize(html)
26:     @html = html
27:   end

Public Instance methods

[Source]

    # File lib/nukumi2/rewritelinks.rb, line 29
29:   def relative_to(root)
30:     @html.gsub(/(<(img|a)\b[^>]*(src|href)=)(["'])(.*?)\4/) {
31:       md = $~
32: 
33:       url = URI.parse CGI.unescapeHTML(md[5])
34: 
35:       if url.relative? && url.path !~ /^\//
36:         md[1] + md[4] + root + "/" + md[5] + md[4]
37:       else
38:         md.to_s
39:       end
40:     }
41:   end

[Validate]