Module: Metz::HamlRubyExtractor
- Extended by:
- TemplateRubyExtractor
- Defined in:
- lib/metz/haml_ruby_extractor.rb
Overview
Ruby extractor for HAML view templates. Mirrors Metz::ErbRubyExtractor:
registered with RuboCop::Runner.ruby_extractors so view-aware Metz cops
(currently Metz/ViewsDeepNavigation) can run against HAML content.
Recognises three HAML constructs that carry Ruby:
* `= ruby_expr` - output script (escaped)
* `- ruby_stmt` - silent script
* `:ruby` filter - indented block of plain Ruby
Each tag's body is handed to RuboCop as its own ProcessedSource whose
offset points at the body's column in the original template. Tags whose
body is not valid Ruby on its own are silently skipped (we never want to
surface Lint/Syntax from a partial HAML fragment).
Constant Summary collapse
- EXPR_LINE =
/\A(?<lead>[ \t]*(?:[%.#][^\s=]*)?)=\s(?<body>.*)$/- STMT_LINE =
/\A(?<lead>[ \t]*)-(?!#)\s(?<body>.*)$/- FILTER_LINE =
/\A(?<indent>[ \t]*):ruby[ \t]*$/
Class Method Summary collapse
Methods included from TemplateRubyExtractor
build_processed_source, build_snippet, call, empty_snippet, install!
Class Method Details
.handles?(path) ⇒ Boolean
29 30 31 |
# File 'lib/metz/haml_ruby_extractor.rb', line 29 def handles?(path) File.extname(path.to_s) == ".haml" && ::Metz::FileClassifier.view?(path) end |