bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
194 stars 92 forks source link

handlebars-asset-pipeline 3.0.6 not aware of templateRoot? #222

Closed DontPlayTheGame closed 4 years ago

DontPlayTheGame commented 6 years ago

I am using Grails 3.3.2 build.gradle was:

buildscript {
    dependencies {
    classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.0.6"
    }
}
apply plugin:"com.bertramlabs.asset-pipeline"
dependencies {
   runtime "com.bertramlabs.plugins:asset-pipeline-grails:3.0.6"
   assets  "com.bertramlabs.plugins:handlebars-asset-pipeline:3.0.6"
}
assets {
    minifyJs = true
    minifyCss = true
    enableDigests = false
}

In application.groovy i had:

grails {
    assets {
        handlebars {
            templateRoot = 'handlebars'
            templatePathSeperator = "/"
        }
    }
}

hbs-Files are in /assets/javascripts/handlebars In a gsp:

<asset:javascript src="handlebars/myTemplate.hbs"/>
<script type="text/javascript">
var hbTemplate = "'myTemplate'";

===== Using this configuration worked fine for development. The precompiled template was fine:

(function(){
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['myTemplate'] = template({"1":function(container,depth0,helpers,partials,data) { ....

BUT in the productive environment this was changed to:

(function(){
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['handlebars/myTemplate'] = template({"1":function(container,depth0,helpers,partials,data) { ....

So I always get the error "Handlebars.template.myTemplate is not a function" After many tries i figured out this: Removing the "grails { assets { handlebars {" block form application.groovy. Change build.gradle to:

assets {
    minifyJs = true
    minifyCss = true
    enableDigests = false
    configOptions = [
            handlebars: [
                    templateRoot: 'handlebars',
                    templatePathSeperator: '/'
            ]
    ]
}

Now: i have the same precompiled code in development and production:

(function(){
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['handlebars/myTemplate'] = template({"1":function(container,depth0,helpers,partials,data) { ...

I can now call var hbTemplate = "'handlebars/myTemplate'";

But this is not how templateRoot should work?!?

DontPlayTheGame commented 6 years ago

Issue can be closed! I missed the part If you want settings to apply to both development runtime and build time the properties have to be duplicated in your applications application.yml ... in the documentation.