Giter VIP home page Giter VIP logo

grunt-ember-templates's Introduction

grunt-ember-templates Build Status

Precompile Handlebars templates for Ember.js.

Getting Started

This plugin requires Grunt ^0.4.5.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-ember-templates --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

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

grunt-ember-templates v1.0 compatible with Ember v1.10+

If you use earlier version of Ember, please use the grunt-ember-templates v0.6.

The most basic example

  • Install Ember.js with bower: $ bower install ember --save
  • Install this package with: $ npm install grunt-ember-templates@~1.0.0 --save-dev
  • Create an app/templates folder for your hbs files. Create a few hbs files there.
  • Create a basic Gruntfile.js:
module.exports = function(grunt) {

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

  grunt.initConfig({
    emberTemplates: {
      default: {
        options: {
          templateBasePath: 'app/templates'
        },
        files: {
          "tmp/templates.js": ["app/templates/**/*.hbs"]
        }
      }
    }
  })

  grunt.registerTask('default', ['emberTemplates']);
}
  • (Optional: Install grunt-cli with $ npm install -g grunt-cli and install grunt locally with $ npm install grunt --save-dev.)
  • Run grunt in your console.

You can find the compiled templates.js in tmp folder.

Overview

Inside your Gruntfile.js file, add a section named emberTemplates. This section specifies the files to compile and the options used with handlebars.

files

Type: object

This defines what files this task will process and should contain key:value pairs.

The key (destination) should be an unique filepath (supports grunt.template) and the value (source) should be a filepath or an array of filepaths (supports minimatch).

Note: Values are precompiled to the Ember.TEMPLATES array in the order passed.

options

Type: object

This controls how this task operates and should contain key:value pairs. See specific options below.

Options

amd

Type: boolean | string Default: false

Include this option to ensure that the compiled output will be defined as a single AMD module with a single dependency (ember). If you'd like to output individual templates as modules, skip this option and use the templateRegistration option described below.

If you'd like to customize the module name for Ember, pass this option a string. (For backwards compatibility, the string "true" acts like the boolean true, and will result in ember being used as the module name. )

options: {
  amd: "vendor/ember"
}
concatenate

Type: boolean or function Default: true

Disable this option to compile the templates to multiple individual files, rather than concatenating them into a single file. When concatenation is disabled, the destination property specifies the folder where compiled templates will be placed. The directory and file structure will mirror the source.

This option is useful for situations where you'd like to let a build optimizer concatenate files in particular ways.

options: {
  concatenate: false
},
files: {
  "path/to/destination/folder": ["path/to/sources/*.handlebars", "path/to/more/*.handlebars"]
}

Alternatively, you can specify your own function to do the concatenation. Here's an example that wraps the output in an IIFE:

options: {
  concatenate: function(output, processedTemplates) {
    output = output.concat('(function(){');
    return output.concat(
      processedTemplates.map(function (template) {
        return template.contents;
      })).concat('})();');
  }
}
precompile

Type: boolean Default: true

Disable this option to skip template precompilation with handlebars.js and instead wrap the template content with Ember.Handlebars.compile. This will reduce template compilation time during development. Don't disable this option for production build.

preprocess

Type: function Arguments: source

This option accepts a function which can be used to preprocess the raw contents of the source read from the template file.

You may want to use this function to strip comments or minify whitespace:

options: {
  preprocess: function(source) {
    return source.replace(/\s+/g, ' ');
  }
}
templateBasePath

Type: regex | string

A regex or string to match the base path to your template directory. If defined, this path will be stripped out of template names by the default implementation of templateNameFromFile().

options: {
  templateBasePath: /path\/to\/templates\//
}
templateFileExtensions

Type: regex | string Default: /\.(hbs|hjs|handlebars)/

A regex or string to match the file extensions for your templates. Extensions will be stripped out of template names by the default implementation of templateNameFromFile().

For example, if you're using a non-standard extension for your template files, you can strip it out like so:

options: {
  templateFileExtensions: /\.hbars/
}
templateName

Type: function Arguments: fileName

This option accepts a function which takes one argument (the source template filepath, which has already been stripped of its file extensions and base directory) and returns a string which will be used as the key for the precompiled template.

For example, let's say that all of your templates are suffixed with _template, which you don't want included in the actual template name. You could strip off this suffix as follows:

options: {
  templateName: function(name) {
    return name.replace('_template', '');
  }
}
templateNameFromFile

Type: function Arguments: filePath

