From 7fb34523aefd88acf8502a510893f0c477d7119b Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Sun, 29 Nov 2015 21:39:02 +0000 Subject: [PATCH] chore(docs-app): add `code` directive to prevent unwanted compilation --- public/_includes/_scripts-include.jade | 1 + public/docs/ts/latest/guide/cheatsheet.jade | 2 +- public/resources/js/directives/code.js | 23 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 public/resources/js/directives/code.js diff --git a/public/_includes/_scripts-include.jade b/public/_includes/_scripts-include.jade index e32fe80975..647214a014 100644 --- a/public/_includes/_scripts-include.jade +++ b/public/_includes/_scripts-include.jade @@ -17,6 +17,7 @@ script(src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular script(src="/resources/js/site.js") script(src="/resources/js/controllers/app-controller.js") script(src="/resources/js/directives/bio.js") +script(src="/resources/js/directives/code.js") script(src="/resources/js/directives/code-tabs.js") script(src="/resources/js/directives/code-pane.js") script(src="/resources/js/directives/code-example.js") diff --git a/public/docs/ts/latest/guide/cheatsheet.jade b/public/docs/ts/latest/guide/cheatsheet.jade index e171a2dd2f..3db12ade7d 100644 --- a/public/docs/ts/latest/guide/cheatsheet.jade +++ b/public/docs/ts/latest/guide/cheatsheet.jade @@ -22,5 +22,5 @@ article(class="l-content-small grid-fluid docs-content") th(ng-bind-html="appCtrl.getSafeHtml(section.description)") tr(ng-repeat='child in section.items') td - code(bold='child.bold') {{child.syntax}} + code(bold='child.bold',ng-compile) {{child.syntax}} td(ng-bind-html="appCtrl.getSafeHtml(child.description)") diff --git a/public/resources/js/directives/code.js b/public/resources/js/directives/code.js new file mode 100644 index 0000000000..fe7991e61b --- /dev/null +++ b/public/resources/js/directives/code.js @@ -0,0 +1,23 @@ +/* +* Code Directive +* Don't compile the contents of `` elements. +* This allows examples to contain angular syntax. +* +* But DO compile if the element also contains the `ng-compile` attribute +* E.g. `{{ 'do interpolate' + 'me' }}` +*/ + +angularIO.directive('code', function($compile) { + return { + priority: 100, + restrict: 'E', + terminal: true, + link: function($scope, $element, $attrs) { + // If the element contains the `ng-compile` attribute then + // go ahead and compile anyway + if ($attrs.ngCompile) { + $compile($element, null, 100, 'code')($scope); + } + } + }; +}); \ No newline at end of file