chore(docs-app): add `code` directive to prevent unwanted compilation

This commit is contained in:
Peter Bacon Darwin 2015-11-29 21:39:02 +00:00 committed by Naomi Black
parent e00b024e95
commit 7fb34523ae
3 changed files with 25 additions and 1 deletions

View File

@ -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")

View File

@ -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)")

View File

@ -0,0 +1,23 @@
/*
* Code Directive
* Don't compile the contents of `<code>` elements.
* This allows examples to contain angular syntax.
*
* But DO compile if the element also contains the `ng-compile` attribute
* E.g. `<code ng-compile>{{ 'do interpolate' + 'me' }}</code>`
*/
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);
}
}
};
});