Class: Superglue::Resolver::JsxPathParser

Inherits:
ActionView::Resolver::PathParser
  • Object
show all
Defined in:
lib/superglue/resolver.rb

Constant Summary collapse

REACT_FORMATS =
[:tsx, :jsx]

Instance Method Summary collapse

Instance Method Details

#build_path_regexObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/superglue/resolver.rb', line 8

def build_path_regex
  formats = Regexp.union(REACT_FORMATS.map(&:to_s))

  %r{
    \A
    (?:(?<prefix>.*)/)?
    (?<action>.*?)
    (?:\.(?<format>#{formats}))??
    \z
  }x
end

#parse(path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/superglue/resolver.rb', line 20

def parse(path)
  @regex ||= build_path_regex
  match = @regex.match(path)
  path = ActionView::TemplatePath.build(match[:action], match[:prefix] || "", false)
  details = ActionView::TemplateDetails.new(
    nil,
    nil,
    match[:format]&.to_sym,
    nil
  )
  ParsedPath.new(path, details)
end