slim-template / slim

Slim is a template language whose goal is to reduce the syntax to the essential parts without becoming cryptic.

Home Page:https://slim-template.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

henrik opened this issue · comments

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'
…

Explicitly adding the actionview gem and requiring it fixes the issue: henrik/henrik.nyh.se@b27f08d

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.

I'm experiencing the same problem.

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.

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: judofyr/temple@de64682

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

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

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.

Explicitly adding the actionview gem and requiring it fixes the issue

This did not work for me for some reason.

If I understand correctly this issue has been solved by adding action_view to the Gemfile as mentioned in #909 (comment)? Rails recommends to use ActionView::OutputBuffer instead of ActiveSupport::SafeBuffer for views, which caused this issue starting from Slim 5.0.

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.

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.

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.

@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:

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.

@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.

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.

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".

Looks like middleman/middleman#2619 is the appropriate place to continue the discussion?

Looks like middleman/middleman#2619 is the appropriate place to continue the discussion?

Isn't it a different issue?

No, looks to be about the same thing to me