leshill / handlebars_assets

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

slimbars problem after migration to rails 4 #93

Closed dotob closed 10 years ago

dotob commented 10 years ago

hi,

i migrated a fine working app from rails 3.2 to rails 4. now my slimbars templates stopped working.

slim always complains about handlebars syntax:

Expected attribute
  (__TEMPLATE__), Line 4, Column 6
    td {{item.path}}
        ^

  (in /Users/basti/Development/rails/lfi/app/assets/javascripts/templates/image_table_row.slimbars)/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/slim-2.0.2/lib/slim/parser.rb:478:in `syntax_error!'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/slim-2.0.2/lib/slim/parser.rb:408:in `parse_attributes'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/slim-2.0.2/lib/slim/parser.rb:317:in `parse_tag'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/slim-2.0.2/lib/slim/parser.rb:228:in `parse_line_indicators'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/slim-2.0.2/lib/slim/parser.rb:176:in `parse_line'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/slim-2.0.2/lib/slim/parser.rb:77:in `call'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/temple-0.6.7/lib/temple/engine.rb:50:in `block in call'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/temple-0.6.7/lib/temple/engine.rb:50:in `each'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/temple-0.6.7/lib/temple/engine.rb:50:in `inject'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/temple-0.6.7/lib/temple/engine.rb:50:in `call'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/temple-0.6.7/lib/temple/mixins/template.rb:10:in `compile'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/temple-0.6.7/lib/temple/templates/tilt.rb:28:in `prepare'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/tilt-1.4.1/lib/tilt/template.rb:79:in `initialize'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/handlebars_assets-0.15/lib/handlebars_assets/tilt_handlebars.rb:31:in `new'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/handlebars_assets-0.15/lib/handlebars_assets/tilt_handlebars.rb:31:in `evaluate'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/context.rb:197:in `block in evaluate'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/context.rb:194:in `each'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/context.rb:194:in `evaluate'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:374:in `new'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:373:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:93:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:287:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:61:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:105:in `each'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:16:in `initialize'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:374:in `new'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:373:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:93:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:287:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:61:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:377:in `new'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:377:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:93:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:287:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:61:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:211:in `block in find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:257:in `benchmark'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:210:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:119:in `block in compile'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:118:in `each'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:118:in `compile'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/rake/sprocketstask.rb:146:in `with_logger'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
AlexRiedler commented 10 years ago

hi @dotob, I think this may be due toe a slim version upgrade?

handlebars_assets compiles through slim first, which is what is throwing the error in this case. You may need to use a raw statement to get around this in slim.

dotob commented 10 years ago

i thought so too. but tried same (old) versions of handlebars_assets and slim (and temple btw). error again:

(__TEMPLATE__):3: syntax error, unexpected '}', expecting =>
....escape_html_safe(({{item.name}}))}"\
...                               ^
(__TEMPLATE__):4: unknown regexp options - td
(__TEMPLATE__):4: syntax error, unexpected '<'
"</a></td><td>{{item.path}}"\
           ^
(__TEMPLATE__):4: syntax error, unexpected '}', expecting =>
"</a></td><td>{{item.path}}"\
                          ^
(__TEMPLATE__):6: unknown regexp options - td
(__TEMPLATE__):6: syntax error, unexpected '<'
"</td><td>{{item.last_change}}"\
       ^
(__TEMPLATE__):6: syntax error, unexpected '}', expecting =>
"</td><td>{{item.last_change}}"\
                             ^
(__TEMPLATE__):7: unknown regexp options - tr
(__TEMPLATE__):7: unterminated string meets end of file
(__TEMPLATE__):7: syntax error, unexpected end-of-input, expecting ')'
end;end;end;end
               ^
  (in /Users/basti/Development/rails/lfi/app/assets/javascripts/templates/image_table_row.slimbars)
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/tilt-1.4.1/lib/tilt/template.rb:264:in `class_eval'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/tilt-1.4.1/lib/tilt/template.rb:264:in `compile_template_method'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/tilt-1.4.1/lib/tilt/template.rb:240:in `compiled_method'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/tilt-1.4.1/lib/tilt/template.rb:169:in `evaluate'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/handlebars_assets-0.12.0/lib/handlebars_assets/tilt_handlebars.rb:28:in `evaluate'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/context.rb:197:in `block in evaluate'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/context.rb:194:in `each'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/context.rb:194:in `evaluate'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:374:in `new'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:373:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:93:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:287:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:61:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:105:in `each'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/processed_asset.rb:16:in `initialize'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:374:in `new'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:373:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:93:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:287:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:61:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/bundled_asset.rb:37:in `init_with'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/asset.rb:24:in `from_hash'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/caching.rb:54:in `cache_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:93:in `build_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/base.rb:287:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/index.rb:61:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:211:in `block in find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:257:in `benchmark'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:210:in `find_asset'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:119:in `block in compile'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:118:in `each'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/sprockets/manifest.rb:118:in `compile'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-2.10.1/lib/rake/sprocketstask.rb:146:in `with_logger'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
/Users/basti/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile

what do you mean by "use a raw statement" ?

AlexRiedler commented 10 years ago

basically slim needs to treat the HB tags as text so, I believe in slim (could not find that other PR where me and a few others talked about it):

td
  | {{item.path}}

and yes, it would be awesome if you didn't have to do that; you could potentially use a template helper and so something like (not verified):

td
  = hb "item.path"

Hope that helps!

the-teacher commented 10 years ago
h1{} {{ title }}
p{}  {{ content }}
AlexRiedler commented 10 years ago

@the-teacher is that another solution, or another problem (just clarifying)

Thanks!

AlexRiedler commented 10 years ago

Closing after 15 days; if it still an issue @dotob feel free to re-open! and I will look into more.