leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
649 stars 159 forks source link

.slimbars are not processed #118

Closed vmotsak closed 9 years ago

vmotsak commented 9 years ago

I tried to use gem with .slimbars templates, but I'm failed.

My research lead me to this code

     def is_slim?
        result = false
        ::HandlebarsAssets::Config.slimbars_extensions.each do |ext|
          if ext.start_with? '.'
            ext = '\\#{ext}'
            result ||= !(@full_path =~ /#{ext}(\..*)*$/).nil?
          else
            result ||= !(@full_path =~ /\.#{ext}(\..*)*$/).nil?
          end
        end
        result
      end

first it look like ext = '\\#{ext}' suppose to evaluate ext but it's in single quotes. also not sure what is checked after extension by regex. why it can't be replaced by

      def is_slim?
        @full_path.end_with?(*::HandlebarsAssets::Config.slimbars_extensions)
      end

PS. it looks like tests are failing on master

AlexRiedler commented 9 years ago

@vmotsak yeah... tests are failing on master, I updated to latest minitest and then they failed; I will be release a new point release which should fix this issue today.

AlexRiedler commented 9 years ago

@vmotsak in regards to that code... it is actually something else that is failing; they reason that is to support both old and new format of trailing dots... however that code really should not be duplicated like that.

must also support .foo.hbs.slim etc

AlexRiedler commented 9 years ago

@vmotsak released 0.19.1

vmotsak commented 9 years ago

| must also support .foo.hbs.slim etc

for this case what's set in Config.slimbars_extensions .hbs.slim? .slim? but even it this case end_with? should return correct result unless it's Config.slimbars_extensions =['.slimbars'] and .foo.slimbars.hbs also should be matched.

AlexRiedler commented 9 years ago

my example was probably bad.... @vmotsak

.hbs must be just one of the extensions (as sprockets allows chaining).

e.g. .hbs.erb or .hbs.txt where the extension is defined as .hbs

ciscou commented 9 years ago

I'm having a similar issue and I'm not sure if I've understood the fix, so to double check

I had a project (middleman) that did serve templates with .hamlbars extension with v0.18

With v0.19 it stopped working (they were not served at all)

With v0.19.1 it is working again, but only if I name my file something.hbs.hamlbars. something.hamlbars will not work (and it used to work in v0.18). Is that intended?

Thanks1

AlexRiedler commented 9 years ago

@ciscou I could have potentially made an error, I will try to look into it soon!

AlexRiedler commented 9 years ago

@ciscou I can't seem to replicate the problem... is there a reproducible test case you have available ?

Are you also using the hamlbars gems? (just curious, cause if that is the case you will need both extensions with sprockets sadly).

vmotsak commented 9 years ago

@AlexRiedler

created sample project for above case at https://github.com/vmotsak/hbs-slimbars-118

Trying to access test.hbs.sllimbars as http://localhost:3000/assets/templates/test.js?body=1

shows

   throw Error("Slim::Parser::SyntaxError: Unknown line indicator\n  (__TEMPLATE__), Line 1, Column 0\n    (function() {\n    ^\n\n......

It looks like handlebars process template before slim.

ciscou commented 9 years ago

Sorry.

Looks like downgrading middleman from 3.3.9 to 3.3.7 fixes the extension issue for me. Will do some further research and open an issue on their side if needed.

Thanks!

AlexRiedler commented 9 years ago

@ciscou interesting...

@vmotsak if your using slimbars, you should have have to do the extension '.slimbars' no need to do '.hbs' as well.

vmotsak commented 9 years ago

.hbs must be just one of the extensions (as sprockets allows chaining).

slimbars works now, so I'm closing the issue