123456789_123456789_123456789_123456789_123456789_

Class: ActionView::TemplatePath

Relationships & Source Files
Inherits: Object
Defined in: actionview/lib/action_view/template_path.rb

Overview

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.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name, prefix, partial, virtual) ⇒ TemplatePath

[ 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

Class Method Details

.build(name, prefix, partial)

Convert name, prefix, and partial into a TemplatePath

[ 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

.parse(virtual)

Build a TemplatePath form a virtual path

[ 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

.virtual(name, prefix, partial)

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

[ 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

Instance Attribute Details

#name (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 12

attr_reader :name, :prefix, :partial, :virtual

#partial? (readonly)

Alias for #partial.

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 13

alias_method :partial?, :partial

#prefix (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 12

attr_reader :name, :prefix, :partial, :virtual

#to_s (readonly)

Alias for #virtual.

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 55

alias :to_s :virtual

#to_str (readonly)

Alias for #virtual.

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 54

alias :to_str :virtual

#virtual (readonly) Also known as: #virtual_path, #to_str, #to_s

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 12

attr_reader :name, :prefix, :partial, :virtual

#virtual_path (readonly)

Alias for #virtual.

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 14

alias_method :virtual_path, :virtual

Instance Method Details

#==(other)

This method is for internal use only.

Alias for #eql?.

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 64

alias :== :eql? # :nodoc:

#eql?(other) ⇒ Boolean Also known as: #==

This method is for internal use only.
[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 61

def eql?(other) # :nodoc:
  @virtual == other.virtual
end

#hash

This method is for internal use only.
[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 57

def hash # :nodoc:
  @virtual.hash
end

#partial (readonly) Also known as: #partial?

[ GitHub ]

  
# File 'actionview/lib/action_view/template_path.rb', line 12

attr_reader :name, :prefix, :partial, :virtual