This option accepts a function which takes one argument (the full source template filepath) and returns a string which will be used as the key for the precompiled template object.

By default, this function strips away templateBasePath and templateFileExtensions from a filepath, and then returns the result of templateName().

This function should only be overridden if you need complete control over the returned template name that can not be achieved via the other options.

templateNamespace

Type: string Default: HTMLBars

This option defines the namespace of the template compiler.

For example, to use Handlebars instead of HTMLBars:

options: {
  templateNamespace: 'Handlebars'
}
templateRegistration

Type: function Arguments: name, contents

This option allows for custom registration of templates. It accepts a function which takes as arguments the name of a template (seetemplateNameFromFile) and its contents (which may be compiled or not - see precompile). This function should return a string of JS code to be added to the generated file.

By default, this function assigns templates to Ember.TEMPLATES with their name as the key and contents as the value.

This function should be overridden if you need to register templates in an alternative fashion. For example, it could be used to define custom modules for each of your templates:

options: {
  templateRegistration: function(name, contents) {
    return "define('templates/" + name + "', ['ember'], function(Ember) { return " + contents + "; });";
  }
}
templateCompilerPath

Type: string Default: bower_components/ember/ember-template-compiler.js

This option allows this default to be overridden to different version of the ember-template-compiler.js.

For example, if there are upstream changes in Ember's compiler that haven't yet been published with ember-template-compiler, you could specify paths to local versions of the template compiler:

options: {
  templateCompilerPath: 'vendor/ember/ember-template-compiler.js'
}

Config Example

A common configuration might be to combine the amd and templateBasePath options as follows:

emberTemplates: {
  compile: {
    options: {
      amd: true,
      templateBasePath: /path\/to\//
    },
    files: {
      "path/to/result.js": "path/to/source.handlebars",
      "path/to/another.js": ["path/to/sources/*.handlebars", "path/to/more/*.handlebars"]
    }
  }
}

Here's an example task that watches for changes to your templates and automatically recompiles them:

watch: {
  emberTemplates: {
    files: 'app/scripts/**/*.handlebars',
    tasks: ['emberTemplates', 'livereload']
  },
}

Usage Tips

  • This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.2.

  • Check the Release History below for version compatibility with Ember and Handlebars. The latest version of this plugin tends to track ember-latest, so you may need an older version to work with the latest official release of Ember.

  • Remember to name partial templates with a leading underscore. This underscore will be preserved in the compiled template name. For instance, post/_edit.hbs will be registered as Ember.TEMPLATES["post/_edit"].

Credit

Many thanks to the following projects upon which this was based:

I created this project as an alternative to grunt-ember-handlebars for the following reasons:

  • to provide maximum compatibility with the grunt-contrib project, using features such as destination:source file arguments
  • to allow for customizable template names based upon source file paths

