Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying an alternate template namespace. #77

Merged
merged 1 commit into from Dec 29, 2014

Conversation

@rwjblue
Copy link
Contributor

commented Dec 28, 2014

Allows precompiling HTMLBars templates.

emberTemplates: {
  options: {
    templateCompilerPath: 'bower_components/ember/ember-template-compiler.js',
    handlebarsPath: 'bower_components/handlebars/handlebars.js',
    templateNamespace: 'HTMLBars'
  },
  files: {
    'tmp/templates.js': 'app/templates/**/*.hbs'
  }
}
Allows precompiling HTMLBars templates.

```javascript
emberTemplates: {
  options: {
    templateCompilerPath: 'bower_components/ember/ember-template-compiler.js',
    handlebarsPath: 'bower_components/handlebars/handlebars.js',
    templateNamespace: 'HTMLBars'
  },
  files: {
    'tmp/templates.js': 'app/templates/**/*.hbs'
  }
}
```
dgeb added a commit that referenced this pull request Dec 29, 2014
Allow specifying an alternate template namespace.
@dgeb dgeb merged commit 88594c6 into dgeb:master Dec 29, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
@dgeb

This comment has been minimized.

Copy link
Owner

commented Dec 29, 2014

Thanks @rwjblue !

At what point should HTMLBars become the default namespace?

@rwjblue

This comment has been minimized.

Copy link
Contributor Author

commented Dec 29, 2014

I believe it should become the default once 1.10.0 is the stable version (roughly 3-4 weeks).

@rwjblue rwjblue deleted the rwjblue:allow-htmlbars-precompilation branch Dec 29, 2014
@dgeb

This comment has been minimized.

Copy link
Owner

commented Dec 29, 2014

Sounds good - thanks.

@panta82

This comment has been minimized.

Copy link

commented Jan 19, 2015

Hey, when do you plan to publish this to npm?

@rwjblue

This comment has been minimized.

Copy link
Contributor Author

commented Jan 19, 2015

We should likely do it soon.

@dgeb - I'll review the state of things to make sure we are good to go...

@dgeb

This comment has been minimized.

Copy link
Owner

commented Jan 19, 2015

@rwjblue - thanks! I'll publish v0.5.0 when you give the word.

@panta82

This comment has been minimized.

Copy link

commented Jan 19, 2015

@rwjblue, I tried patching the lib manually and failed. I'm confused about the "bower_components" parts. Do I have to install these separately? And where?

@panta82

This comment has been minimized.

Copy link

commented Jan 19, 2015

Never mind, I got it.

To make it clear, for those who want to get HTMLBars working prior to stable, you need to:

  • download ember-template-compiler.js from bower (not from npm, they only have the last stable there), and place it somewhere inside your project. If you're not using bower (like me), here's the direct link: https://raw.githubusercontent.com/components/ember/master/ember-template-compiler.js
  • Update grunt-ember-templates, once it gets on npm
  • Add the config that @rwjblue provided, where "handlebarsPath" is path to your handlebars.js (probably not needed, you should have it in node_modules) and templateCompilerPath is path to the downloaded beta ember-template-compiler.
@rwjblue

This comment has been minimized.

Copy link
Contributor Author

commented Jan 20, 2015

@panta82 - It is very important that you use the specific ember-template-compiler.js that is paired with your Ember version. That is the only way to ensure that your precompiled templates will match what your running Ember version expects. That is also why we publish ember.prod.js and ember-template-compiler.js to both Bower and S3 at the same time.

@rwjblue

This comment has been minimized.

Copy link
Contributor Author

commented Feb 6, 2015

@dgeb - I think we are ready to bump to 0.5.0. I'll keep an eye on the issues here, in case folks gets tripped up...

@joeruello

This comment has been minimized.

Copy link

commented Feb 8, 2015

Friendly ping to @dgeb, looking forward to using 1.10!

@hankthetank

This comment has been minimized.

Copy link

commented Feb 9, 2015

I'm still having trouble compiling a simple template. This is my Gruntfile.

module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),

emberTemplates: {
  compile: {
    options: {
      templateBasePath: /templates\//,
      templateCompilerPath: 'static/javascripts/emberlibs/ember-template-compiler.js',
      handlebarsPath: 'static/javascripts/emberlibs/handlebars-v2.0.0.js',
      templateNamespace: 'HTMLBars'
    },
    files: {
      'static/javascripts/templates.js': 'templates/*.hbs'
    }
  }
},

watch: {
  emberTemplates: {
    files: 'templates/*.hbs',
    tasks: ['emberTemplates']
  }
}

});

Running "emberTemplates:compile" (emberTemplates) task

ReferenceError: module is not defined
Warning: Ember Handlebars failed to compile templates/login.hbs. Use --force to continue.

Aborted due to warnings.

Only thing I have in my login.hbs is:

Hello {{name}}

Any ideas?

@dgeb

This comment has been minimized.

Copy link
Owner

commented Feb 9, 2015

@joeruello I just published v0.5.0, which uses HTMLBars as the default template namespace and should be compatible with ember 1.10.

@hankthetank please give v0.5.0 a try and open a new issue if you continue to have problems. Note that you won't need to specify HTMLBars as the templateNamespace, since it is now the default.

@hankthetank

This comment has been minimized.

Copy link

commented Feb 9, 2015

@dgeb Brilliant! No more errors! :) 👍

@panta82

This comment has been minimized.

Copy link

commented Feb 9, 2015

Works fine @dgeb , thx.

My grunt task:

emberTemplates: {
    options: {
        precompile: true,
        handlebarsPath: "node_modules/handlebars/dist/handlebars.js",
        templateCompilerPath: "vendor/ember/ember-template-compiler.js"
    },
    "public/js/templates.js": ["dev/templates/**/*.hbs"]
}

