Skip to content

Commit

Permalink
feature: innerHtml templates will get rendered now
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyTheTank committed Jan 24, 2016
1 parent 6e6ee62 commit 6758ed5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apiNG",
"version": "1.0.4",
"version": "1.0.5",
"homepage": "https://github.com/JohnnyTheTank/apiNG",
"authors": [
"Jonathan Hornung <[email protected]>"
Expand Down
17 changes: 8 additions & 9 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,31 @@
<style>
body {
font-family: 'Source Sans Pro', sans-serif;
background:#0d3349;
color:white;
padding:10px;
background: #0d3349;
color: white;
padding: 10px;
}

a:link,
a:active,
a:visited {
color:yellow;
color: yellow;
}
</style>

</head>
<body ng-app="app">

<h1>Unstyled, one result</h1>
<aping
template-url="unstyled_template.html"
aping-jsonloader="[{ 'path': 'https://randomuser.me/api/' }]">
<aping aping-jsonloader="[{ 'path': 'https://randomuser.me/api/' }]">
<pre>{{results | json}}</pre>
</aping>

<hr>
<h1>Styled, but two results</h1>
<aping
template-url="template.html"
aping-jsonloader="[{ 'path': 'https://randomuser.me/api/' }, { 'path': 'https://randomuser.me/api/' }]">
template-url="template.html"
aping-jsonloader="[{ 'path': 'https://randomuser.me/api/' }, { 'path': 'https://randomuser.me/api/' }]">
</aping>

<br><br>
Expand Down
3 changes: 0 additions & 3 deletions demo/unstyled_template.html

This file was deleted.

31 changes: 24 additions & 7 deletions dist/aping.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
@name: aping
@version: 1.0.4 (23-01-2016)
@version: 1.0.5 (24-01-2016)
@author: Jonathan Hornung <[email protected]>
@url: https://github.com/JohnnyTheTank/apiNG
@license: MIT
Expand Down Expand Up @@ -36,11 +36,28 @@ angular.module('jtt_aping')
valueName: '@'
},
link: function (scope, element, attrs) {
$templateRequest(scope.templateUrl || apingDefaultSettings.templateUrl).then(function (html) {
var template = angular.element(html);
element.append(template);
$compile(template)(scope);
});

var templatePath = scope.templateUrl || undefined;
if (angular.isUndefined(templatePath)) {
if (angular.isDefined(apingDefaultSettings.templateUrl)) {
templatePath = apingDefaultSettings.templateUrl;
}
}

if (angular.isDefined(templatePath) && templatePath !== "$NONE") {
$templateRequest(templatePath).then(function (html) {
var template = angular.element(html);
element.append(template);
$compile(template)(scope);
});
} else {
var html = element.html();
html = html.replace(/\[\[(\w+)\]\]/g, function (_, text) {
return '<span translate="' + text + '"></span>';
});
element.html(html);
$compile(element.contents())(scope);
}
},
controller: ['$scope', function ($scope) {
$scope.results = [];
Expand Down Expand Up @@ -170,7 +187,7 @@ angular.module('jtt_aping')
$scope.results = $scope.results.splice(0, appSettings.maxItems);
}

if(angular.isDefined(appSettings.valueName)) {
if (angular.isDefined(appSettings.valueName)) {
apingResults[appSettings.valueName] = $scope.results;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/aping.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aping",
"version": "1.0.4",
"version": "1.0.5",
"description": "apiNG is an AngularJS directive that enables you to receive, aggregate, limit, order and display data from one or more sources. The complete setup is dead simple, just by adding data-attributes to your html",
"main": "dist/aping.min.js",
"scripts": {
Expand Down
29 changes: 23 additions & 6 deletions src/aping-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,28 @@ angular.module('jtt_aping')
valueName: '@'
},
link: function (scope, element, attrs) {
$templateRequest(scope.templateUrl || apingDefaultSettings.templateUrl).then(function (html) {
var template = angular.element(html);
element.append(template);
$compile(template)(scope);
});

var templatePath = scope.templateUrl || undefined;
if (angular.isUndefined(templatePath)) {
if (angular.isDefined(apingDefaultSettings.templateUrl)) {
templatePath = apingDefaultSettings.templateUrl;
}
}

if (angular.isDefined(templatePath) && templatePath !== "$NONE") {
$templateRequest(templatePath).then(function (html) {
var template = angular.element(html);
element.append(template);
$compile(template)(scope);
});
} else {
var html = element.html();
html = html.replace(/\[\[(\w+)\]\]/g, function (_, text) {
return '<span translate="' + text + '"></span>';
});
element.html(html);
$compile(element.contents())(scope);
}
},
controller: ['$scope', function ($scope) {
$scope.results = [];
Expand Down Expand Up @@ -160,7 +177,7 @@ angular.module('jtt_aping')
$scope.results = $scope.results.splice(0, appSettings.maxItems);
}

if(angular.isDefined(appSettings.valueName)) {
if (angular.isDefined(appSettings.valueName)) {
apingResults[appSettings.valueName] = $scope.results;
}

Expand Down

0 comments on commit 6758ed5

Please sign in to comment.