Class: ActionView::TemplatePath

Inherits:
Object
  • Object
show all
Defined in:
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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, prefix, partial, virtual) ⇒ TemplatePath

Returns a new instance of TemplatePath.



45
46
47
48
49
50
# File 'lib/action_view/template_path.rb', line 45

def initialize(name, prefix, partial, virtual)
  @name    = name
  @prefix  = prefix
  @partial = partial
  @virtual = virtual
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#partialObject (readonly) Also known as: partial?

Returns the value of attribute partial.



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

def partial
  @partial
end

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

#virtualObject (readonly) Also known as: to_str, to_s

Returns the value of attribute virtual.



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

def virtual
  @virtual
end

Class Method Details

.build(name, prefix, partial) ⇒ Object

Convert name, prefix, and partial into a TemplatePath



41
42
43
# File 'lib/action_view/template_path.rb', line 41

def self.build(name, prefix, partial)
  new name, prefix, partial, virtual(name, prefix, partial)
end

.parse(virtual) ⇒ Object

Build a TemplatePath form a virtual path



26
27
28
29
30
31
32
33
34
35
36
37
38
# File '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) ⇒ Object

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



15
16
17
18
19
20
21
22
23
# File '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

Instance Method Details

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

:nodoc:

Returns:

  • (Boolean)


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

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

#hashObject

:nodoc:



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

def hash # :nodoc:
  @virtual.hash
end

#virtual_pathObject

Returns the value of attribute virtual.



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

def virtual
  @virtual
end