Class: ActionviewPrecompiler::ParsedFilename
- Inherits:
-
Object
- Object
- ActionviewPrecompiler::ParsedFilename
- Defined in:
- lib/actionview_precompiler/parsed_filename.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(path) ⇒ ParsedFilename
constructor
A new instance of ParsedFilename.
- #parse_template_path(path) ⇒ Object
- #partial? ⇒ Boolean
- #path_regex ⇒ Object
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3 def action @action end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
3 4 5 |
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3 def details @details end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/actionview_precompiler/parsed_filename.rb', line 3 def path @path end |
#prefix ⇒ Object (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
15 16 17 |
# File 'lib/actionview_precompiler/parsed_filename.rb', line 15 def partial? @partial end |
#path_regex ⇒ Object
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 |