Class: Nanoc3::Filters::RelativizePaths
- Nanoc3::Plugin
- Nanoc3::Filter
- Nanoc3::Filters::RelativizePaths
Included Modules
Constants Inherited from Nanoc3::Plugin
Constructor Summary
This class inherits a constructor from Nanoc3::Filter.
Public Visibility
Public Class Methods Inherited from Nanoc3::Filter
Public Class Methods Inherited from Nanoc3::Plugin
Public Instance Method Summary
| #run(content, params = {}) |
|---|
Public Instance Methods Inherited from Nanoc3::Filter
Public Instance Methods Included from Nanoc3::Helpers::LinkTo
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 |