emilioforrer / haml_coffee_assets

Haml Coffee templates in the Rails asset pipeline or as Sprockets engine.
https://rubygems.org/gems/haml_coffee_assets
MIT License
438 stars 145 forks source link

Templates not being found #152

Closed jwarzech closed 3 years ago

jwarzech commented 8 years ago

I just created a new rails 4.2 app and my templates are getting loaded int JST. I see in the issues that it looks like there was some version incompatibilities but as I understand @emilioforrer seems to have fixed these?

rpbaltazar commented 8 years ago

Is your JST being populated at all? If I use the latest version of the gem 1.16.2 JST doesn't even get defined to me.

jwarzech commented 8 years ago

It will if I place a normal ".jst" file in my templates directory - I don't believe JST gets defined unless there is a single template it recognizes in the directory.

Since I can't get ".jst.hamlc" files to get recognized that object won't get defined if that is all I have in /templates

rpbaltazar commented 8 years ago

I believe that is in fact a bug.

I have a project that is using haml_coffee_assets 1.16.0 and hamlc files get loaded and JST gets defined. The only problem is that the old version of the gem requires an old version of sprokets.

I'm open for suggestions here....

derSascha commented 8 years ago

Looks like its a bug with sprockets-rails > 3.

This Gemfile works fine (server and client side hamlc rendering):

gem 'rails', '4.2.6'
gem 'sass-rails'
gem 'coffee-rails'
gem 'sprockets-rails', '< 3' # = 2.3.3
gem 'haml-rails'
gem 'haml_coffee_assets', '1.16.2'
gem 'jquery-rails'

After upgrading sprockets-rails, server side rendering works but templates are not available in assets pipepline anymore:

gem 'rails', '4.2.6'
gem 'sass-rails'
gem 'coffee-rails'
gem 'sprockets-rails', '> 3' # = 3.0.4
gem 'haml-rails'
gem 'haml_coffee_assets', '1.16.2'
gem 'jquery-rails'

Both versions are using sprockets 3.5.2. Any suggestions what changes in sprockets-rails?

TheKidCoder commented 8 years ago

I took a dive into the changes to sprockets that could cause this... Unfortunately the changes are large and not well documented. Would be great to get someone more familiar with sprockets and the 3.x changes to take a look.

EDIT: It looks like I didn't see a pull request that is pending. Need that merged in to fix this issue. In the mean time, you can use this: https://github.com/TheKidCoder/haml_coffee_assets

arjun-urs commented 8 years ago

+1. I am facing the same problem after upgrading the sprockets

@TheKidCoder Your fork did not fix the issue. Have you merged it yet?

TheKidCoder commented 8 years ago

Can you post your Gemfile.lock ? My branch is working for me (for the most part)...

arjun-urs commented 8 years ago

@TheKidCoder Here is the Gemfile.lock gist. Please have a look.

https://gist.github.com/arjun-urs/d95bb094e0e37edfa299f5f4675ad663

Also, I am concerned with this repo, it's not up-to-date and many pull requests pending. I am wary of including this gem in future projects.

emilioforrer commented 8 years ago

I just found this bug in a new project, where JST is undefined. I seems to be an incompatibility with sprockets-rails v3+.

As a work around you, can downgrade sprockets-rails to gem "sprockets-rails", "2.3.3" until this bug gets fixed

TheKidCoder commented 8 years ago

@arjun-urs I'm working on the upgrade for sprockets 3.x. In the mean time, @emilioforrer is right, you need to downgrade.

mmatviyiv commented 8 years ago

The same issue guys P.S: rails 4.2.6, haml_coffee_assets 1.16.2

mnoack commented 8 years ago

@emilioforrer I think some people have solved it in their forks. In rails 5 with sprockets 2 I get this deprecation:

DEPRECATION WARNING: Sprockets method register_engine is deprecated. Please register a mime type using register_mime_type then use register_compressor or register_transformer. https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors (called from block in class:Engine at haml_coffee_assets-1.16.2/lib/haml_coffee_assets/rails/engine.rb:83)

This person's fork works for me (it doesn't resolve the deprecation, I note some other forks resolve the deprecation but didn't work for me) in rails 5 and sprockets 3 https://github.com/nolan/haml_coffee_assets/commits/master