Release History

  • 2018/09/02 - v1.2.0 - Extend concatenate option with accepting function as a param.
  • 2017/12/24 - v1.1.2 - Add Ember v2.17 support.
  • 2017/01/25 - v1.1.1 - Add Ember v2.11 support, improve testing.
  • 2016/09/12 - v1.1.0 - Add Ember v2.7 and v2.8 support, extend tests for testing multiple Ember versions.
  • 2016/03/28 - v1.0.0 - Removed ember-template-compiler and handlebar npm dependencies. Removed handlebarsPath option. Default: using the bundled ember-template-compiler.js from Ember.js bower package.
  • 2015/02/09 - v0.5.0 - HTMLBars is now the default template namespace.
  • 2014/11/17 - v0.5.0-alpha - Handlebars 2.0 compatibility via alpha ember-template-compiler. Thanks @smounir!
  • 2014/10/29 - v0.4.23 - Fixed peer dependencies issue for ember-template-compiler 1.8.x
  • 2014/10/23 - v0.4.22 - Updated ember-template-compiler peer dependencies for Handlebars 1.x compatibility. Thanks @cyril-sf!
  • 2014/04/02 - v0.4.21 - Introduced concatenate option. Thanks @joshvfleming!
  • 2014/03/11 - v0.4.20 - amd option can now accept a string to define Ember's module name. Thanks @Kerrick!
  • 2014/03/02 - v0.4.19 - Require node to be >= 0.8.19 to avoid peerDependencies issue. Thanks @rjackson!
  • 2013/12/04 - v0.4.18 - Introduced ember-template-compiler dependency. Thanks @rjackson!
  • 2013/11/20 - v0.4.17 - Added templateCompilerPath and handlebarsPath option. Thanks @rjackson!
  • 2013/11/04 - v0.4.16 - Added preprocess option. Thanks @timrwood!
  • 2013/09/25 - v0.4.15 - Added templateRegistration option. Thanks @lukemelia!
  • 2013/09/05 - v0.4.14 - Now using lowercase module name ember with amd option. Thanks @rpflorence!
  • 2013/09/01 - v0.4.13 - Upgraded ember-template-compiler.js to 1.0.0 (woot!). Added precompile option - thanks @manoharank!
  • 2013/08/19 - v0.4.12 - Added templateBasePath alias to templateBaseDir. Default templateFileExtensions now also include .hjs.
  • 2013/08/18 - v0.4.11 - Upgraded ember-template-compiler.js to 1.0.0-rc.7. Plus new amd, templateBaseDir, templateFileExtensions, and templateNameFromFile options.
  • 2013/06/25 - v0.4.10 - Upgraded Handlebars to 1.0.0.
  • 2013/06/24 - v0.4.9 - Upgraded ember-template-compiler.js to 1.0.0-rc.6
  • 2013/06/09 - v0.4.8 - Upgraded ember-template-compiler.js to 1.0.0-rc.5 - thanks @AdamFerguson!
  • 2013/05/22 - v0.4.7 - Deprecate ember_templates task in favor of emberTemplates.
  • 2013/05/16 - v0.4.6 - Upgraded Handlebars to 1.0.0-rc4.
  • 2013/05/03 - v0.4.5 - Fixed multi-file output - thanks @seankeating!
  • 2013/04/05 - v0.4.4 - Ember v1.0.0-rc.2 compatible.
  • 2013/02/18 - v0.4.3 - Upgraded to grunt 0.4.0 final.
  • 2013/02/17 - v0.4.3rc8 - Now uses ember-template-compiler. Upgraded to grunt 0.4.0.rc8.
  • 2013/02/06 - v0.4.3rc7 - Updated to latest handlebars for compatibility with latest ember - thanks @codeofficer!
  • 2013/01/24 - v0.4.2rc7 - Upgraded for grunt 0.4.0rc7 and handlebars 1.0.rc.2 - thanks @GManzato!
  • 2013/01/10 - v0.4.2rc5 - Upgraded for grunt 0.4.0rc5 - thanks @trev!
  • 2013/01/01 - v0.4.1 - Fixed file pattern matching
  • 2012/12/26 - v0.4.0 - Upgraded for grunt 0.4.0 compatibility - thanks @trek!
  • 2013/03/07 - v0.3.2 - Backported ember-template-compiler for Grunt 0.3 compatibility - thanks @rafshar
  • 2013/01/24 - v0.3.1 - Fixed grunt-contrib-lib dependency
  • 2013/01/24 - v0.3.0 - Grunt 0.3.0 and Handlebars 1.0.rc.2 compatible - thanks @GManzato!
  • 2012/10/11 - v0.2.0 - Renamed grunt-ember-templates from grunt-contrib-ember.
  • 2012/09/28 - v0.1.0 - Initial release.

Development and test

  • Please use Node.js v0.12 for testing and development, so we can keep the backward compatibility. I suppose, you use nvm for managing Node.js versions on your computer. .nvmrc added to the root folder, so it can jump back to this version when you open this project.
$ nvm install 0.12

Install node packages

$ npm install

Run tests:

$ npm test

or

$ grunt test

Adding a new Ember version test

  1. Add the new version string to the EMBER_VERSIONS constant in Gruntfile.js.
  2. Create the expected result files and save in the test/expected folder. For example: test/expected/2.11.0

grunt-ember-templates's People

Contributors

adamferguson avatar amacneil avatar andyhot avatar codeofficer avatar cyril-sf avatar dgeb avatar gmanzato avatar gr0uch avatar huguesdk avatar joshvfleming avatar kadishmal avatar kerrick avatar lukemelia avatar m-bd avatar manoharank avatar nerdyworm avatar rafshar avatar rwjblue avatar ryanflorence avatar timrwood avatar trek avatar trev avatar zoltan-nz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-ember-templates's Issues

Error log doesn't show the problematic filename

Hi,

This is what I get:

Running "emberTemplates:dist" (emberTemplates) task
Warning: Encoding::UndefinedConversionError on line ["654"] of C: "\x90" to UTF-8 in conversion from Windows-1252 to UTF-8
Run with --trace to see the full backtrace Use --force to continue.

I am using inside a grunt server task but using --trace doesn't make any difference in the output

