Skip to content

Commit 870317d

Browse files
committed
docs: expand 2.3.0 changelog and document missing pattern:diff options
CHANGELOG: add all new classes (BlockNormalizer, PatternDiffer, TranslationDetector, WooCommerceValidator), the full PatternDiff test suite, all command options, and the .vibe/config.toml change. README: document --show-suggestions, --json, and --similarity-threshold options for pattern:diff.
1 parent 69fdc5c commit 870317d

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,41 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
88

99
### Added
1010

11-
- **`pattern:diff --apply` flag** — merges Gutenberg clipboard HTML back into an existing PHP pattern file while preserving all PHP translation wrappers (`esc_html_e`, `esc_attr_e`, `wp_kses_post`, `get_template_directory_uri`). Strips editor-only attributes (`__privatePreviewState`), normalises bare font-size slug values to CSS variables, and removes nested `<p>` copy artefacts. Pair with `--dry-run` to preview the merged result before writing.
11+
- **`pattern:diff` command** (`src/Commands/PatternDiffCommand.php`) — compares a Gutenberg clipboard paste against an existing PHP pattern file and reports differences (missing translations, editor-only attributes, CSS drift, WooCommerce block issues). Options:
12+
- `--from-stdin` — read Gutenberg HTML from stdin (pipe from `pbpaste`)
13+
- `--apply` — merge clipboard changes into the PHP file, preserving all PHP translation wrappers (`esc_html_e`, `esc_attr_e`, `wp_kses_post`, `get_template_directory_uri`)
14+
- `--dry-run` — with `--apply`: print the merged result to stdout instead of writing to disk
15+
- `--theme` — theme config to use (default: `elayne`)
16+
- `--json` — output diff results as JSON
17+
- `--similarity-threshold` — minimum block similarity score to consider a match (0–1, default: `0.95`)
18+
- `--show-suggestions` / `-s` — include fix suggestions in the output
1219

13-
- **`pattern:diff --dry-run` flag** — prints the merged result to stdout instead of writing to disk; only meaningful when combined with `--apply`.
20+
- **`BlockNormalizer` class** (`src/PatternDiff/BlockNormalizer.php`) — normalises block HTML for comparison: strips editor-only attributes (`__privatePreviewState`, `isNotStackedOnMobile`, constrained layout flags, product-collection block flags), normalises CSS value tokens (font-size slugs → CSS variables, spacing presets), collapses whitespace, and decodes HTML entities. Exposes `detectEditorAttributes()`, `extractOuterBlockType()`, and `hasWooCommerceBlocks()` as public helpers.
1421

15-
- **`PatternSyncer` class** (`src/PatternDiff/PatternSyncer.php`) — implements the merge strategy: extracts the PHP docblock header, builds a `text → PHP call` map from all translation wrappers in the original file, applies structural fixes to the clipboard, then walks every HTML text node replacing raw strings with their original wrappers (or generating new `esc_html_e()` calls for new strings).
22+
- **`PatternDiffer` class** (`src/PatternDiff/PatternDiffer.php`) — calculates structural similarity between clipboard HTML and a PHP pattern file. Extracts block HTML from PHP, computes a similarity score via `similar_text`, and finds CSS, structural, and text-node differences. WooCommerce plugin paths (`wp-content/plugins/woocommerce/patterns/*`) are exempt via `isExempt()`.
23+
24+
- **`PatternSyncer` class** (`src/PatternDiff/PatternSyncer.php`) — implements the `--apply` merge strategy: extracts the PHP docblock header, builds a `text → PHP call` map from all translation wrappers in the original file, applies structural fixes to the clipboard (strips `__privatePreviewState`, normalises font-size slugs, removes nested `<p>` copy artefacts), then walks every HTML text node replacing raw strings with their original wrappers or generating new `esc_html_e()` calls for new strings.
25+
26+
- **`TranslationDetector` class** (`src/PatternDiff/TranslationDetector.php`) — finds text nodes in clipboard HTML that are not yet wrapped in a translation function in the existing PHP file. Generates `esc_html_e()` fix suggestions. Exposes `isTranslated()`, `generateTranslationWrapper()`, and `extractTranslatableText()` as public helpers.
27+
28+
- **`WooCommerceValidator` class** (`src/PatternDiff/WooCommerceValidator.php`) — validates WooCommerce-specific block structure in the diff context: checks `isDescendentOfQueryLoop` on WC blocks inside `product-template`, validates `<div>` wrappers and layout attributes, and inspects `product-collection` query metadata.
29+
30+
- **PHPUnit test suite for `PatternDiff`** — 6 new test files covering all public methods in the feature:
31+
- `tests/PatternDiff/BlockNormalizerTest.php` — 29 tests for all normalisation methods
32+
- `tests/PatternDiff/PatternDifferTest.php` — 5 tests (diff result shape, identical-file similarity, PHP extraction, exempt paths)
33+
- `tests/PatternDiff/PatternSyncerTest.php` — 22 tests (header extraction/stripping, PHP call map, structural fixes, translation restore, wrapper generation)
34+
- `tests/PatternDiff/TranslationDetectorTest.php` — 16 tests (missing translation detection, `isTranslated`, `generateTranslationWrapper`, `extractTranslatableText`)
35+
- `tests/PatternDiff/WooCommerceValidatorTest.php` — 6 tests (validate, extractWooCommerceBlocks, isDescendantOfProductTemplate)
36+
- `tests/Commands/PatternDiffCommandTest.php` — 9 tests (command name, path validation, apply/dry-run guards, JSON output, threshold, theme option)
1637

1738
### Fixed
1839

1940
- **`PatternDiffer::isTranslatable()`** — the `if (preg_match(...))` guard around the CSS-value `return false` branch was accidentally omitted, causing the method to always return `false` after the single-character check. All text nodes after that point were silently skipped by the translation detector.
2041

42+
### Changed
43+
44+
- **`.vibe/config.toml`**`python` and `python3` removed from the vibe tools denylist to allow local script execution during pattern diffing.
45+
2146
## [2.2.3] - 2026-05-13
2247

2348
### Added

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,20 @@ the changes back while preserving all PHP translation wrappers.
8080
# Report differences only (shows missing translations, editor attrs, CSS issues)
8181
pbpaste | pt-cli pattern:diff patterns/woo-signature-pieces.php --from-stdin
8282

83+
# Include fix suggestions in the diff report
84+
pbpaste | pt-cli pattern:diff patterns/woo-signature-pieces.php --from-stdin --show-suggestions
85+
86+
# Output diff results as JSON (for tooling integration)
87+
pbpaste | pt-cli pattern:diff patterns/woo-signature-pieces.php --from-stdin --json
88+
8389
# Preview the merged result without touching the file
8490
pbpaste | pt-cli pattern:diff patterns/woo-signature-pieces.php --from-stdin --apply --dry-run
8591

8692
# Apply clipboard changes to the PHP file (preserves esc_html_e, esc_attr_e, etc.)
8793
pbpaste | pt-cli pattern:diff patterns/woo-signature-pieces.php --from-stdin --apply
94+
95+
# Lower the similarity threshold for loosely matched blocks (default: 0.95)
96+
pbpaste | pt-cli pattern:diff patterns/woo-signature-pieces.php --from-stdin --similarity-threshold=0.80
8897
```
8998

9099
**What `--apply` does:**

0 commit comments

Comments
 (0)