Class: Jpmobile::Resolver::PathParser
- Inherits:
-
ActionView::Resolver::PathParser
- Object
- ActionView::Resolver::PathParser
- Jpmobile::Resolver::PathParser
- Defined in:
- lib/jpmobile/resolver.rb
Instance Method Summary collapse
Instance Method Details
#build_path_regex ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jpmobile/resolver.rb', line 16 def build_path_regex handlers = Regexp.union(::ActionView::Template::Handlers.extensions.map(&:to_s)) formats = Regexp.union(::ActionView::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 = '[^.]*' mobile = Jpmobile::Mobile.all_variants.map {|x| Regexp.escape(x) }.join('|') %r{ \A (?:(?<prefix>.*)/)? (?<partial>_)? (?<action>.*?) (?:_(?<mobile>#{mobile}))?? (?:\.(?<locale>#{locales}))?? (?:\.(?<format>#{formats}))?? (?:\+(?<variant>#{variants}))?? (?:\.(?<handler>#{handlers}))? \z }x end |
#parse(path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jpmobile/resolver.rb', line 40 def parse(path) @regex ||= build_path_regex match = @regex.match(path) path = ActionView::TemplatePath.build(match[:action], match[:prefix] || '', !!match[:partial]) details = Jpmobile::TemplateDetails.new( match[:locale]&.to_sym, match[:handler]&.to_sym, match[:format]&.to_sym, match[:variant]&.to_sym, match[:mobile]&.to_sym, ) ParsedPath.new(path, details) end |