123456789_123456789_123456789_123456789_123456789_

Class: ActionView::Resolver::PathParser

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: actionview/lib/action_view/template/resolver.rb

Instance Method Summary

Instance Method Details

#build_path_regex

[ GitHub ]

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

def build_path_regex
  handlers = Regexp.union(Template::Handlers.extensions.map(&:to_s))
  formats = Regexp.union(Template::Types.symbols.map(&:to_s))
  available_locales = I18n.available_locales.map(&:to_s)
  regular_locales = [/[a-z]{2}(?:[-_][A-Z]{2})?/]
  locales = Regexp.union(available_locales + regular_locales)
  variants = "[^.]*"

  %r{
    \A
    (?:(?<prefix>.*)/)?
    (?<partial>_)?
    (?<action>.*?)
    (?:\.(?<locale>#{locales}))??
    (?:\.(?<format>#{formats}))??
    (?:\+(?<variant>#{variants}))??
    (?:\.(?<handler>#{handlers}))?
    \z
  }x
end

#parse(path)

[ GitHub ]

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

def parse(path)
  @regex ||= build_path_regex
  match = @regex.match(path)
  path = TemplatePath.build(match[:action], match[:prefix] || "", !!match[:partial])
  details = TemplateDetails.new(
    match[:locale]&.to_sym,
    match[:handler]&.to_sym,
    match[:format]&.to_sym,
    match[:variant]&.to_sym
  )
  ParsedPath.new(path, details)
end