From c9cceed1b488a2519a827d406d0408dbbdebbc82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 12 Aug 2024 13:39:18 +0200 Subject: fix haml engine caching and escaping --- lib/zorglub/app.rb | 3 ++- lib/zorglub/engines/haml.rb | 7 ++++--- spec/data/view/node0/engines.haml | 2 +- spec/node_spec.rb | 4 ++-- spec/spec_helper.rb | 1 + 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/zorglub/app.rb b/lib/zorglub/app.rb index 86adf1e..91635ab 100644 --- a/lib/zorglub/app.rb +++ b/lib/zorglub/app.rb @@ -18,7 +18,8 @@ module Zorglub engines: {}, haml_options: { format: :html5, - encoding: 'utf-8' + encoding: 'utf-8', + escape_html: false }, sass_options: { syntax: :scss, diff --git a/lib/zorglub/engines/haml.rb b/lib/zorglub/engines/haml.rb index b602773..0031eec 100644 --- a/lib/zorglub/engines/haml.rb +++ b/lib/zorglub/engines/haml.rb @@ -5,12 +5,13 @@ module Zorglub module Engines module Haml def self.proc(path, obj) - haml = ::Haml::Template.new(path) if obj.app.opt(:engines_cache_enabled) key = path.sub obj.app.opt(:root), '' - obj.app.engines_cache[key] ||= haml + haml = obj.app.engines_cache[key] || ::Haml::Template.new(obj.app.opt(:haml_options)) { ::File.read(path) } + else + haml = ::Haml::Template.new(obj.app.opt(:haml_options)) { ::File.read(path) } end - html = haml.render(obj, obj.app.opt(:haml_options)) + html = haml.render(obj) [html, 'text/html'] end end diff --git a/spec/data/view/node0/engines.haml b/spec/data/view/node0/engines.haml index b9ea984..d35145e 100644 --- a/spec/data/view/node0/engines.haml +++ b/spec/data/view/node0/engines.haml @@ -1 +1 @@ -%h1="Hello world" +%h1="Hello #{@name}" diff --git a/spec/node_spec.rb b/spec/node_spec.rb index fe1edfb..785da42 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -266,10 +266,10 @@ describe Zorglub do it 'haml engine should work' do Node0.app.opt! :engines_cache_enabled, false r = Node0.my_call '/engines/haml' - expect(r.body[0]).to eq "

Hello world

\n" + expect(r.body[0]).to eq "

Hello world

\n" Node0.app.opt! :engines_cache_enabled, true r = Node0.my_call '/engines/haml' - expect(r.body[0]).to eq "

Hello world

\n" + expect(r.body[0]).to eq "

Hello world

\n" end it 'sass engine should work' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 257327e..079607b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -112,6 +112,7 @@ class Node0 < Zorglub::Node no_layout! case name when 'haml' + @name = 'world' engine! :haml when 'sass' engine! :sass -- cgit v1.1-2-g2b99