Skip to Content Skip to Search

class ActionView::TemplatePath

Action View TemplatePath

Represents a template path within ActionView’s lookup and rendering system, like “users/show”

TemplatePath makes it convenient to convert between separate name, prefix, partial arguments and the virtual path.

Attributes

[R] name
[R] partial
[R] partial?
[R] prefix
[R] to_s
[R] to_str
[R] virtual
[R] virtual_path

Public class methods

Convert name, prefix, and partial into a TemplatePath

Source code GitHub
# File actionview/lib/action_view/template_path.rb, line 43
def self.build(name, prefix, partial)
  new name, prefix, partial, virtual(name, prefix, partial)
end
Source code GitHub
# File actionview/lib/action_view/template_path.rb, line 47
def initialize(name, prefix, partial, virtual)
  @name    = name
  @prefix  = prefix
  @partial = partial
  @virtual = virtual
end

Build a TemplatePath form a virtual path

Source code GitHub
# File actionview/lib/action_view/template_path.rb, line 28
def self.parse(virtual)
  if nameidx = virtual.rindex("/")
    prefix = virtual[0, nameidx]
    name = virtual.from(nameidx + 1)
    prefix = prefix[1..] if prefix.start_with?("/")
  else
    prefix = ""
    name = virtual
  end
  partial = name.start_with?("_")
  name = name[1..] if partial
  new name, prefix, partial, virtual
end

Convert name, prefix, and partial into a virtual path string

Source code GitHub
# File actionview/lib/action_view/template_path.rb, line 17
def self.virtual(name, prefix, partial)
  if prefix.empty?
    "#{partial ? "_" : ""}#{name}"
  elsif partial
    "#{prefix}/_#{name}"
  else
    "#{prefix}/#{name}"
  end
end

Definition files