middleman / middleman-asciidoc

:beginner: AsciiDoc support for Middleman 4. (In Middleman 3, AsciiDoc support is provided by a core extension).
https://middlemanapp.com
Other
27 stars 12 forks source link

Problems rendering a custom toc / block_outline.html.slim #88

Closed marcobehler closed 6 years ago

marcobehler commented 6 years ago

Hi @mojavelinux , I've got a Middleman 4.2.1 project, with a \source\_asciidoc_templates\block_outline.html.slim file (Link), which I copied from the asciidoctor-backends project.

Furthermore I have a layout file, which calls the following method:

<div class="sidebar">
  <% if (doc = current_page.data.document) %>
    <%= doc.converter.convert doc, 'outline', toclevels: 3 %>
   <% end %>
</div>

Now i know that the block_outline.html.slim file is getting applied correctly (i.e. I also made the necessary changes to config.rb), because I get the following error message when trying to render my pages:

undefined method `section_level' for # Did you mean? sections

Ruby | /mnt/c/dev/blah/source/_asciidoc_templates/block_outline.html.slim: in block in singleton class, line 3

What am I missing? Why does it not find the helper appropriate helper methods?

Thank you! Marco

mojavelinux commented 6 years ago

Did you copy the helpers.rb to \source_asciidoc_templates\ too?

marcobehler commented 6 years ago

Of course.....not :D

For anyone else interested in this: Copying the file over is however only half the story. You need to add the following to your Gemfile

gem 'opal', '~> 0.10.5'

Note You need to specify the version, as with newer versions of the opal gem it won't work.

Thanks @mojavelinux !

mojavelinux commented 6 years ago

You can avoid the problem with Opal being used by setting the template_engine option. Otherwise, tilt goes a little crazy and tries to use Opal to compile the helper file.

mojavelinux commented 6 years ago

Actually, it turns out the problem is putting the templates under the source folder. We don't want Middleman looking at those files, so it's best to move them outside the source directory. Then only Asciidoctor processes them, and it doesn't do stupid things like try to load Opal. I updated the README.

marcobehler commented 6 years ago

When I move the helpers.rb file out of the source folder, how do I tell Asciidoctor to pick it up, i.e. where to I configure it?

mojavelinux commented 6 years ago

See the README. Move the whole templates folder. It was wrong of me to suggest that it goes inside source since Middleman monitors that folder.

On Sun, May 6, 2018, 05:21 Marco Behler notifications@github.com wrote:

When I move the helpers.rb file out of the source folder, how do I tell Asciidoctor to pick it up, i.e. where to I configure it?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/middleman/middleman-asciidoc/issues/88#issuecomment-386872214, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE192dzUt8VIGEJ4G6DJFDfbXwoSDJvks5tvtzGgaJpZM4Tzpsg .

marcobehler commented 6 years ago

Thank you!