Created
April 14, 2016 16:23
-
-
Save olostan/d621ccc0a8d45784d1be2bddc9b15afd to your computer and use it in GitHub Desktop.
Converts from Directive Definition to Directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<textarea id="a" cols=80 rows=20>@directiveDefinition("viewControlPanel", []) | |
export class ControlPanelView implements ng.IDirective { | |
restrict = 'E'; | |
template = controlPanelViewTemplate; | |
bindToController = { activity: '=' }; | |
controller = controlPanelViewController; | |
controllerAs = "ctrl"; | |
require = { payload: "^uifDataPayload" }; | |
scope = true; | |
} | |
</textarea> | |
<button id="c" >Convert</button> | |
<textarea id="b" cols=80 rows=20></textarea> | |
<script> | |
function converter(m,dir,param) { | |
param = param.replace(/;/g,','); | |
param = param.replace(/\s+=\s+/g,' : '); | |
param = param.replace(/\s*controller\s*:\s*\w+\s*,/g,''); | |
console.log(param); | |
return `@directive(${dir},${param})`; | |
} | |
document.getElementById('c').addEventListener('click', function() { | |
let text = document.getElementById('a').value; | |
text = text.replace(/@directiveDefinition\((.*?)(?:,\s*\[\])?\)[\s\S]*export class \w+ implements (?:angular|ng)\.IDirective([\s\S]*?})[\s]*$/mg,converter); | |
document.getElementById('b').value = text; | |
}); | |
document.getElementById('c').click(); | |
</script> | |
<body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment