Skip to Content Skip to Search

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.

Methods
B
N
P
V

Attributes

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

Class Public methods

build(name, prefix, partial)

Convert name, prefix, and partial into a TemplatePath

# File actionview/lib/action_view/template_path.rb, line 41
def self.build(name, prefix, partial)
  new name, prefix, partial, virtual(name, prefix, partial)
end

new(name, prefix, partial, virtual)

# File actionview/lib/action_view/template_path.rb, line 45
def initialize(name, prefix, partial, virtual)
  @name    = name
  @prefix  = prefix
  @partial = partial
  @virtual = virtual
end

parse(virtual)

Build a TemplatePath form a virtual path

# File actionview/lib/action_view/template_path.rb, line 26
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

virtual(name, prefix, partial)

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

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