Skip to content

Instantly share code, notes, and snippets.

@brandonhesse
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonhesse/c2edf315aeedd5e53f88 to your computer and use it in GitHub Desktop.
Save brandonhesse/c2edf315aeedd5e53f88 to your computer and use it in GitHub Desktop.
(function(ng, undefined) {
ng.module('sm.directive')
.factory('es6Macro', [function es6Macro() {
// ECMAScript6 style string replacement implemented in ES5
return function macro(replace, macroString) {
var compiled = macroString,
keyR = Object.keys(replace),
replacementR = keyR.map(function (key) {
return new RegExp('\\${' + key + '}', 'g');
}), keyIdx, replacementCnt = replacementR.length;
for (keyIdx = 0; keyIdx < replacementCnt; keyIdx += 1) {
compiled = compiled.replace(replacementR[keyIdx], replace[keyR[keyIdx]]);
}
return compiled;
};
}])
.directive('smCheckboxes', ['$templateCache', '$parse', function($tplCache, $parse) {
function postLink(scope, elm, attr, ctrls) {
}
return {
restrict: 'EA',
require: 'ngModel',
template: function (elem, attr) {
// Build the template via a macro method
return es6Macro(
{
},
$tplCache('template.html');
);
},
link: postLink
};
}]);
})(angular);
<label data-ng-repeat="${repeatClause}" class="control-label col-sm-12" data-ng-style="checkbox.style.label">
<input name="${section}[]" class="form-control" data-ng-class="checkbox.style.input"
type="checkbox" data-ng-model="${model}" value="${name}"/><span
data-translate="${translate}"></span>
</label>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment