Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAML partial rendering fails because of missing _erbout binding #1639

Open
freesteph opened this issue Dec 12, 2022 · 3 comments
Open

HAML partial rendering fails because of missing _erbout binding #1639

freesteph opened this issue Dec 12, 2022 · 3 comments

Comments

@freesteph
Copy link

freesteph commented Dec 12, 2022

Steps to reproduce

  1. Setup HAML for a simple nanoc project ;
  2. Try and render a HAML partial with a block ;
  3. Rendering fails

Expected behavior

The template compiles normally.

Actual behavior

NameError: undefined local variable or method `_erbout' for #<Nanoc::Core::Context:0x0000000107a373b8 @content="%h1 My simple page.\n\n= render(\"/partials/foobar.haml\") do\n  %h2 This should work normally\n", @item=<Nanoc::Core::CompilationItemView identifier=/page.haml>, @rep=<Nanoc::Core::CompilationItemRepView item.identifier=/page.haml name=default>, @item_rep=<Nanoc::Core::CompilationItemRepView item.identifier=/page.haml name=default>, @items=<Nanoc::Core::ItemCollectionWithRepsView>, @layouts=<Nanoc::Core::LayoutCollectionView>, @config=<Nanoc::Core::ConfigView>>

Details

I'm probably doing something wrong but I just cannot figure out what it is. I've made a repo with the full files but it looks roughly like this:

# content/page.haml
%h1 Example page

= render("/partials/foobar.haml") do
  %h2 This should work normally
# layout/partials/foobar.haml
.foobar
  %h2 This is a partial rendered from a page

  - if block_given?
    = yield

Crash log

https://gist.github.com/freesteph/13a20fe7a618f1229e2d6b7c6073a8d6

Thank you.

@denisdefreyne
Copy link
Member

This is likely the result of Haml 6.0 changing the API (see #1595).

I haven’t been able to figure out how to make the filtering helper work with Haml 6, and the same underlying reason is making it impossible to use #render with a block.

@freesteph
Copy link
Author

So I've been exploring nanoc + tilt + haml + temple over the holidays and my mind is absolutely numbed at this point. Not only that but after writing lots of terrible hacks and spending hours in debug statements it turns out the fix might be disappointingly simple and consists in replicating the options used to coerce the Slim filter.

From a5fb9efd821419f8b8e4f1248587182292af00e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Maniaci?= <stephane.maniaci@gmail.com>
Date: Wed, 28 Dec 2022 00:15:17 +0100
Subject: [PATCH] filters: get the Haml filter to play nicely

We rely on an output buffer of `_erbout`, and we want to handle
`capture` statements ourselves, which was already being done for the
Slim filter but not the Haml one.
---
 nanoc/lib/nanoc/filters/haml.rb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/nanoc/lib/nanoc/filters/haml.rb b/nanoc/lib/nanoc/filters/haml.rb
index 8d57d8df6..052b58efe 100644
--- a/nanoc/lib/nanoc/filters/haml.rb
+++ b/nanoc/lib/nanoc/filters/haml.rb
@@ -15,7 +15,11 @@ module Nanoc::Filters
     # @return [String] The filtered content
     def run(content, params = {})
       # Get options
-      options = params.merge(filename: filename)
+      options = params.merge(
+        filename: filename,
+        outvar: '_erbout',
+        disable_capture: true
+      )
 
       # Create context
       context = ::Nanoc::Core::Context.new(assigns)
-- 
2.38.1

Hopefully this provides a starting point for an actual fix, or better yet, might be the fix? Do let me know if I can be of any help when you get a chance to look at it.

@denisdefreyne
Copy link
Member

Ooh, thanks for looking into this! I’m short on time, but will try to give this a closer look. PRs are also always appreciated too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants