Class: ActionView::TemplatePath

Inherits:
Object
  • Object
show all
Defined in:
actionview/lib/action_view/template_path.rb

Overview

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.

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.



47
48
49
50
51
52
# 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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#partialObject (readonly) Also known as: partial?

Returns the value of attribute partial.



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

def partial
  @partial
end

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

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

Returns the value of attribute virtual.



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

def virtual
  @virtual
end

Class Method Details

.build(name, prefix, partial) ⇒ Object

Convert name, prefix, and partial into a TemplatePath



43
44
45
# 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) ⇒ Object

Build a TemplatePath form a virtual path



28
29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object

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



17
18
19
20
21
22
23
24
25
# 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 Method Details

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

:nodoc:

Returns:

  • (Boolean)


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

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

#hashObject

:nodoc:



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

def hash # :nodoc:
  @virtual.hash
end

#virtual_pathObject

Returns the value of attribute virtual.



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

def virtual
  @virtual
end