Skip to content

timschlechter/angular-transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transform JSON to any text format Build Status

Features:

  • 1 function which transforms JSON to any text format
  • Use the full power of AngularJS (templates, directives, filters, services, controllers)
  • Extendable: easy to write your own plugins. Checkout the MS Word 2003 plugin which is currently used to test out these things
  • Very testable! Just use the testtools you allready know to write your Javascript tests

Why?

"Who likes writing XSLT, please raise hands?"
"...and who likes maintaining XSLT?"
"...and who likes testing XSLT?"

At this moment, there probably aren't that many raised hands left.XSLT is very powerfull, but writing, maintaining and testing it is pretty hard.

Wouldn't it be nice...

...if we could transform data using the simplicity and power of AngularJS? Think about it:

  • Nowadays most of our data is available in JSON, we loooove JSON
  • Javascript is gaining more and more popularity, it runs both in client browsers as standalone using NodeJS.
  • AngularJS offers enormous power, simplicity and testability
  • Binding JSON to a template is very easy when using AngularJS
  • Easy to extend by using your own directives, filter and controllers in templates

Why not trying to use all this stuff to transform JSON to... any text format?

Maybe we don't get the performance we can get using XSLT or the streaming capabilities, but I think for most use cases using AngularJS will be sufficient. And next to NodeJS and browsers, it shouldn't be that hard to make this useable in other environments like .Net or Java.

But first...

To avoid any confusion: this is not an AngularJS module. This library exposes a transform function, which internally bootstraps an AngularJS app. This app is used to perform the transformation.

This will look something like...

Well this is a fairly simple example, but you get the idea.

Data:

	var data = {
		company: "Some Company",
		employees: [
			{ name: 'Jack', age: '31'},
			{ name: 'Jill', age: '29'}
		]
	};

Template:

<?xml version="1.0" encoding="UTF-8"?>
<company>
	<name><at>{{company}}</at></name>
	<at ng-if="employees.length">
		<employees>
			<at ng-repeat="employee in employees | orderBy:'age'">
				<employee>
					<name age="{{age}}"><at>{{employee.name}}</at></name>
				</employee>
			</at>
		</employees>
	</at>
</company>

Transform:

var result = angularTransform({
    data: data,
    template: template
});

Result:

<?xml version="1.0" encoding="UTF-8"?>
<company>
	<name>Some Company</name>
	<employees>
		<employee>
			<name age="29">Jill</name>
		</employee>
		<employee>
			<name age="31">Jack</name>
		</employee>		
	</employees>
</company>

Run tests

npm install 
npm install -g bower
bower install
npm test

Dependencies

  • AngularJS

About

Transform JSON to any text format, using the power and simplicity of AngularJS. Note: this is *not* an AngularJS module (see README.md)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published