super-productivity/packages/plugin-dev/ai-productivity-prompts/test-template-fixed.js
2025-08-29 15:50:19 +02:00

37 lines
1 KiB
JavaScript

// Simple test for the renderPrompt function - FIXED VERSION
function renderPrompt(template, tasksMd) {
return template.replace(/{{#if tasks_md}}([\s\S]*?){{\/if}}/g, (match, content) => {
if (tasksMd) {
return content.replace(/{{tasks_md}}/g, tasksMd);
}
return '';
});
}
// Test cases
console.log('Test 1 - Without tasks:');
const template1 = 'Hello {{#if tasks_md}}here are tasks: {{tasks_md}}{{/if}} end.';
console.log(renderPrompt(template1));
console.log('\nTest 2 - With tasks:');
console.log(renderPrompt(template1, '- Task 1\n- Task 2'));
console.log('\nTest 3 - Real prompt template:');
const realTemplate = `You are an executive function coach. Given my tasks, help me pick a realistic Top 3 for today.
{{#if tasks_md}}
Here are my tasks:
{{tasks_md}}
{{/if}}`;
console.log('Without tasks:');
console.log(renderPrompt(realTemplate));
console.log('\nWith tasks:');
console.log(
renderPrompt(
realTemplate,
'- [ ] Complete project report\n- [ ] Review PR #123\n- [ ] Meeting with team',
),
);