123456789_123456789_123456789_123456789_123456789_

Module: ActionView::LookupContext::ViewPaths

Relationships & Source Files
Defined in: actionview/lib/action_view/lookup_context.rb

Overview

::ActionView::Helpers related to template lookup using the lookup context information.

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#html_fallback_for_js (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 126

attr_reader :view_paths, :html_fallback_for_js

#view_paths (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 126

attr_reader :view_paths, :html_fallback_for_js

Instance Method Details

#any?(name, prefixes = [], partial = false) ⇒ Boolean Also known as: #any_templates?

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 148

def any?(name, prefixes = [], partial = false)
  name, prefixes = normalize_name(name, prefixes)
  details, details_key = detail_args_for_any
  @view_paths.exists?(name, prefixes, partial, details, details_key, [])
end

#any_templates?(name, prefixes = [], partial = false)

Alias for #any?.

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 153

alias :any_templates? :any?

#append_view_paths(paths)

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 155

def append_view_paths(paths)
  @view_paths = build_view_paths(@view_paths.to_a + paths)
end

#build_view_paths(paths) (private)

Whenever setting view paths, makes a copy so that we can manipulate them in instance objects as we wish.

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 166

def build_view_paths(paths)
  if ActionView::PathSet === paths
    paths
  else
    ActionView::PathSet.new(Array(paths))
  end
end

#detail_args_for(options) (private)

Compute details hash and key according to user options (e.g. passed from #render).

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 175

def detail_args_for(options) # :doc:
  return @details, details_key if options.empty? # most common path.
  user_details = @details.merge(options)

  if @cache
    details_key = DetailsKey.details_cache_key(user_details)
  else
    details_key = nil
  end

  [user_details, details_key]
end

#detail_args_for_any (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 188

def detail_args_for_any
  @detail_args_for_any ||= begin
    details = {}

    LookupContext.registered_details.each do |k|
      if k == :variants
        details[k] = :any
      else
        details[k] = Accessors::DEFAULT_PROCS[k].call
      end
    end

    if @cache
      [details, DetailsKey.details_cache_key(details)]
    else
      [details, nil]
    end
  end
end

#exists?(name, prefixes = [], partial = false, keys = [], **options) ⇒ Boolean Also known as: #template_exists?

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 141

def exists?(name, prefixes = [], partial = false, keys = [], **options)
  name, prefixes = normalize_name(name, prefixes)
  details, details_key = detail_args_for(options)
  @view_paths.exists?(name, prefixes, partial, details, details_key, keys)
end

#find(name, prefixes = [], partial = false, keys = [], options = {}) Also known as: #find_template

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 128

def find(name, prefixes = [], partial = false, keys = [], options = {})
  name, prefixes = normalize_name(name, prefixes)
  details, details_key = detail_args_for(options)
  @view_paths.find(name, prefixes, partial, details, details_key, keys)
end

#find_all(name, prefixes = [], partial = false, keys = [], options = {})

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 135

def find_all(name, prefixes = [], partial = false, keys = [], options = {})
  name, prefixes = normalize_name(name, prefixes)
  details, details_key = detail_args_for(options)
  @view_paths.find_all(name, prefixes, partial, details, details_key, keys)
end

#find_template(name, prefixes = [], partial = false, keys = [], options = {})

Alias for #find.

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 133

alias :find_template :find

#normalize_name(name, prefixes) (private)

Fix when prefix is specified as part of the template name

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 209

def normalize_name(name, prefixes)
  name = name.to_s
  idx = name.rindex("/")
  return name, prefixes.presence || [""] unless idx

  path_prefix = name[0, idx]
  path_prefix = path_prefix.from(1) if path_prefix.start_with?("/")
  name = name.from(idx + 1)

  if !prefixes || prefixes.empty?
    prefixes = [path_prefix]
  else
    prefixes = prefixes.map { |p| "#{p}/#{path_prefix}" }
  end

  return name, prefixes
end

#prepend_view_paths(paths)

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 159

def prepend_view_paths(paths)
  @view_paths = build_view_paths(paths + @view_paths.to_a)
end

#template_exists?(name, prefixes = [], partial = false, keys = [], **options)

Alias for #exists?.

[ GitHub ]

  
# File 'actionview/lib/action_view/lookup_context.rb', line 146

alias :template_exists? :exists?