Sha256: acb0f78b5c2aae22135bb0923ef9d109cde12e927c844ff2398c2860fda30072

Contents?: true

Size: 565 Bytes

Versions: 1

Compression:

Stored size: 565 Bytes

Contents

module Nanoc::Filters
  class RelativizePaths < Nanoc::Filter

    identifier :relativize_paths

    require 'nanoc/helpers/link_to'
    include Nanoc::Helpers::LinkTo

    def run(content, params={})
      type = params[:type] || :html

      case 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
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanoc-2.2 lib/nanoc/filters/relativize_paths.rb