Module: ActionView::LookupContext::ViewPaths

Included in:
ActionView::LookupContext
Defined in:
actionview/lib/action_view/lookup_context.rb

Overview

Helpers related to template lookup using the lookup context information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#html_fallback_for_jsObject (readonly)

Returns the value of attribute html_fallback_for_js



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

def html_fallback_for_js
  @html_fallback_for_js
end

#view_pathsObject (readonly)

Returns the value of attribute view_paths



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

def view_paths
  @view_paths
end

Instance Method Details

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

Returns:

  • (Boolean)


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

def any?(name, prefixes = [], partial = false)
  @view_paths.exists?(*args_for_any(name, prefixes, partial))
end

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

Returns:

  • (Boolean)


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

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

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



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

def find(name, prefixes = [], partial = false, keys = [], options = {})
  @view_paths.find(*args_for_lookup(name, prefixes, partial, keys, options))
end

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



136
137
138
# File 'actionview/lib/action_view/lookup_context.rb', line 136

def find_all(name, prefixes = [], partial = false, keys = [], options = {})
  @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options))
end

#with_fallbacksObject

Adds fallbacks to the view paths. Useful in cases when you are rendering a :file.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'actionview/lib/action_view/lookup_context.rb', line 152

def with_fallbacks
  view_paths = build_view_paths((@view_paths.paths + self.class.fallbacks).uniq)

  if block_given?
    ActiveSupport::Deprecation.warn <<~eowarn.squish
    Calling `with_fallbacks` with a block is deprecated.  Call methods on
    the lookup context returned by `with_fallbacks` instead.
    eowarn

    begin
      _view_paths = @view_paths
      @view_paths = view_paths
      yield
    ensure
      @view_paths = _view_paths
    end
  else
    ActionView::LookupContext.new(view_paths, @details, @prefixes)
  end
end