Class: Temple::Filters::Encoding
- Defined in:
- lib/temple/filters/encoding.rb
Overview
Try to encode input string
Constant Summary
Constants included from Utils
Utils::ESCAPE_HTML, Utils::ESCAPE_HTML_PATTERN
Instance Attribute Summary
Attributes included from Mixins::Options
Instance Method Summary collapse
Methods included from Mixins::Options
Methods included from Utils
#empty_exp?, #escape_html, #escape_html_safe, #indent_dynamic, #unique_name
Instance Method Details
#call(s) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/temple/filters/encoding.rb', line 10 def call(s) if [:encoding] && s.respond_to?(:encoding) old_enc = s.encoding s = s.dup if s.frozen? s.force_encoding([:encoding]) # Fall back to old encoding if new encoding is invalid unless s.valid_encoding? s.force_encoding(old_enc) s.force_encoding(::Encoding::BINARY) unless s.valid_encoding? end end s end |