slim-template / slim

Slim is a template language whose goal is to reduce the syntax to the essential parts without becoming cryptic.
https://slim-template.github.io
MIT License
5.31k stars 501 forks source link

Slim 5 no longer working with Middleman: "NameError: uninitialized constant #<Class:0x0000000106bf2320>::ActionView" #909

Closed henrik closed 1 year ago

henrik commented 1 year ago

I tried using Slim 5 with Middleman and got an error when I visited a page (not when Middleman boots, but when it attempts to render a template).

Slim 4 works fine.

$ bundle exec middleman
== The Middleman is loading
== View your site at "http://192.168.0.113:4567"
== Inspect your site configuration at "http://192.168.0.113:4567/__middleman"
# (At this point I visit a page)
NameError: uninitialized constant #<Class:0x0000000106bf2320>::ActionView
        /Users/henrik/Projects/henrik.nyh.se/source/uses.html.slim:1:in `__tilt_7340'
        /Users/henrik/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/tilt-2.0.11/lib/tilt/template.rb:181:in `call'
        /Users/henrik/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/tilt-2.0.11/lib/tilt/template.rb:181:in `evaluate'
        /Users/henrik/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/tilt-2.0.11/lib/tilt/template.rb:109:in `render'
        /Users/henrik/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.3/lib/middleman-core/renderers/slim.rb:6:in `render'
        /Users/henrik/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/padrino-helpers-0.15.2/lib/padrino/rendering.rb:17:in `render'
        /Users/henrik/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.3/lib/middleman-core/file_renderer.rb:79:in `render'
…
henrik commented 1 year ago

Explicitly adding the actionview gem and requiring it fixes the issue: https://github.com/henrik/henrik.nyh.se/commit/b27f08d5c8db01fa6b8e914221a752580953faed

So the next step I suppose is to either automatically do this at some appropriate place in Slim (or Middleman or something) or documenting the requirement.

bostonaholic commented 1 year ago

I'm experiencing the same problem.

UweKubosch commented 1 year ago

Slim and Temple do not require ActionView and have fallbacks to other implementations if ActionView is not present.

The dependency comes from Middleman here:

https://github.com/middleman/middleman/blob/3812b031b6313ade4622c01f95ca154f36e09fb7/middleman-core/lib/middleman-core/renderers/slim.rb#L42

This line explicitly requires ::Temple::Generators::RailsOutputBuffer which requires ActionView::OutputBuffer.

Right now it looks like the application is the component that decides that it will render slim templates using middleman and therefore has to include the action action_view gem.

henrik commented 1 year ago

Well researched! I guess the reason it worked fine on Slim 4 was that it would use an earlier version of Temple, pre this change: https://github.com/judofyr/temple/commit/de6468249618e28ef67b4dea6a048892c31cd8d7

henrik commented 1 year ago

@judofyr Any thoughts on this? I assume it would not be appropriate for Temple to add ActionView as a dependency.

UweKubosch commented 1 year ago

Maybe let middleman choose a buffer type based on whether rails is available or not?

bostonaholic commented 1 year ago

Maybe let middleman choose a buffer type based on whether rails is available or not?

I agree. Why does middleman depend on rails in the first place? That makes no sense to me.

DannyBen commented 1 year ago

Explicitly adding the actionview gem and requiring it fixes the issue

This did not work for me for some reason.

minad commented 1 year ago

If I understand correctly this issue has been solved by adding action_view to the Gemfile as mentioned in https://github.com/slim-template/slim/issues/909#issuecomment-1435916165? Rails recommends to use ActionView::OutputBuffer instead of ActiveSupport::SafeBuffer for views, which caused this issue starting from Slim 5.0.

henrik commented 1 year ago

Thanks!

The issue was worked around from my point of view, and I’m a bit unclear on where it “should” be fixed – haven’t fully digested the comments above, but it seems to point to Middleman being the place. Either for a code change or “this is how you use it with Slim 5+” docs.

DannyBen commented 1 year ago

and I’m a bit unclear on where it “should” be fixed

I am too. One thing I am quite sure of - it does not need to be fixed in the user's side. This feels fragile. I had to add both the gem and a require 'action_view' in my middleman's config.rb.

minad commented 1 year ago

Yes, ideally it would be documented in the middleman documentation. Is there some place where Slim is already mentioned? Otherwise we could also add a link to a working Middleman example with Slim to the Slim README. But generally I don't want to add Middleman-specifics here.

henrik commented 1 year ago

@tdreyno (of Middleman), can I ask you for your thoughts?

If it is solved via docs, I guess one or both of these places could make sense:

DannyBen commented 1 year ago

Isn't it possible to solve it rather than documenting it? It is very rare that users are requested to "bring their own indirect dependencies", especially when it will not work without them.

minad commented 1 year ago

@DannyBen

Isn't it possible to solve it rather than documenting it? It is very rare that users are requested to "bring their own indirect dependencies", especially when it will not work without them.

Slim doesn't depend on Rails, but provides integration. We cannot depend on it here. If you want to solve the dependency issue, it must be done in Middleman.

DannyBen commented 1 year ago

If you want to solve the dependency issue, it must be done in Middleman.

Thanks. Yes, I realize that. I was responding to the comment above, who called for Middleman guys into the discussion.

henrik commented 1 year ago

Yes, I pinged them for their thoughts on how to solve it, ideally, and documenting only as a fallback solution. Thus the "If it is solved via docs".

dentarg commented 1 year ago

Looks like https://github.com/middleman/middleman/issues/2619 is the appropriate place to continue the discussion?

DannyBen commented 1 year ago

Looks like https://github.com/middleman/middleman/issues/2619 is the appropriate place to continue the discussion?

Isn't it a different issue?

dentarg commented 1 year ago

No, looks to be about the same thing to me