Search code examples
yeomanyeoman-generator

Create JS files dynamically with Yeoman


I'm trying to make a Yeoman generator to easily create controller files for Angular with this EXACT template, problem is I can't figure out how to create it with the function name dynamically, like: myangularjs:controller main (main as function name). Is this even possible?

Thanks

   (function() {
     "use strict";

     function Config($routeProvider) {
         $routeProvider.when("", {
         controller: "<%= name %>",
         templateUrl: "",
         resolve: "<%= name %>".resolve
     });
     }

     function <%= name %>Ctrl() {

     }

     <%= name %>Ctrl.resolve = {};

     angular.module("App.Overview")
            .controller("'<%= name %>'Ctrl", [<%= name %>Ctrl])
            .config(["$routeProvider", Config]);
    })();

Solution

  • Have a look at the angular generator, short answer for you is YES.

    Here's how it will look like

    angular.module('<%= scriptAppName %>')
      .controller('<%= classedName %>Ctrl', function ($scope) {
        $scope.awesomeThings = [
          'HTML5 Boilerplate',
          'AngularJS',
          'Karma'
        ];
      });
    

    And have a look at the 'Sub Generators' section here