123456789_123456789_123456789_123456789_123456789_

Class: ActionView::FileSystemResolver

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
ActionView::FallbackFileSystemResolver, ActionView::OptimizedFileSystemResolver
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Resolver
Instance Chain:
self, Resolver
Inherits: ActionView::PathResolver
Defined in: actionview/lib/action_view/template/resolver.rb

Overview

A resolver that loads files from the filesystem. It allows setting your own resolving pattern. Such pattern can be a glob string supported by some variables.

Examples

Default pattern, loads views the same way as previous versions of rails, eg. when you're looking for users/new it will produce query glob: users/new{.{en},}{.{html,js},}{.{erb,haml},}

FileSystemResolver.new("/path/to/views", ":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}")

This one allows you to keep files with different formats in separate subdirectories, eg. users/new.html will be loaded from users/html/new.erb or users/new.html.erb, users/new.js from users/js/new.erb or users/new.js.erb, etc.

FileSystemResolver.new("/path/to/views", ":prefix/{:formats/,}:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}")

If you don't specify a pattern then the default will be used.

In order to use any of the customized resolvers above in a ::Rails application, you just need to configure ActionController::Base.view_paths in an initializer, for example:

ActionController::Base.view_paths = FileSystemResolver.new(
  Rails.root.join("app/views"),
  ":prefix{/:locale}/:action{.:formats,}{+:variants,}{.:handlers,}"
)

Pattern format and variables

Pattern has to be a valid glob string, and it allows you to use the following variables:

  • :prefix - usually the controller path

  • :action - name of the action

  • :locale - possible locale versions

  • :formats - possible request formats (for example html, json, xml…)

  • :variants - possible request variants (for example phone, tablet…)

  • :handlers - possible handlers (for example erb, haml, builder…)

Class Attribute Summary

Resolver - Inherited

Class Method Summary

Instance Attribute Summary

Resolver - Inherited

Instance Method Summary

Resolver - Inherited

#caching?, #clear_cache,
#find_all

Normalizes the arguments and passes it on to find_templates.

#find_all_anywhere

Constructor Details

.new(path, pattern = nil) ⇒ FileSystemResolver

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'actionview/lib/action_view/template/resolver.rb', line 325

def initialize(path, pattern=nil)
  raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
  super(pattern)
  @path = File.expand_path(path)
end

Instance Method Details

#==(resolver)

Alias for #eql?.

[ GitHub ]

  
# File 'actionview/lib/action_view/template/resolver.rb', line 339

alias :== :eql?

#eql?(resolver) ⇒ Boolean Also known as: #==

[ GitHub ]

  
# File 'actionview/lib/action_view/template/resolver.rb', line 336

def eql?(resolver)
  self.class.equal?(resolver.class) && to_path == resolver.to_path
end

#to_path

Alias for #to_s.

[ GitHub ]

  
# File 'actionview/lib/action_view/template/resolver.rb', line 334

alias :to_path :to_s

#to_s Also known as: #to_path

[ GitHub ]

  
# File 'actionview/lib/action_view/template/resolver.rb', line 331

def to_s
  @path.to_s
end