Skip to content

Commit f8b3963

Browse files
authored
Merge pull request #628 from HeyPuter/eric/fix-templates
Write contents from template when creating a file from a tempalte
2 parents 1f7f094 + 5d58764 commit f8b3963

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/gui/src/helpers.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -869,17 +869,26 @@ window.available_templates = async () => {
869869

870870
hasTemplateFiles.forEach(element => {
871871
console.log(element)
872-
const elementInformation = element.name.split(".")
873-
const name = elementInformation[0]
874-
let extension = elementInformation[1]
875-
console.log(extension)
872+
873+
const extIndex = element.name.lastIndexOf('.');
874+
const name = extIndex === -1
875+
? element.name
876+
: element.name.slice(0, extIndex);
877+
let extension = extIndex === -1
878+
? ''
879+
: element.name.slice(extIndex + 1);
880+
876881
if(extension == "txt") extension = "text"
882+
883+
const _path = path.join( baseRoute, hasTemplateFolder.name, element.name);
884+
885+
console.log(_path)
877886
const itemStructure = {
887+
path: _path,
878888
html: `${extension.toUpperCase()} ${name}`,
879889
extension:extension,
880890
name: element.name
881891
}
882-
console.log(extension)
883892
result.push(itemStructure)
884893
});
885894

src/gui/src/helpers/new_context_menu_item.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ const new_context_menu_item = function(dirname, append_to_element){
8484
items: window.file_templates.map(template => ({
8585
html: template.html,
8686
icon: `<img src="${html_encode(window.icons[`file-${template.extension}.svg`])}" class="ctx-item-icon">`,
87-
onClick: function() {
88-
window.create_file({dirname: dirname, append_to_element: append_to_element, name: template.name});
87+
onClick: async function () {
88+
const content = await puter.fs.read(template.path);
89+
window.create_file({
90+
dirname: dirname,
91+
append_to_element: append_to_element,
92+
name: template.name,
93+
content,
94+
});
8995
}
9096
}))
9197
});

0 commit comments

Comments
 (0)