Class: ActionView::TemplatePath
- Inherits:
-
Object
- Object
- ActionView::TemplatePath
- Defined in:
- 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
-
#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.
47 48 49 50 51 52 |
# File '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
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/action_view/template_path.rb', line 12 def name @name end |
#partial ⇒ Object (readonly) Also known as: partial?
Returns the value of attribute partial.
12 13 14 |
# File 'lib/action_view/template_path.rb', line 12 def partial @partial end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
12 13 14 |
# File 'lib/action_view/template_path.rb', line 12 def prefix @prefix end |
#virtual ⇒ Object (readonly) Also known as: to_str, to_s
Returns the value of attribute virtual.
12 13 14 |
# File '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 '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 '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 '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:
61 62 63 |
# File 'lib/action_view/template_path.rb', line 61 def eql?(other) # :nodoc: @virtual == other.virtual end |
#hash ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/action_view/template_path.rb', line 57 def hash # :nodoc: @virtual.hash end |
#virtual_path ⇒ Object
Returns the value of attribute virtual.
14 15 16 |
# File 'lib/action_view/template_path.rb', line 14 def virtual @virtual end |