save.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Save.js
  3. This file save the web content to file
  4. require paramter:
  5. filepath
  6. content
  7. Optional:
  8. template
  9. title
  10. */
  11. requirelib("filelib");
  12. requirelib("appdata");
  13. function saveFile(){
  14. //Load templates
  15. var templateContent = "";
  16. if (typeof(template) == "undefined" || !filelib.fileExists(template)){
  17. //Use default template
  18. templateContent = appdata.readFile("Web Builder/template.html");
  19. //Custom CSS replacement in the content
  20. content = content.split("<table>").join("<table class='ui celled table'>")
  21. //Replace seperation lines
  22. content = content.split("__se__solid").join("__se__ ui divider");
  23. content = content.split("__se__dotted").join("__se__ ui dotted divider");
  24. content = content.split("__se__dashed").join("__se__ ui dashed divider");
  25. }else if (template != ""){
  26. //Use user defined template
  27. templateContent = filelib.readFile(template);
  28. }
  29. var defaultTitle = USERNAME + " Webpage";
  30. if (typeof(title) != "undefined" && title != ""){
  31. defaultTitle = title
  32. }
  33. //Apply the content to the template
  34. templateContent = templateContent.split("{{title}}").join(defaultTitle);
  35. templateContent = templateContent.split("{{content}}").join(content);
  36. filelib.writeFile(filepath, templateContent)
  37. sendResp("OK");
  38. }
  39. saveFile();