0.1.2 • Published 10 years ago

grunt-template-transformer v0.1.2

Weekly downloads
2
License
-
Repository
github
Last release
10 years ago

template-transformer

Module for Transforming JavaScript template to JSON Object

Getting Started

This plugin requires Grunt ~0.4.2

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-template-transformer --save-dev

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

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

The "template_transformer" task

Overview

In your project's Gruntfile, add a section named template_transformer to the data object passed into grunt.initConfig().

grunt.initConfig({
  template_transformer: {
    options: {
      // Task-specific options go here.
      }
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Options

options.assign.variable

Type: String

A string specifying variable name to be assigned

options.assign.object

Type: String

A string specifying object name to be assigned.

Usage Examples

Custom Options

grunt.initConfig({
  template_transformer: {
    options: {
        assign : {
            variable : "TemplateJSON",        // specify variable name to be assigned.
            object : "foo.com.TemplateJSON"   // specify object name to be assigned.
        }
    },
    files: {
      'template-context.js': ["test/resources/template.html"]
    },
  },
});

'test/resources/template.html'

<!DOCTYPE html>
<html>
<head>
    <title>Template for test</title>
</head>
<body>

<script type="text/template" id="test1">
    <div></div>
</script>

<script type="text/template" id="test2">
    <a></a>
</script>

</body>
</html>

When this example task is executed, it will transform HTML file into js on the below.

'template-context.js'

var foo = foo || {};
foo.com = foo.com || {};

var TemplateJSON = foo.com.TemplateJSON = {"test1":"<script type=\"text/template\" id=\"test1\">\n    <div></div>\n</script>","test2":"<script type=\"text/template\" id=\"test2\">\n    <a></a>\n</script>"}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

(Nothing yet)

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago