lib/hanami/view/template.rb in hanami-view-1.2.0 vs lib/hanami/view/template.rb in hanami-view-1.2.1

- old
+ new

@@ -5,13 +5,19 @@ # A logic-less template. # # @since 0.1.0 class Template def initialize(template, encoding = Encoding::UTF_8) - # NOTE disable_escape: true is for Slim compatibility - # See https://github.com/hanami/assets/issues/36 - @_template = Tilt.new(template, nil, default_encoding: encoding, disable_escape: true) + options = { default_encoding: encoding } + + if slim?(template) + # NOTE disable_escape: true is for Slim compatibility + # See https://github.com/hanami/assets/issues/36 + options[:disable_escape] = true + end + + @_template = Tilt.new(template, nil, options) end # Returns the format that the template handles. # # @return [Symbol] the format name @@ -37,9 +43,15 @@ # @since 0.1.0 # # @see Hanami::View::Scope def render(scope, &blk) @_template.render(scope, {}, &blk) + end + + private + + def slim?(template) + File.extname(template) == ".slim".freeze end end end end