Class: ActionView::TemplatePath
- Inherits:
-
Object
- Object
- ActionView::TemplatePath
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#partial ⇒ Object
(also: #partial?)
readonly
Returns the value of attribute partial.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#virtual ⇒ Object
(also: #to_str, #to_s)
readonly
Returns the value of attribute virtual.
Class Method Summary collapse
-
.build(name, prefix, partial) ⇒ Object
Convert name, prefix, and partial into a TemplatePath.
-
.parse(virtual) ⇒ Object
Build a TemplatePath form a virtual path.
-
.virtual(name, prefix, partial) ⇒ Object
Convert name, prefix, and partial into a virtual path string.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(name, prefix, partial, virtual) ⇒ TemplatePath
constructor
A new instance of TemplatePath.
-
#virtual_path ⇒ Object
Returns the value of attribute virtual.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/action_view/template_path.rb', line 10 def name @name end |
#partial ⇒ Object (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 |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/action_view/template_path.rb', line 10 def prefix @prefix end |
#virtual ⇒ Object (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:
59 60 61 |
# File 'lib/action_view/template_path.rb', line 59 def eql?(other) # :nodoc: @virtual == other.virtual end |
#hash ⇒ Object
:nodoc:
55 56 57 |
# File 'lib/action_view/template_path.rb', line 55 def hash # :nodoc: @virtual.hash end |
#virtual_path ⇒ Object
Returns the value of attribute virtual.
12 13 14 |
# File 'lib/action_view/template_path.rb', line 12 def virtual @virtual end |