Class: ActionView::Resolver::PathParser

Inherits:
Object
  • Object
show all
Defined in:
lib/action_view/template/resolver.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#build_path_regexObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/action_view/template/resolver.rb', line 39

def build_path_regex
  handlers = Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|")
  formats = Template::Types.symbols.map { |x| Regexp.escape(x) }.join("|")
  locales = "[a-z]{2}(?:-[A-Z]{2})?"
  variants = "[^.]*"

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

#parse(path) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/action_view/template/resolver.rb', line 58

def parse(path)
  @regex ||= build_path_regex
  match = @regex.match(path)
  {
    prefix: match[:prefix] || "",
    action: match[:action],
    partial: !!match[:partial],
    locale: match[:locale]&.to_sym,
    handler: match[:handler]&.to_sym,
    format: match[:format]&.to_sym,
    variant: match[:variant]
  }
end