From d5c0260678df9d9e091046499d5e488c21655716 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Wed, 29 Oct 2025 12:42:41 -0700 Subject: [PATCH 01/13] Refine HTL compatibility plan: expression syntax, migration docs, and utils:eval() - #1: Make ${} optional in data-fly-* directives for HTL familiarity - #2: Create HTL migration documentation explaining key differences - #3: Add utils:eval() for JavaScript expressions (future consideration) - Uses new Function() for full JS power (~150 bytes) - Appropriately scary naming with 'eval' to warn developers - CSP requires unsafe-eval policy - Removed data-fly-use (not needed - context functions work better) - Removed context options (DOM manipulation doesn't need HTL's escaping) --- HTL_COMPATIBILITY_PLAN.md | 273 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 HTL_COMPATIBILITY_PLAN.md diff --git a/HTL_COMPATIBILITY_PLAN.md b/HTL_COMPATIBILITY_PLAN.md new file mode 100644 index 0000000..ab31cfb --- /dev/null +++ b/HTL_COMPATIBILITY_PLAN.md @@ -0,0 +1,273 @@ +# HTL/Sightly Compatibility Improvements Plan + +This document outlines planned improvements to make Faintly easier to use for developers with HTL/Sightly background. + +## Implementation Priority + +### ✅ To Implement + +#### 1. Standardize Expression Syntax (Refined) +Make `${}` optional in `data-fly-*` directives for consistency with HTL. + +**Current behavior:** +- `${}` required in text content and regular attributes (explicit evaluation) +- Bare expressions in `data-fly-*` directive values + +**Proposed behavior:** +- **In `data-fly-*` directives**: Accept both `${expression}` and bare `expression` +- **In regular attributes and text**: Keep `${}` required (current behavior - efficient and explicit) + +**Why this approach:** +- Avoids evaluating every attribute value (performance concern) +- No ambiguity - `${}` explicitly marks what should be evaluated +- Provides HTL-like feel where it matters (directives) +- Maintains backward compatibility + +**Examples:** +```html + +
+
+ + +Link +
Content
+ + +

Hello ${user.name}

+``` + +**Implementation notes:** +- Modify directive processing functions in `directives.js` to strip `${}` wrapper if present +- Only affects `data-fly-*` attribute value parsing +- Ensure backward compatibility with existing code +- Update tests to cover both syntaxes in directives +- Update README.md to document both syntaxes are supported in directives + +--- + +#### 2. Add HTL Migration Documentation +Create a dedicated doc linked from README.md with side-by-side comparisons. + +**Content to include:** +- Directive comparison table (HTL vs Faintly) +- Expression syntax differences +- Backend integration comparison (`data-sly-use` vs context object) + - **Important**: Explain that `data-sly-use` is replaced by context functions + - Show how Faintly's automatic function calling provides lazy/conditional loading + - Example: `data-fly-content="fetchArticles"` automatically calls the function +- Context options (`@ context='uri'`) and why they're not needed in Faintly + - HTL needs context-aware escaping because it generates HTML strings server-side + - Faintly manipulates DOM directly - browser handles escaping automatically + - Faintly's security module provides attribute/URL validation without needing context options +- Common patterns and their equivalents +- Migration examples from typical HTL components + +**Example table:** +| HTL/Sightly | Faintly | Description | +|-------------|---------|-------------| +| `data-sly-test` | `data-fly-test` | Conditional rendering | +| `data-sly-list` | `data-fly-repeat` | Iteration | +| `data-sly-use` | context object | Backend integration | +| `data-sly-template` | `