2015-05-02 18:34:16 -04:00
|
|
|
/*
|
|
|
|
* Code Example Directive
|
|
|
|
*
|
|
|
|
* Formats codes examples and prevents
|
|
|
|
* Angular code from being processed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
angularIO.directive('codeExample', function() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
|
2015-05-18 09:41:26 -04:00
|
|
|
compile: function(tElement, attrs) {
|
|
|
|
var html = (attrs.escape === "html") ? _.escape(tElement.html()) : tElement.html();
|
2015-06-03 06:24:26 -04:00
|
|
|
var classes = 'prettyprint ' + attrs.format + ' lang-' + attrs.language +
|
|
|
|
(attrs.showcase === 'true' ? ' is-showcase' : '');
|
2016-01-20 07:07:00 -05:00
|
|
|
var template =
|
|
|
|
'<copy-container>' +
|
|
|
|
'<pre class="' + classes + '">' +
|
|
|
|
'<code ng-non-bindable>' + html + '</code>' +
|
|
|
|
'</pre>' +
|
|
|
|
'</copy-container>';
|
2015-05-02 18:34:16 -04:00
|
|
|
|
2015-05-03 22:09:25 -04:00
|
|
|
// UPDATE ELEMENT WITH NEW TEMPLATE
|
|
|
|
tElement.html(template);
|
|
|
|
|
|
|
|
// RETURN ELEMENT
|
2015-05-18 09:41:26 -04:00
|
|
|
return function(scope, element, attrs) {};
|
2015-05-03 22:09:25 -04:00
|
|
|
}
|
2015-05-02 18:34:16 -04:00
|
|
|
};
|
2016-01-20 07:07:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// '<div style="position: relative">' +
|
|
|
|
// '<copy-button style="position: absolute; top: 10px; right: 0px; z-index: 1000" ></copy-button>' +
|
|
|
|
// '<pre class="' + classes + '">' +
|
|
|
|
// '<code ng-non-bindable>' + html + '</code>' +
|
|
|
|
// '</pre>' +
|
|
|
|
// '</div>';
|