<%
// setup few constant

directive = _.camelize(tagName);
controller = _.camelize('-'+tagName) + 'Controller';

if (require.length) {
	inject = _.union(inject, ['$element']);
}

hasLink = classes.length || _.size(attributes);
hasScope = _.size(scope);

dirInject = [];
if (style) {
	dirInject.push('$document');
}

%>
/*
	<%= '<' + tagName %><% _.forEach(scope, function(attr,scope) { %>
			<%= scope %>="<%= attr %>..."
			<% }); %><%= '></' + tagName + '>' %>

	Controller <%= controller %> as <%= directive %>

*/
(function(angular) {
	'use strict';

	angular
		.module('<%= moduleName %>')
		.directive('<%= directive %>', <%= directive %>);

	<%= directive %>.$inject = [<%= dirInject.map(function(i){return '\''+i+'\'';}).join(',') %>];
	function <%= directive %>  (<%= dirInject.map(function(i){return '\ '+i+'\ ';}).join(',') %>) {
		var directive = {
			bindToController: true,
			controller: <%= controller %>,
			controllerAs: '<%= directive %>',
			<% if (hasLink) { %>
			link: link,
			<% } %>
			<% if (require) { %>
			require: <%= json(require) %>,
			<% } %>
			restrict: <%= json(restrict) %>,
			<% if (hasScope) { %>
			scope: {
			<% _.forEach(scope, function(attr, scope) { %>
				<%= scope %>: <%= json(attr) %>,
			<% }) %>
			},
			<% } %>
			<% if (template) { %>
			template: <%= json(template) %>,
			<% } %>
			<% if (transclude) { %>
			transclude: <%= json(transclude) %>,
			<% } %>
		};

		<% if (style) { %>
		// register style for this component
		$document.find('head').append('<style><%= json(style).slice(1,-1) %></style>');
		<% } %>

		<% if (hasLink) { %>
		function link(scope, element) {
			<% if (classes) { %>
			element.addClass(<%= json(classes) %>);
			<% } %>
			<% if (_.size(attributes)) { _.forEach(attributes, function(value,attr) { %>
			if (angular.isUndefined(element.attr(<%= json(attr) %>)) { element.attr(<%= json(attr) %>,<%= json(value) %>); }
			<% }); } %>
		}
		<% } %>

		return directive;
	}

	<%= controller %>.$inject = [<%= inject.map(function(i){return '\''+i+'\'';}).join(',') %>];
	function <%= controller %>  (<%= inject.map(function(i){return '\ '+i+'\ ';}).join(',') %>) {
		<% if (require) require.match(/(\w+)/g).forEach(function(ctrl) { %>
		var <%= ctrl %> = $element.controller('<%= ctrl %>');
		<% }); %>
		<%= script %>
	}


})(angular);


@@ -311,17 +311,16 @@
 );%0A%7D%0A%0A%25%3E
-%0A
 /*%0A%09%3C%25= 
@@ -2313,10 +2313,8 @@
 ngular);
-%0A%0A

remove nasty spaces from generated files