k0kubun / hamlit

High Performance Haml Implementation
https://rubygems.org/gems/hamlit
Other
981 stars 59 forks source link

Helper method does not get picked up within template #132

Closed wimrijnders closed 5 years ago

wimrijnders commented 5 years ago

In my haml template, a helper method _css() is called. This method is defined within the context of the page generator. The helper method gets used by Haml, but Hamlit doesn't appear to recognize it.

Is there any way to make it work with Hamlit?


Below the information as requested under 'Reporting an Issue'. Only, I will not supply the full backtrace and template because I feel that that adds a lot of senseless cruft.

Backtrace

....
6: from /home/wim/.rvm/gems/ruby-2.5.1-latest/gems/tilt-2.0.8/lib/tilt/template.rb:109:in `render'
5: from /home/wim/.rvm/gems/ruby-2.5.1-latest/gems/tilt-2.0.8/lib/tilt/template.rb:170:in `evaluate'
4: from /home/wim/.rvm/gems/ruby-2.5.1-latest/gems/tilt-2.0.8/lib/tilt/template.rb:170:in `call'
3: from (__TEMPLATE__):-5:in `__tilt_47184482149820'
2: from (__TEMPLATE__):-2:in `singleton class'
1: from (__TEMPLATE__):-2:in `instance_eval'
(__TEMPLATE__):3:in `block in singleton class': undefined method `_css' for #<Object:0x000055d3fd4722d8> (NoMethodError)

Haml template

!!! 5
- base_url = "vendor/skeleton"
- _css "#{base_url}/stylesheets/base.css", HIGH
- _css "#{base_url}/stylesheets/skeleton.css", HIGH
:plain
    <!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
    <!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
    <!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
    <!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
%head
...

Ruby version: 2.5.1

Hamlit version: 2.9.1

Rails/Sinatra version: none/2.0.4

k0kubun commented 5 years ago

I love to see "senseless cruft" to exclude some possibilities of bug by myself.

Anyway, _css is neither Haml's feature nor Hamlit's one (and what's HIGH?). So I have no way to reproduce your issue. Could you provide a minimal repository that reproduces your issue?

wimrijnders commented 5 years ago

Anyway, _css is neither Haml's feature nor Hamlit's one (and what's HIGH?). So I have no way to reproduce your issue. Could you provide a minimal repository that reproduces your issue?

_css() is of my making. I understand perfectly that you want something reproducable; however I've decided to go back to Haml and in this light, dismantling my project for a minimal example is asking a lot. Let this serve as a notification that this kind of thing can happen.

All the best!

k0kubun commented 5 years ago

I hope you're using Haml 5 and you'll love it, as I authored a significant part of the version :)

wimrijnders commented 5 years ago

:+1: I've being using Haml for 5+ years now without a significant problem. I have faith that latest version will work just as well. Kudo's for your work!