Module: Revelio::TemplateType
- Included in:
- ErbTemplateExtension, HamlTagCompilerExtension, HamlTemplateExtension, RenderSubscriber, SlimParserExtension, SlimTemplateExtension
- Defined in:
- lib/revelio/template_type.rb
Instance Method Summary collapse
-
#resolve_template_info(template) ⇒ Object
Resolves a template object (or raw identifier string) into [relative_path, type, short_name].
- #template_type(filename) ⇒ Object
Instance Method Details
#resolve_template_info(template) ⇒ Object
Resolves a template object (or raw identifier string) into [relative_path, type, short_name].
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/revelio/template_type.rb', line 20 def resolve_template_info(template) identifier = if template.respond_to?(:identifier) template.identifier elsif template.is_a?(String) template else "unknown" end relative = identifier.dup root = Revelio.config.project_root if root && relative.start_with?(root.to_s) relative = relative.delete_prefix(root.to_s).delete_prefix("/") end type = template_type(relative) short = File.basename(relative) [relative, type, short] end |
#template_type(filename) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/revelio/template_type.rb', line 5 def template_type(filename) basename = File.basename(filename) if filename.match?(%r{(^|/)components/}) "component" elsif basename.start_with?("_") "partial" elsif filename.match?(%r{(^|/)layouts/}) "layout" else "view" end end |