jshint complain about using dot notation

While running my tasks, jshint complain to how the template is compiled and suggest to use dot notation

app/templates/compiledTemplates.js
3 |Ember.TEMPLATES["index"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
^ ['index'] is better written in dot notation.

1 error in 4 files
Warning: Task "jshint:files" failed. Use --force to continue.

I force and now I can work but I don't think is the best way using force..

New release with latest changes?

Hello,

Since Ember.js 1.9, when using the templateCompilerPath and handlebarsPath options, this task fails with the following error:

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

It works fine though with the latest changes in the master, even with Ember.js 1.10.

Is a new release to NPM planned soon?

Thanks.

Does not work for ember versions > 1.9.1

Starting in v1.10, Ember is distributing the ember-template-compiler with the ember install.
grunt-ember-templates uses the ember-template-compiler package on npm, which is stuck at 1.9.
Do you have any plans to work out compatibility for newer versions of Ember?
Otherwise, I'd suggest making a note on your Readme.

Templates not redendering anymore in EmberJS app after upgrade from v 0.4.22

I have upgraded the grunt-ember-templating, with in return installed ember-template-compiler 1.9.0 alfa.
Once i reconfigured grunt to compile the hbs files into 1 template.js, my app does not render the templates anymore.

i use nodeJS with express framework

If i replace the "new" template with the "old" template ([email protected] and ember-template-compiler 1.8.0) the application works like expected.

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

Option to compress templates

Can we get an option to compress the templates before they are stuffed into a string? This way, it gets rid of all the leading tabs/spaces leading up to the actual content. I realize some wouldn't want this feature, but I'm very interested in reducing our HTML footprint.

Throw grunt.fatal on old versions of grunt

Can we add a check and see if grunt.version >= 0.4.0rc5 and potentially throw an error if the version isn't compatible?

I've seen some experiences in the wild where people spent a lot of time looking for something wrong and eventually finding their grunt version was wrong.

TypeError: Object #<Object> has no method 'options'

Here's the error:

$ grunt
Running "qunit:files" (qunit) task
>> 0 assertions passed (0ms)

Running "ember_templates:default" (ember_templates) task

TypeError: Object #<Object> has no method 'options'
    at Object.module.exports (/Users/krainboltgreene/Code/ruby/absolvte/public/node_modules/grunt-ember-templates/tasks/ember_templates.js:25:24)
    at Object.task.registerMultiTask.thisTask (/usr/local/share/npm/lib/node_modules/grunt/lib/grunt/task.js:109:15)
    at Object.task.registerTask.thisTask.fn (/usr/local/share/npm/lib/node_modules/grunt/lib/grunt/task.js:58:16)
    at Task.<anonymous> (/usr/local/share/npm/lib/node_modules/grunt/lib/util/task.js:343:36)
    at Task.<anonymous> (/usr/local/share/npm/lib/node_modules/grunt/lib/util/task.js:319:9)
    at Task.<anonymous> (/usr/local/share/npm/lib/node_modules/grunt/lib/util/task.js:346:11)
    at Task.<anonymous> (/usr/local/share/npm/lib/node_modules/grunt/lib/util/task.js:319:9)
    at module.exports.grunt.registerHelper.grunt.utils.spawn.cmd (/usr/local/share/npm/lib/node_modules/grunt/tasks/qunit.js:223:7)
    at Object.async.forEachSeries (/usr/local/share/npm/lib/node_modules/grunt/node_modules/async/lib/async.js:104:20)
    at Object.module.exports.grunt.registerHelper.grunt.utils.spawn.cmd (/usr/local/share/npm/lib/node_modules/grunt/tasks/qunit.js:130:23)

Here's my grunt.js file:

/*global module:false*/
module.exports = function(grunt) {
  // Project Options
  var metadata = {
    version: '1.0.0',
    namespacing: 'var Application = Ember.Application.create();',
    banner: '/*! Absolvte Client - v<%= meta.version %> - ' +
      '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
      '* https://absolvte-client.github.com/\n' +
      '* Copyright (c) <%= grunt.template.today("yyyy") %> ' +
      'Kurtis Rainbolt-Greene; Licensed MIT */'
  }

  var templates_options = {
    'default': {
      options: {
        templateName: function(sourceFile) {
          return sourceFile.replace(/application\/templates\//, '');
        }
      },
      files: {
        "build/templates.js": ["application/templates/**/*.handlebars"]
      }
    }
  }

  var concat_options = {
    styles: {
      src: [
        'styles/vendor/bootstrap.css',
        'styles/vendor/bootstrap-responsive.css',
        'styles/vendor/fontawesome.css',
        'styles/styles.css'
      ],
      dest: 'styles.min.css'
    },
    scripts: {
      src: [
        'scripts/vendor/bootstrap.js',
        'scripts/vendor/modernizr.js',
        'scripts/scripts.js'
      ],
      dest: 'build/scripts.js'
    },
    libraries: {
      src: [
        'application/libraries/jquery.js',
        'application/libraries/sugar.js',
        'application/libraries/handlebars.js',
        'application/libraries/ember.js',
        'application/libraries/ember-data.js'
      ],
      dest: 'build/libraries.js'
    },
    application: {
      src: [
        'application/models/model.js',
        'application/models/**/*.js',
        'application/controllers/controller.js',
        'application/controllers/**/*.js',
        'application/views/view.js',
        'application/views/**/*.js',
        'application/routers/router.js',
        'application/routers/**/*.js',
        'application/application.js'
      ],
      dest: 'build/application.js'
    }
  }

  var minify_options = {
    application: {
      src: [
        '<banner:meta.banner>',
        '<config:concat.libraries.dest>',
        '<banner:meta.namespacing>',
        'build/templates.js',
        '<config:concat.application.dest>'
      ],
      dest: 'application.min.js'
    },
    scripts: {
      src: [
        '<banner:meta.banner>',
        '<config:concat.scripts.dest>'
      ],
      dest: 'scripts.min.js'
    }
  }

  var jshint_options = {
    options: {
      curly: true,
      eqeqeq: true,
      immed: true,
      latedef: true,
      newcap: true,
      noarg: true,
      sub: true,
      undef: true,
      boss: true,
      eqnull: true,
      browser: true
    },
    globals: {
      jQuery: true
    }
  }

  // Project configuration.
  grunt.initConfig({
    meta: metadata,
    lint: { files: ['grunt.js'] },
    qunit: { files: ['test/**/*.html'] },
    ember_templates: templates_options,
    concat: concat_options,
    min: minify_options,
    watch: {
      files: ['<config:concat.application.src>'],
      tasks: ['concat:application']
    },
    jshint: jshint_options
  });

  // Extra tasks.
  grunt.loadNpmTasks('grunt-ember-templates');

  // Default task.
  grunt.registerTask('default', 'qunit ember_templates concat min');

};

writing component templates within components subfolder causes error

We are relying heavily on ember components. Initially we had all our hbs templates associated with components written within "templates/components" folder, but since the number of components are growing we wanted to give more structure and define the templates within subfolder within components folder. When doing so, ember complains

You are looking for a [XYZ] component in the [SUBFOLDER] namespace, but the namespace could not be found

My compiled template looks like:

Ember.TEMPLATES["components/answers/checkbox-answer"] = ...

But things work if I were to make following change :

Ember.TEMPLATES["components/checkbox-answer"] = ...

The work around I have now is to modify gruntfile like this

 emberTemplates: {
        options: {
            templateName: function(sourceFile) {
                var fileName = sourceFile.replace(/.*\/templates\//, '');

                if((/^components\//).test(fileName)){
                    /*if component hbs files are defined within sub-folder, remove the subfolder part*/
                    return "components"+fileName.substr(fileName.lastIndexOf('/'));
                }
                return sourceFile.replace(/.*\/templates\//, '');
            }
        }

I am not sure if this is an ember thing or something else. But putting the question out there hoping for some better solution.

UPDATE
It seems like the problem is caused because of the way we were loading components. We are basically using helper function that loads the component based on parameter we pass to it like :

Ember.Handlebars.helpers[componentToLoad].call(this, options);

I checked the Ember.Handlebars.helpers and it doesn't seem to have components that were defined within any folder within component(but only those defined in components folder).

grunt-contrib-lib

FYI: we're changing the name of grunt-contrib-lib to grunt-lib-contrib. Please update your deps!

Handlebars 1.0.0

Hi Dan, is there a reason you're holding off Handlebars 1.0.0?

I'd like to upgrade to 1.0.0 but ember-templates is forcing the use of COMPILER_REVISION 3.

Thanks!

Generating templates as "[object Object]".

I'm getting this result when compiling templates:

define(["ember"], function(Ember){

Ember.TEMPLATES["application"] = Ember.Handlebars.template([object Object]);

// ...

My grunt config looks something like this:

emberTemplates: {
  compile: {
    options: {
      amd: true,
      templateBasePath: PATH_SOURCE_HBS
    },
    files: [ {
      src: [ PATH_SOURCE_HBS + '**/*.hbs'],
      dest: PATH_SOURCE_JS_APP + 'templates.js'
    } ]
  }
}

It's only started recently, but nothing has changed in my configuration.

templateBasePath requires closing slash

In case someone runs into the same issue, my templates weren't compiling as I didn't have an ending / in my path. Not sure if this is the way it's supposed to be or an issue. Feel free to close.

works:

templateBasePath: '<%= yeoman.app %>/scripts/templates/'

does not work:

templateBasePath: '<%= yeoman.app %>/scripts/templates'

grunt-ember

Do you want the grunt-ember name? grunt-ember is not really maintained and I'd be happy to give it away

False alarm

Update: for some reason NPM update was not working, I had to uninstall then re-install and it worked. If I could delete this I would. Sorry for jumping the gun.
. . .
Just updated to the latest release of ember/handlebars and loaded my app and got this error:

"Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version (>= 1.0.0) or downgrade your runtime to an older version (== 1.0.0-rc.4). "

However in looking at the repo here and handlebars.js it seems it has been updated so perhaps NPM is not finding the latest version?

Ember-template-compiler version conflict

When upgrading my Ember instance to 1.9.1 which I run within Yeoman, I noticed that the ember-template-compiler is on version 1.8.0 while grunt-ember-templates' package.json expects 1.9.0-alpha, e.g.:

"devDependencies": {
    ...
    "ember-template-compiler": "~1.9.0-alpha"
  },

I don't know why the compiler went from 1.9 to 1.8, but my npm installer doesn't like the conflict.

Bryan

version problem

Do not use ~v0.4.10 as it has handlebars 1.0.0 which is not compatible with the present version of ember ( rc-6 ) and gives an error.

For now ~0.4.9 is the right version.

Errors don't show where they are occurring

Hello. I'm running into an error when compiling my templates and it doesn't provide any useful information as to where the error is occurring.

Warning: Running "emberTemplates:dist" (emberTemplates) task
    >> Error: if doesn't match each
    Warning: Ember Handlebars failed to compile ... Use --force to continue.

It would be nice if it told me what line is causing this error. I've manually searched my template and it appears all of my if/else/each match each other (other colleagues have confirmed too).

templates/output array is not flushing the previous compiled templates

I specify multiple files in the task... while compiling and merging the templates... it doesn't flushes out the previous compiled templates from the 'templates' and 'output' array.

E.g.

ember_templates: {
compile: {
options: {
templateName: function(sourceFile) {
return sourceFile.replace(/path/to//, '');
}
},
files: {
"path/to/result.js": "path/to/source.handlebars",
"path/to/another.js": ["path/to/sources/.handlebars", "path/to/more/.handlebars"]
}
}
}

In this case... I get two files created result.js and another.js, which is correct... the issue is in another.js, it consists of the compiled templates from previous path (result.js = sources.handlebars) + ["path/to/sources/.handlebars", "path/to/more/.handlebars"]... ideally it should contains the compiled templates of only ["path/to/sources/.handlebars", "path/to/more/.handlebars"].

Please fix this.

Support "grunt.file.expandMapping"

I tried this

ember_templates:
   files: grunt.file.expandMapping(["**/*.tmpl"], "public/",
     cwd: "app/"
     rename: (destBase, destPath) -> destBase + (destPath.replace /\.tmpl$/, ".tmpl.js")
   )

which results in

Warning: Object #<Object> has no method 'indexOf' Use --force to continue.

Is there another way to specify a whole directory to be converted recursively, each file individually?

Uncaught TypeError: Object #<Object> has no method 'merge'

this.merge does not exist in the compiled template closures.

Ember.TEMPLATES["application"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
  var buffer = '', stack1, hashTypes, hashContexts, options, helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;


  data.buffer.push("<div class=\"application\">\n   <div class=\"content\">\n       ");
  hashTypes = {};
  hashContexts = {};
  options = {hash:{},contexts:[depth0],types:["ID"],hashContexts:hashContexts,hashTypes:hashTypes,data:data};
  data.buffer.push(escapeExpression(((stack1 = helpers.outlet || depth0.outlet),stack1 ? stack1.call(depth0, "content", options) : helperMissing.call(depth0, "outlet", "content", options))));
  data.buffer.push("\n  </div>\n</div>");
  return buffer;

});

ember-template-compiler dependency targets alpha version

Currently ember-template-compiler has released version 1.9.0-alpha which has handlebars 2.0.0 as dependency. This is causing errors when running grunt-ember-templates, because it has a dependency >= 1 on ember-template-compiler which will pick up the alpha version.

Maybe it's better to change the dependency on ember-template-compiler in package.json to a stable version instead of latest.

Support for linkToAnimated or link-to-animated

Disclaimer: I'm new to Ember.js

First off. Thank you. Grunt-ember-templates is great.

I'm using grunt-ember-templates on a phonegap/cordova project, where animated transitions are a must. I just tried to use https://github.com/billysbilling/ember-animated-outlet (while it is appears to use the older linkTo rather than link-to which should be getting updated soon). But during the template compilation phase, I receive an error:

Error: linkToAnimated doesn't match link-to

Would it be possible to either 1) all compilation with a linkToAnimated or better 2) pass an options hash with a custom link-to name?

Error code: ENOENT with pattern matching

Hey
(I am using yeoman 0.9.6 and grunt-ember-templates 0.4.1)

I have two templates in my app/scripts/templates. Now, when I specify files like

    ember_templates: {
      compile: {
        options: {
          templateName: function(sourceFile) {
            return sourceFile.replace(/app\/scripts\/templates\//, '');
          }
        },
        files: {
          'app/scripts/templates.js': ["app/scripts/templates/**/*.hbs"]
        }
      }
    }

I am getting this error

Error: Unable to read "app/scripts/templates/**/*.hbs" file (Error code: ENOENT).
<WARN> Ember Handlebars failed to compile app/scripts/templates/**/*.hbs. Use --force to continue. </WARN>

however, when I manually specify the files, like below, everything works out fine.

    ember_templates: {
      compile: {
        options: {
          templateName: function(sourceFile) {
            return sourceFile.replace(/app\/scripts\/templates\//, '');
          }
        },
        files: {
          'app/scripts/templates.js': ["app/scripts/templates/application.hbs",
          "app/scripts/templates/header.hbs"]
        }
      }
    }

any ideas?

TypeError: Object #<Object> has no method 'options'

➜  grunt ember_templates      
path.existsSync is now called `fs.existsSync`.
Running "ember_templates:compile" (ember_templates) task

TypeError: Object #<Object> has no method 'options'
    at Object.module.exports (/home/test/projects/test/node_modules/grunt-ember-templates/tasks/ember_templates.js:23:24)
    at Object.task.registerMultiTask.task._tasks.(anonymous function).multi (/usr/lib/node_modules/grunt/lib/grunt/task.js:103:15)
➜ npm list grunt-cli -g  
/usr/local/lib
└── [email protected] 
➜  node -v                    
v0.8.16
➜  npm -v
1.1.69
➜  npm list
└── [email protected]

Add an option to print the output in AMD style

Original Handlebars supports AMD style output using --amd or -a options used like:

handlebars -a -m -e hb ./js/photos > ./js/photos/templates.js

Since my entire application is based on Require.js, I need AMD compliant compiled templates.

All that is required is to wrap the current output with:

define(["Ember"],function(Ember){
    // Current output goes here.
});

I think it should be fairly simple to add this feature. Please let me know if it has already been added.

Considering renaming task `emberTemplates`

In order to be more consistent with other grunt plugins, I'm considering renaming the grunt task for this project from ember_templates to emberTemplates.

One of the issues I'm struggling with is whether to bump the minor version from 0.4 to 0.5 along with this change. Obviously, this would be a breaking change. However, I'm reticent to move to 0.5, considering that this plugin is compatible with grunt ~0.4, and most other grunt plugins are keeping pace with the same minor version.

Thoughts?

grunt-este-watch compatibility

grunt-contrib-watch is a bit slow and when compared to grunt-este-watch it is really slow. I got other grunt-contrib-* scripts working but I couldn't get grunt-ember-templates to work. It might be configuration issue but I tried and I failed. Could someone kindly have a look and advise on how to get it working ... thanks

"helpers" is undefiened

I get an error when launching the app coming from EMBER.TEMPLATES['index']

TypeError: 'undefined' is not a function (evaluating 'this.merge(helpers, Ember.Handlebars.helpers)')

I am running handlebars-1.0.0-rc.4 and ember-1.0.0-rc.6

Any idea what is happening ?

Plugin setup

i have a structure
-login
---login.hbs
-users
---users.hbs
---create.hbs

With default settings if templates are generate i see template names
login/login
users/users
users/create

I need "login/login" to be "login" only
"users/users" to be "users"

I tried different variations without any luck - can you suggest how task should looks like.

grunt-contrib naming

Nice work on this one :)

grunt-contrib is a collection of officially supported grunt plugins, by using the contrib name you're making users believe that is the fact.

I would like to see this either be accepted as an official contrib plugin and moved to the gruntjs org or renamed to something else than grunt-contrib-*.

@tkellen Thoughts?

Version 0.2.0 concatenates all source files

I've got a config that looks like this:

ember_templates: {
    compile: {
        options: {
            templateName: function(sourceFile) {
                return sourceFile.replace(/src\/Lararjouren\/[a-z]+\/Resources\/templates\//i, '');
            }
        },
        files: {
            "src/Lararjouren/ArticleBundle/Resources/public/js/templates.js": "src/Lararjouren/ArticleBundle/Resources/templates/*.hbs",
            "src/Lararjouren/UserBundle/Resources/public/js/templates.js": "src/Lararjouren/UserBundle/Resources/templates/*.hbs"
        }
    }
}

When templates.js in UserBundle is created (the second entry in files hash) it contains all the templates from both bundles. Is this by design or a bug?

Is there any way to compile just the matching .hbs files into a template.js file?

Task errors

As per documentation, value in key-value object map for files within the compile configuration, is supposed to accept minimatch.

Current results:
Input:

files: {
          'app/scripts/templates.js': 'app/scripts/**/*.handlebars'
        }

Output:

$ yeoman ember_templates
Running "ember_templates:compile" (ember_templates) task
<WARN> Object app/scripts/**/*.handlebars has no method 'forEach' Use --force to continue. </WARN>

And for input:

files: {
          'app/scripts/templates.js': ['app/scripts/**/*.handlebars']
        }

It outputs:

$ yeoman ember_templates
Running "ember_templates:compile" (ember_templates) task
>> Error: Unable to read "app/scripts/**/*.handlebars" file (Error code: ENOENT).
<WARN> Ember Handlebars failed to compile app/scripts/**/*.handlebars. Use --force to continue. </WARN>

What configuration should I use to convert all my *.handlebars to template.js single file?

EDIT: I've tried using the exact same code at Gruntfile.js at https://github.com/dgeb/yeoman-ember-basic-example with no success, same error.

Handlebars 2.0.0

Is there any progress on the alpha version? I'm still using this grunt lib to render my templates for a non-cli ember project, i'd like to know if this lib keeps available.

EDIT: I should have asked this question to the ember-template-compiler project I guess...

Window not defined

Hi,

I'm trying to pre-compile my templates in Grunt with your module. It works perfectly on Ember 1.9 but now we want to upgrade to the latest version of Ember. That's why I tried to use your module as described with the ember-template-compiler.js from downloaded from here.

This is how the task is setup:

module.exports = function (grunt) {
    grunt.initConfig({
        emberTemplates: {
            'default': {
                options: {
                    templateName: function (sourceFile) {
                        return sourceFile.replace('Views/Handlebars/', '').replace('.hbs', '');
                    },
                    templateCompilerPath: 'JS/libs/ember-template-compiler.js',
                    templateNamespace: 'HTMLBars',
                    handlebarsPath: 'JS/libs/handlebars-v3.0.1.js'
                },
                files: {
                    'JS/Templates.js': ['Views/Handlebars/*.hbs']
                }
            }
        }
    });

    //Load the Ember template compiler
    grunt.loadNpmTasks('grunt-ember-templates');

    //Register default grunt task
    grunt.registerTask('default', ['emberTemplates']);
};

But when I execute Grunt then this error occurs:

Running "emberTemplates:default" (emberTemplates) task
>> ReferenceError: window is not defined
Warning: Ember Handlebars failed to compile Views/Handlebars/addtrack.hbs. Use --force to continue.

Aborted due to warnings.

Doesn't do anything

Hi! Great, you published that one just in time for me, thanks!

Unfortunately for me it doesn't do anything. I took all the relevant parts from you example project. No error, but also nothing happens. Any hint how I can debug?

Add "each" to known helpers?

Just wondering: I'm using each a lot and I've seen in /lib/ember-template-compiler.js that it is not inside the knownHelpers:

  var options = {
    knownHelpers: {
      action: true,
      unbound: true,
      bindAttr: true,
      template: true,
      view: true,
      _triageMustache: true
    },
    data: true,
    stringParams: true
  };

Could it be that it could improve the performance of my application?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.