Hopefully, I'll be able to get rid of these paths at some point in the future?

@joeruello

This comment has been minimized.

Copy link

commented Feb 9, 2015

@dgeb Thanks so much!

@inexuscore

This comment has been minimized.

Copy link

commented Feb 18, 2015

I'm having trouble compiling my templates, I'm using Ember 1.10 and all dependencies are correctly installed and referenced. here's my gruntfile.js:

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        emberTemplates: {
            compile: {
                options: {
                    handlebarsPath: 'bower_components/handlebars/handlebars.js',
                    templateCompilerPath: 'bower_components/ember/ember-template-compiler.js',
                    templateNamespace: 'HTMLBars',
                    templateBasePath: /app\/templates\//
                },
                files: {
                    'app/scripts/templates.js': 'app/templates/**/*.hbs'
                }
            }
        },
        watch: {
            emberTemplates: {
                files: 'app/templates/**/*.hbs',
                tasks: ['emberTemplates']
            }
        }
    });

    grunt.loadNpmTasks('grunt-ember-templates');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', ['emberTemplates', 'watch']);
}

When i run grunt i get the following error:

ReferenceError: window is not defined

Any ideas? One more thing though. grunt-ember-templates has renamed the default namespace to HTMLBars in their latest release. If i remove the handlebarsPath and templateNamespace properties, my grunt tasks works fine and the output file is created without a problem. but then when i start the app i get the following error which i have encountered before:

Assertion Failed: template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?
@rwjblue

This comment has been minimized.

Copy link
Contributor Author

commented Feb 18, 2015

@inexuscore - Please make sure you are using the latest version (0.5.0).

@inexuscore

This comment has been minimized.

Copy link

commented Feb 18, 2015

@rwjblue - I doubled checked my packages and my grunt-ember-templates is 0.5.0, still no luck. anything i can do to make my case clearer? thank you

@rwjblue

This comment has been minimized.

Copy link
Contributor Author

commented Feb 18, 2015

@inexuscore - Please open a new issue, and provide a small demo repo so others can help out.

@inexuscore

This comment has been minimized.

Copy link

commented Feb 18, 2015

@rwjblue sure thing I'm on it, thanks again Robert

@inexuscore

This comment has been minimized.

Copy link

commented Feb 18, 2015

Resolved! turns out my handlebarsPath was pointing to the bower package. changed the path to the handlebars package in my node_modules and everything worked fine. duh, oh well 🎱 I guess that's what happens when you work with sleepy eyes.

@jeffma

This comment has been minimized.

Copy link

commented Feb 23, 2015

@inexuscore @rwjblue i changed the path to the handlebars to 'node_modules/handlebars/dist/handlebars.js' like you did, but it said

Running "emberTemplates:compile" (emberTemplates) task
>> Error: A block may only be used inside an HTML element or another block.

when i remove handlebarsPath option it can be compiled, but when i open the page it said

Assertion Failed: template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?

my grunt-ember-templates version is 0.5.0, ember version in bower is 1.10.0

@inexuscore

This comment has been minimized.

Copy link

commented Feb 23, 2015

Hi @jeffma
Based on the error message you get I would say that there's a problem in one your template's markup, a syntactic error perhaps.
I've created a new demo repo on github recently, you can find it at https://github.com/inexuscore/ember-tabbed-ui.
This project uses Ember 1.10 and grunt-ember-templates for precompilation. just clone the repo then do a bower install, npm install and you should be good to go.

Let me know if you couldn't use the repo.

@jeffma

This comment has been minimized.

Copy link

commented Feb 24, 2015

@inexuscore thanks your project, has solved my problem, template block must inside html tags, like <p>this is index hbs,title is {{title}}</p> , "<p></p>" is necessary;

@inexuscore

This comment has been minimized.

Copy link

commented Feb 24, 2015

@jeffma glad i could help, yup the problem was in your markup.

@and2

This comment has been minimized.

Copy link

commented Feb 25, 2015

Hey guys, there's something I don't seem to get: is ember-template-compiler.js still required in the html if the templates are precompiled on the server?

@joeruello

This comment has been minimized.

Copy link

commented Feb 25, 2015

Nope, we only include it on dev builds.
On 25 Feb 2015 12:26, "and2" notifications@github.com wrote:

Hey guys, there's something I don't seem to get: is
ember-template-compiler.js still required in the html if the templates are
compiled on the server?


Reply to this email directly or view it on GitHub
#77 (comment)
.

@and2

This comment has been minimized.

Copy link

commented Feb 25, 2015

Thanks @joeruello! I thought so. The thing is, I've got a template precompiled with grunt-ember-templates. But when I try to run my app without ember-template-compiler.js I get "Uncaught Error: Cannot call compile without the template compiler loaded. Please load ember-template-compiler.js prior to calling compile."

I'm loading ember.prod.js (1.10). The template seems to be compiled fine with

options: {
precompile: true,
templateNamespace: 'HTMLBars',
templateCompilerPath: 'public/components/ember/ember-template-compiler.js',
handlebarsPath: 'node_modules/handlebars/dist/handlebars.js'
} 
@rwjblue

This comment has been minimized.

Copy link
Contributor Author

commented Feb 25, 2015

@and2 - Most likely you have something being included in your build that is attempting to use Ember.Handlebars.compile or Ember.HTMLBars.compile (that is not your templates).

@and2

This comment has been minimized.

Copy link

commented Feb 25, 2015

Hmm, I wonder where. There's the same issue with @inexuscore's repo above. If ember-template-compiler is removed from html, same exception is thrown. I'll dig deeper..

@and2

This comment has been minimized.

Copy link

commented Feb 25, 2015

Ah, silly, I had an {{outlet}} in the html which was obviously trying to compile at runtime..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.