Class: ActionviewPrecompiler::ParsedFilename

Inherits:
Object
  • Object
show all
Defined in:
lib/actionview_precompiler/parsed_filename.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ParsedFilename

Returns a new instance of ParsedFilename.



5
6
7
8
9
10
11
12
13
# File 'lib/actionview_precompiler/parsed_filename.rb', line 5

def initialize(path)
  @path = path

  details = parse_template_path(path)
  @prefix = details.delete(:prefix)
  @action = details.delete(:action)
  @partial = details.delete(:partial)
  @details = details
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3

def action
  @action
end

#detailsObject (readonly)

Returns the value of attribute details.



3
4
5
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3

def details
  @details
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3

def path
  @path
end

#prefixObject (readonly)

Returns the value of attribute prefix.



3
4
5
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3

def prefix
  @prefix
end

Instance Method Details

#parse_template_path(path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/actionview_precompiler/parsed_filename.rb', line 37

def parse_template_path(path)
  match = path_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

#partial?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/actionview_precompiler/parsed_filename.rb', line 15

def partial?
  @partial
end

#path_regexObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/actionview_precompiler/parsed_filename.rb', line 19

def path_regex
  handlers = ActionView::Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|")
  formats = ActionView::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