Class: Nanoc3::Filters::RelativizePaths

Included Modules

Nanoc3::Helpers::LinkTo

Constants Inherited from Nanoc3::Plugin

MAP

Constructor Summary

This class inherits a constructor from Nanoc3::Filter.

Public Visibility

Public Class Methods Inherited from Nanoc3::Filter

identifier, identifiers, register

Public Class Methods Inherited from Nanoc3::Plugin

all, named

Public Instance Method Summary

#run(content, params = {})

Public Instance Methods Inherited from Nanoc3::Filter

filename

Public Instance Method Details

run

public run(content, params = {})
[View source]


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nanoc3/filters/relativize_paths.rb', line 9

def run(content, params={})
  # Set assigns so helper function can be used
  @item_rep = assigns[:item_rep] if @item_rep.nil?

  # Filter
  case params[:type]
  when :html
    content.gsub(/(src|href)=(['"]?)(\/.+?)\2([ >])/) do
      $1 + '=' + $2 + relative_path_to($3) + $2 + $4
    end
  when :css
    content.gsub(/url\((['"]?)(\/.+?)\1\)/) do
      'url(' + $1 + relative_path_to($2) + $1 + ')'
    end
  else
    raise RuntimeError.new(
      "The relativize_paths needs to know the type of content to " +
      "process. Pass :type => :html for HTML or :type => :css for CSS."
    )
  end
end
Generated on Sunday, August 09 2009 at 01:43:10 PM by YARD 0.2.3.2 (ruby-1.8.7).