npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-template-generator

v1.1.1

Published

generate file template

Downloads

3

Readme

Grunt-template-generator

npm version

Grunt task that help generate template files (angular, nodejs, backbone, java...)

Prerequisites

This project has a dependencie that require Grunt to be installed. For help to install Grunt, go to:

http://gruntjs.com/installing-grunt

Table of Contents

Installation

BEFORE YOU INSTALL: please read the prerequisites

npm install grunt-template-generator

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

grunt.loadNpmTasks('grunt-template-generator');

Overview

 grunt.initConfig({
        generate: {
            options: {
                showPrompt: true,
                includeTest: true,
                wrapInFolder: true,
                templatePathRoot: "modules",
                dest: {
                    // The destination where the files will be stored. 
                    'common': 'modules/common/app/components',
                    'signup': 'modules/signup/app/components',
                    'reporting': 'modules/reporting/app/components',
                    'payments': 'modules/payments/app/components',
                    'backend': '../../src/main/java/com/api/resources/v1'
                },
                acronyms: {
                    // Acronyms are used to prefix a component name
                    'common': 'cn',
                    'signup': 'su',
                    'reporting': 'rp',
                    'payments': 'pm'
                }
            }
        }
    });

Usage

grunt generate:module:component:name

Options

Scaffold | Type | Usage --- |--- | --- showPrompt | boolean | Show a prompt confirmation message before creating files. Default set to true. includeTest | boolean | Will generate unit test. Defaut set to true. wrapInFolder | boolean | The generated files will wrap inside a folder. Default set to true. templatePathRoot | string | Set file template path root. e.g (modules/reporting/components/app), the path should start from reporting/.. dest | object | The destination where the files will be stored. acronyms | object | Acronyms are used to prefix a component name [ac]Name e.g (rpTimeLine) where rp stand for reporting. customTemplatesUrl | object | Specify the directory for custom templates

Templating

The grunt task, comes with some predefined templates such as angular directives, etc ... But you can also custom your own templates using the customTemplatesUrl option.

Meta data

The meta data helps customize your templates, here are some options:

Name | Description
--- |---
name | The fullname including the componentName and the componentType. E.g (productDirective) componentName | The component name. E.g (product) componentType | The component type. E.g (directive) nameWithAcronym | The fullname including the acronym is speficied. E.g (rpProductDirective) dasherizedName | The fullname seperated with dashes. E.g "rpProductDirective" will become "rp-product-directive". Usefull for calling directives in angular for example. acronym | If specified will return the acronym otherwise this will be empty templatePathRoot | The absolute path of the file

Example

For the example, lets use the following custom template for an angular directive:

/**
 * @ngdoc directive
 * @name <%= meta.acronym %>Directives.directive:<%= meta.nameWithAcronym %>
 * @description
 * @restrict EA
 * @scope true
 * @requires
 * @param {object} options Configuration options for the directive
 */

angular.module('<%= meta.acronym %>Directives').directive('<%= meta.nameWithAcronym %>', [function () {
  return {
    restrict: "EA",
    replace: true,
    scope: {
      options: '='
    },
    templateUrl: "<%= meta.templatePathRoot %>/<%= meta.name %>.tpl.html",
    controller: function ($scope) {
      /***************************************************
       * Exposed for testing
       ***************************************************/

      /***************************************************
       * Scope variables, functions
       ***************************************************/

      /***************************************************
       * Private variables, functions
       ***************************************************/
    }
  };
}]);

Now that we got our template defined lets run the grunt task:

grunt generate:common:directive:product

This will generate the following template:

/**
 * @ngdoc directive
 * @name cnDirectives.directive:cnProduct
 * @description
 * @restrict EA
 * @scope true
 * @requires
 * @param {object} options Configuration options for the directive
 */

angular.module('cnDirectives').directive('cnProduct', [function () {
  return {
    restrict: "EA",
    replace: true,
    scope: {
      options: '='
    },
    templateUrl: "common/productDirective/productDirective.tpl.html",
    controller: function ($scope) {
      /***************************************************
       * Exposed for testing
       ***************************************************/

      /***************************************************
       * Scope variables, functions
       ***************************************************/

      /***************************************************
       * Private variables, functions
       ***************************************************/
    }
  };
}]);

License

MIT