Class: Twig::FileExtensionEscapingStrategy
- Inherits:
-
Object
- Object
- Twig::FileExtensionEscapingStrategy
- Defined in:
- lib/twig/file_extension_escaping_strategy.rb
Class Method Summary collapse
-
.guess(name) ⇒ Symbol, false
Guesses the best autoescaping strategy based on the file name.
Class Method Details
.guess(name) ⇒ Symbol, false
Guesses the best autoescaping strategy based on the file name.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/twig/file_extension_escaping_strategy.rb', line 9 def self.guess(name) # Return html for directories if name.end_with?('/') || name.end_with?('\\') return :html end # Remove .twig extension if present if name.end_with?('.twig') name = name[0...-5] end # Get file extension extension = File.extname(name)[1..] case extension when 'js', 'json' :js when 'css' :css when 'txt' false else :html end end |