With any luck perhaps adopting this change (or tweaking it) might just work.

emilioforrer commented 8 years ago

Thanks @mnoack.

Can you try the branch release/v2.0.0, to see if it works for you?

mnoack commented 8 years ago

@emilioforrer Yes that works. I will note before I had files in the format: _blah.hamlc, _blah.jst.haml and blah.hamlc

I have to remove _ prefix and add '.jst' before hamlc before it worked, and that's probably a good thing because our files were so inconsistent!

theoo commented 8 years ago

@emilioforrer That works also for me with the following line in Gemfile:

gem 'haml_coffee_assets', github: "emilioforrer/haml_coffee_assets", branch: "release/v2.0.0"

and after renaming my files in .jst.hamlc instead of just .hamlc It worked, but I had the following bug after the migration: #156, it's maybe related to the last change on the v2.0.0 branch.

r3cha commented 8 years ago

I just made little update - and get this, as new in backbone(have this on front) i can't realize what happens... so i use gem 'haml_coffee_assets' who depends on sprockets >= 2 may be dependency of this gem should set on sprockets < 3 upd.: get generated templates but i think i have another problem it is - backbone js, i don't know it )

TheKidCoder commented 7 years ago

I just released a new verion, 1.17.0, can you all give that a try and let me know if you are still having issues?

theoo commented 7 years ago

Hi @TheKidCoder, on my setup this unfortunately doesn't work. JST get populated but none of the array entries are functions that I could call with JST["path/to/my/view"]()

You can find a Gemfile.lock in the tree of my (work in progress) work. This is how I load my views in Spine.js.

bikramwp commented 7 years ago

Looking into this, I found that adding return to the following file fixes the issue: https://github.com/emilioforrer/haml_coffee_assets/blob/master/lib/js/hamlcoffee.js#L790

So, template += "" + this.options.namespace + "['" + this.options.name + "'] = (context) -> ( ->\n"; to template += "" + "return " + this.options.namespace + "['" + this.options.name + "'] = (context) -> ( ->\n";

ebeigarts commented 7 years ago

I have managed to get this working by using HamlCoffeeAssets.config.placement = 'standalone' with Sprockets 3 and Rails 5.1.

Before:

(function() { this.JST || (this.JST = {}); this.JST["my_template"] = (function() {
    if (window.JST == null) {
      window.JST = {};
    }

    window.JST['my_template'] = function(context) {
      return (function() {
        var $c, $e, $o, title;
        $e = window.HAML.escape;
        $c = window.HAML.cleanValue;
        $o = [];
        $o.push("...");
        return $o.join("\n").replace(/\s([\w-]+)='“true'/mg, ' $1').replace(/\s([\w-]+)='“false'/mg, '').replace(/\s(?:id|class)=(['"])(\1)/mg, "");
      }).call(window.HAML.context(context));
    };

  }).call(this);;
}).call(this);

After (with standalone):

(function() { this.JST || (this.JST = {}); this.JST["my_template"] = (function() {
    return function(context) {
      return (function() {
        var $c, $e, $o, title;
        $e = window.HAML.escape;
        $c = window.HAML.cleanValue;
        $o = [];
        $o.push("...");
        return $o.join("\n").replace(/\s([\w-]+)='“true'/mg, ' $1').replace(/\s([\w-]+)='“false'/mg, '').replace(/\s(?:id|class)=(['"])(\1)/mg, "");
      }).call(context);
    };

  }).call(this);;
}).call(this);
jcotillo commented 6 years ago

Still experiencing this problem with v1.18.0 and rails 4.2. Are there plans to release a fix for this problem in the next version?

Using this fork github.com/nolan/haml_coffee_assets/ until further notice; since it also seems to support rails 5. Would prefer to use this gem directly though!

covard commented 6 years ago

@jcotillo you have it working with that fork? I am pointing to it and still having the depreciation warnings.

mathieujobin commented 4 years ago

The fix above mentioned by @cyu worked for me

Rails 4.2 and latest Sprockets 3.7

mathieujobin commented 3 years ago

You can use the latest master, the patch for this has been merged. I will release in a few days or weeks