Class: Nanoc::Filters::RelativizePaths Private

Inherits:
Nanoc::Filter show all
Includes:
Helpers::LinkTo
Defined in:
lib/nanoc/filters/relativize_paths.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

SELECTORS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

['*/@href', '*/@src', 'object/@data', 'param[@name="movie"]/@content', 'comment()'].freeze

Constants inherited from Nanoc::Filter

Nanoc::Filter::TMP_BINARY_ITEMS_DIR

Instance Attribute Summary

Attributes inherited from Nanoc::Filter

#assigns

Instance Method Summary collapse

Methods included from Helpers::LinkTo

#link_to, #link_to_unless_current, #relative_path_to

Methods included from Helpers::HTMLEscape

#html_escape

Methods included from Helpers::Capturing

#capture, #content_for

Methods inherited from Nanoc::Filter

#depend_on, #filename, from_binary?, #initialize, #output_filename, requires, setup, #setup_and_run, to_binary?, type

Methods included from Int::PluginRegistry::PluginMethods

#all, #identifier, #identifiers, #named, #register

Methods inherited from Int::Context

#get_binding, #initialize

Constructor Details

This class inherits a constructor from Nanoc::Filter

Instance Method Details

#run(content, params = {}) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Relativizes all paths in the given content, which can be HTML, XHTML, XML or CSS. This filter is quite useful if a site needs to be hosted in a subdirectory instead of a subdomain. In HTML, all ‘href` and `src` attributes will be relativized. In CSS, all `url()` references will be relativized.

Parameters:

  • content (String)

    The content to filter

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :type (Symbol)

    The type of content to filter; can be ‘:html`, `:xhtml`, `:xml` or `:css`.

  • :select (Array)

    The XPath expressions that matches the nodes to modify. This param is useful only for the ‘:html`, `:xml` and `:xhtml` types.

  • :namespaces (Hash)

    The pairs ‘prefix => uri` to define any namespace you want to use in the XPath expressions. This param is useful only for the `:xml` and `:xhtml` types.

Returns:

  • (String)

    The filtered content



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nanoc/filters/relativize_paths.rb', line 29

def run(content, params = {})
  Nanoc::Extra::JRubyNokogiriWarner.check_and_warn

  # Set assigns so helper function can be used
  @item_rep = assigns[:item_rep] if @item_rep.nil?

  # Filter
  case params[:type]
  when :css
    relativize_css(content)
  when :html, :xml, :xhtml
    relativize_html_like(content, params)
  else
    raise 'The relativize_paths needs to know the type of content to ' \
      'process. Pass a :type to the filter call (:html for HTML, ' \
      ':xhtml for XHTML, :xml for XML, or :css for CSS).'
  end
end