Sha256: e0a8c94713fef6e53d421003d6b593033d3d8d0e9f809bf44cb9d200f23b0ab8

Contents?: true

Size: 1.65 KB

Versions: 37

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

module ActionView
  # 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 TemplatePath
    attr_reader :name, :prefix, :partial, :virtual
    alias_method :partial?, :partial
    alias_method :virtual_path, :virtual

    # Convert name, prefix, and partial into a virtual path string
    def self.virtual(name, prefix, partial)
      if prefix.empty?
        "#{partial ? "_" : ""}#{name}"
      elsif partial
        "#{prefix}/_#{name}"
      else
        "#{prefix}/#{name}"
      end
    end

    # Build a TemplatePath form a virtual path
    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

    # Convert name, prefix, and partial into a TemplatePath
    def self.build(name, prefix, partial)
      new name, prefix, partial, virtual(name, prefix, partial)
    end

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

    alias :to_str :virtual
    alias :to_s :virtual

    def hash # :nodoc:
      @virtual.hash
    end

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

Version data entries

37 entries across 35 versions & 4 rubygems

Version Path
actionview-7.0.8.6 lib/action_view/template_path.rb
actionview-7.0.8.5 lib/action_view/template_path.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actionview-7.0.8.4/lib/action_view/template_path.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actionview-7.0.5.1/lib/action_view/template_path.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actionview-7.0.5.1/lib/action_view/template_path.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actionview-7.0.5.1/lib/action_view/template_path.rb
actionview-7.0.8.4 lib/action_view/template_path.rb
actionview-7.0.8.1 lib/action_view/template_path.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actionview-7.0.3.1/lib/action_view/template_path.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actionview-7.0.2.3/lib/action_view/template_path.rb
actionview-7.0.8 lib/action_view/template_path.rb
actionview-7.0.7.2 lib/action_view/template_path.rb
actionview-7.0.7.1 lib/action_view/template_path.rb
actionview-7.0.7 lib/action_view/template_path.rb
actionview-7.0.6 lib/action_view/template_path.rb
actionview-7.0.5.1 lib/action_view/template_path.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actionview-7.0.2.3/lib/action_view/template_path.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actionview-7.0.3.1/lib/action_view/template_path.rb
actionview-7.0.5 lib/action_view/template_path.rb
actionview-7.0.4.3 lib/action_view/template_path.rb