WebOrbiton
v1.5.0

AtheraStudio Code

58 lines · 1.5 KB
  1. (function () {
  2. "use strict";
  3. ​
  4. var A = window.Athera;
  5. var util = A.util;
  6. ​
  7. function title(path) {
  8. var base = util.basename(path).replace(/\.[^.]+$/, "");
  9. return base === "index" ? "My Page" : base.charAt(0).toUpperCase() + base.slice(1);
  10. }
  11. ​
  12. function head(t) {
  13. return [
  14. "<!DOCTYPE html>",
  15. '<html lang="en">',
  16. "<head>",
  17. ' <meta charset="UTF-8">',
  18. ' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
  19. " <title>" + t + "</title>",
  20. "</head>",
  21. "<body>"
  22. ];
  23. }
  24. ​
  25. var BY_EXT = {
  26. html: function (path) {
  27. var t = util.esc(title(path));
  28. return head(t).concat([
  29. " <h1>" + t + "</h1>",
  30. " <p>Start editing this file.</p>",
  31. "</body>",
  32. "</html>",
  33. ""
  34. ]).join("\n");
  35. },
  36. php: function (path) {
  37. var t = title(path).replace(/["\\$]/g, "\\$&");
  38. return ["<?php", '$title = "' + t + '";', "?>"].concat(head("<?= htmlspecialchars($title) ?>"), [
  39. " <h1><?= htmlspecialchars($title) ?></h1>",
  40. "</body>",
  41. "</html>",
  42. ""
  43. ]).join("\n");
  44. },
  45. json: function () { return "{\n \n}\n"; },
  46. md: function (path) { return "# " + title(path) + "\n\n"; }
  47. };
  48. BY_EXT.htm = BY_EXT.html;
  49. ​
  50. A.templates = {
  51. forFile: function (path) {
  52. if (!A.settings || !A.settings.get("newFileTemplates")) return "";
  53. var fn = BY_EXT[util.ext(path)];
  54. return fn ? fn(path) : "";
  55. }
  56. };
  57. })();
  58. ​