jsutils / file
Javascript File Utility
Installs: 80
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 1
Open Issues: 0
Language:JavaScript
Requires
- jsutils/json: >=0.0.0
- jsutils/tmpl: >=0.0.0
- webmodules/jquery: >=2.1.5
README
##getJSON load JSON file from server and applies dummyJSON if data is passed.
//my_server/my_json_file.json { "people": { "id" : "{{data.id}}" } } //Client Side Code var fileUtil = _module_("jsutils.file"); fileUtil.getJSON("my_server/my_json_file.json",{ id : 100}).done(function(resp){ //formatted json }); //OUTPUT FORMATTED { "people": { "id" : "100" } }
##getHTML load HTML file from server, applies underscore templating on it.
//my_server/my_html_file.html <div> <strong>Hi, Data id is {{data.id}}</strong> </div> //Client Side Code var fileUtil = _module_("jsutils.file"); fileUtil.getHTML("my_server/my_html_file.html",{ id : 100}).done(function(resp){ //formatted html }); //OUTPUT FORMATTED <div> <strong>Hi, Data id is 100</strong> </div>
Include Nested HTML
If template contains include tag, then nested HTML template is applied. Data can be passed as you wish to nested template.
//my_server/in_other_folder_my_other_html_file.html <div> <strong>And My name is {{data.name}}</strong> </div> //my_server/my_html_file2.html <div> <strong>Hi, Data id is {{data.id}}</strong> <include src="in_other_folder_my_other_html_file.html" data=data.user /> </div> //Client Side Code var fileUtil = _module_("jsutils.file"); fileUtil.getHTML("my_server/my_html_file2.html",{ id : 100, user : { name : "Lalit" } }).done(function(resp){ //formatted html }); //OUTPUT <div> <strong>Hi, Data id is {{data.id}}</strong> <div> <strong>And My name is Lalit</strong> </div> </div>