Jon-Biz / FireUser

A Firebase user management module for Angularjs
61 stars 10 forks source link

Extract templates to template folder #10

Open rmtuckerphx opened 10 years ago

rmtuckerphx commented 10 years ago

i would like to use the FireUser directives with Ionic framework and would like templates externalized so that they can be changed.

Jon-Biz commented 10 years ago

Would it make more sense to make the controllers standalone, so they can be required or specified?

Jon-Biz commented 10 years ago

In the current version of FireUser, the directive controllers have been extracted and can now included via require or controller in your directive. The documentation has yet to be updated. Will this solve your issue?

rmtuckerphx commented 10 years ago

That is a partial solution. I could write my own directive with a different template. What I like better is the approach taken at https://github.com/angular-ui/bootstrap where the directive and controller make up the component and the template is external. You could then have different folders under the template folder for bootstrap 2, bootstrap 3, ionic or any other CSS framework. Part of the configuration would be the path to template folder.

rmtuckerphx commented 10 years ago

Here are samples of the updated directives that use externalized templates:

angular.module('fireUser', ['firebase']) .constant('FireUserDefault', { redirectPath:'/', datalocation:'data', userdata:'user', iconCss:'fontawesome', templatePath:'template/bootstrap3' })

.directive('fireuserlogin', ['FireUserValues', function(FireUserValues) { return { scope:{ type:'@' }, replace: true, templateUrl: FireUserValues.templatePath + '/fireuser-login.html', controller:'fireuserloginCTRL', link: function ($scope,element,attr,ctrl) { if(FireUserValues.iconCss === 'fontawesome'){ element.addClass('fa fa-'+attr.type); } else { element.text = 'Log In with ' + attr.type; } }, restrict: 'E' }; }])

.directive('fireuserlogout', ['FireUserValues', function(FireUserValues) { return { scope:{ type:'@' }, replace: true, templateUrl: FireUserValues.templatePath + '/fireuser-logout.html', controller:'fireuserlogoutCTRL', restrict: 'E' }; }])

.directive('fireuserloginform', ['$compile', '$http', '$templateCache', 'FireUserValues', function ($compile, $http, $templateCache, FireUserValues) { return { scope:{}, restrict:'E', controller:'fireuserloginformCTRL', link:function ($scope,element,attr,ctrl) { var tplUrl = FireUserValues.templatePath + '/fireuser-login-form.html';

   $http.get(tplUrl, {cache: $templateCache}).success(function(tplContent){
       element.replaceWith($compile(tplContent.trim())($scope));
    });
}

}; }])

.directive('fireusersignupform', ['$compile', '$http', '$templateCache', 'FireUserValues', function ($compile, $http, $templateCache, FireUserValues) { return { scope:{}, restrict:'E', controller:'fireusersignupformCTRL', link:function ($scope,element,attr,ctrl) { var tplUrl = FireUserValues.templatePath + '/fireuser-signup-form.html';

   $http.get(tplUrl, {cache: $templateCache}).success(function(tplContent){
       element.replaceWith($compile(tplContent.trim())($scope));
    });
}

}; }])