ericclemmons / grunt-angular-templates

Grunt build task to concatenate & pre-load your AngularJS templates
MIT License
710 stars 107 forks source link

module option #10

Closed geddski closed 11 years ago

geddski commented 11 years ago

What about this idea: instead of creating app.templates module, just let people specify the name of the module to add templates to:

ngtemplates: {
      app: {
        src: ['app/templates/**/*.html'],
        dest: 'app/templates.js',
        module: 'app'
      }
    },

That way you wouldn't have to specify a dependency:

angular.module('app', []);

The benefit of this is you don't have to run a build before being able to use your app.

ericclemmons commented 11 years ago

Hi! I don't know if I understand well enough, but I do know you can change app to whatever you'd like:

ngtemplates: {
  mymodule: {
    src: ['app/templates/**/*.html'],
    dest: 'mymodule/templates.js'
  }
},

This will create mymodule.templates. I can update the README if that helps.

As for the last line about "don't have to run a build", are you saying that you only want to use the templates as the app, without a "parent" module?

Thanks for opening an issue, btw!

geddski commented 11 years ago

Right, I get how it currently works. I mean instead of creating a new module named <module-name>.templates, the plugin could add the templates to the module.

So for example, say I have an angular module named app:

angular.module('app', []);

Now I tell the grunt plugin to add all my templates to it (rather than to a separate module):

ngtemplates: {
    app: {
        src: ['app/templates/**/*.html'],
        dest: 'app/templates.js',
        module: 'app'
      }
  }

And now app/templates.js would look like this:

angular.module("app").run(["$templateCache", function($templateCache) {

  $templateCache.put("app/templates/partial1.html",
    "<h1>Users</h1>"...
  );

  $templateCache.put("app/templates/partial2.html",
    "<p>This is the partial for view 2.</p>"...
  );

}]);

Does that make sense? So it adds the templates to my app module, rather than to a separate module that I need to declare as a dependency to my module.

ericclemmons commented 11 years ago

Ooh!! I see! I like that a lot better! :D

The one downside is that you'd have to ensure the template is included after the fact (whereas app.templates can be included before or after other module files), but I think that's a trivial downside.

kwhitley commented 11 years ago

I like this!

:+1: @geddesign

geddski commented 11 years ago

Wow that was fast! Rock on dudes. This is a great improvement.

ericclemmons commented 11 years ago

Thanks for the PR! Take a look @ some of my other grunt projects & open up issues if you see anything!