Skip to content

Commit

Permalink
Fixed #4: added support for template overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
grtjn committed Nov 29, 2016
1 parent dcc3c0d commit 20d9d0b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
21 changes: 17 additions & 4 deletions src/friendly-json.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
* @description
* Angular directive for rendering nested JSON structures in a user-friendly way.
*
* @attr {String} uri Optional. Url of JSON file to be rendered. Url must be trusted upfront.
* @attr {String} json Optional. JSON contents to be rendered. Do not use together with uri.
* @attr {String} template Optional. Url of HTML template to use for this directive.
* @attr {String} uri Optional. Url of JSON file to be rendered. Url must be trusted upfront.
*
* @example
* <friendly-json uri="ctrl.viewUri"></friendly-json>
* <friendly-json uri="ctrl.viewUri" template="/my/json-template.html"></friendly-json>
*
* or
*
* <friendly-json json="ctrl.json"></friendly-json>
* <friendly-json json="ctrl.json" template="/my/json-template.html"></friendly-json>
*/

(function () {
Expand Down Expand Up @@ -49,7 +50,7 @@
uri: '=?',
json: '=?'
},
templateUrl: '/view-file-ng/friendly-json.html',
templateUrl: template,
compile: function(element) {
// Use the compile function from the RecursionHelper,
// And return the linking function(s) which it returns
Expand All @@ -64,6 +65,18 @@
});
}
};

function template(element, attrs) {
var url;

if (attrs.template) {
url = attrs.template;
} else {
url = '/view-file-ng/friendly-json.html';
}

return url;
}
}

}());
19 changes: 16 additions & 3 deletions src/friendly-xml.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
* @description
* Angular directive for rendering nested JSON structures in a user-friendly way.
*
* @attr {String} template Optional. Url of HTML template to use for this directive.
* @attr {String} uri Optional. Url of XML file to be rendered. Url must be trusted upfront.
* @attr {String} xml Optional. XML contents to be rendered. Do not use together with uri.
*
* @example
* <friendly-xml uri="ctrl.viewUri"></friendly-xml>
* <friendly-xml uri="ctrl.viewUri" template="/my/xml-template.html"></friendly-xml>
*
* or
*
* <friendly-xml xml="ctrl.xml"></friendly-xml>
* <friendly-xml xml="ctrl.xml" template="/my/xml-template.html"></friendly-xml>
*/

(function () {
Expand All @@ -34,7 +35,7 @@
uri: '=?',
xml: '=?'
},
templateUrl: '/view-file-ng/friendly-json.html',
templateUrl: template,
compile: function(element) {
// Use the compile function from the RecursionHelper,
// And return the linking function(s) which it returns
Expand All @@ -55,6 +56,18 @@
});
}
};

function template(element, attrs) {
var url;

if (attrs.template) {
url = attrs.template;
} else {
url = '/view-file-ng/friendly-json.html';
}

return url;
}
}

}());

0 comments on commit 20d9d0b

Please sign in to comment.