Skip to content

feat: add eq / in processors and make WhenRenderer whitespace-tolerant (#31)#32

Merged
mt8 merged 1 commit intomainfrom
feature/31-eq-in-processors
Apr 28, 2026
Merged

feat: add eq / in processors and make WhenRenderer whitespace-tolerant (#31)#32
mt8 merged 1 commit intomainfrom
feature/31-eq-in-processors

Conversation

@mt8
Copy link
Copy Markdown
Owner

@mt8 mt8 commented Apr 28, 2026

Closes #31.

Summary

  • 等価判定用プロセッサ eq / in を追加。feedwright/when の expression を map:trash=1,*= のような冗長な書き方から eq:trash / in:trash,draft に置き換え可能。
  • ついでに feedwright/when の真偽判定を whitespace-tolerant に変更('' === trim($value))。式の末尾にうっかり半角スペースを入れて常に真扱いになる事故を防ぐ(実際のローカル検証で踏んだのを修正)。

ビフォーアフター

# 等価判定
{{post_raw.post_status|map:trash=1,*=}}      → {{post_raw.post_status|eq:trash}}

# 複数値マッチ
{{post_raw.post_status|map:trash=1,draft=1,*=}}  → {{post_raw.post_status|in:trash,draft}}

eq / in入力が一致するときに入力をそのまま返し、違えば空文字列を返すfeedwright/when の判定基準(非空 = 真)にそのまま乗る。負の判定は feedwright/whennegate で済むので neq / not_in は意図的に追加しない。

Whitespace tolerance

WhenRenderer の判定が '' !== $value から '' !== trim( $value ) に変わるので、

{{post_raw.post_status|eq:trash}}    ← OK
{{post_raw.post_status|eq:trash}}    ← 末尾にスペース 1 個。以前は常に真、今は trim されて期待通り

Changes

  • src/Bindings/Resolver.phpprocess_eq / process_in を built-in processors に追加
  • src/Renderer/WhenRenderer.php:判定行に trim() を追加
  • blocks/_shared/processor-suggestions.js| autocomplete に eq / in 追加(argHint trash, trash,draft
  • tests/Unit/BindingResolverTest.php:eq / in の挙動・空白トリム・空リスト・チェーン整合
  • tests/Integration/RenderTest.php:when ブロックでの eq:trash の sanity check と whitespace-only expression が空扱いになる regression
  • docs/requirements.md §13.6.2(whitespace tolerance の言及) + §14.6.1(プロセッサ表)
  • ja 翻訳 2 件追加

Test plan

  • Visual:BindingInput で | autocomplete に eq / in が出る
  • Render{{post_raw.post_status|eq:trash}} の when 配下が trash 投稿でだけ出力される
  • Render:以前バグった末尾スペース付き式({{...|eq:trash}} )が今は常に空扱いになる
  • Testscomposer test:unit (80 passed)、wp-env tests (141 passed)、composer phpcs (29 passed)
  • wp-env 実機:goonews フィードで <mdf:deleted/> がトラッシュ済み 1 件にだけ出る(今回の修正前は 20 件全部に出ていた)

関連

#27feedwright/when ブロック追加)の延長。eq / in プロセッサと組み合わせると mediba 削除通知の expression が読みやすくなる。

…erant (#31)

Equality predicates against bindings used to require the verbose
`map:value=1,*=` idiom. Two new processors make the common
single-value and multi-value match cases direct:

  {{post_raw.post_status|eq:trash}}        # was: |map:trash=1,*=
  {{post_raw.post_status|in:trash,draft}}  # was: |map:trash=1,draft=1,*=

The `eq` / `in` processors return the input unchanged when the match
holds, and an empty string otherwise. They compose with the rest of the
pipeline and gate `feedwright/when` directly. Negative match is still
expressed via `feedwright/when negate=true`, so we deliberately do not
add `neq` / `not_in`.

Bundled with this: WhenRenderer's truthiness check now uses
`'' !== trim( $value )`, so a stray trailing space in the expression
(common typo class — observed in real local testing) no longer flips
the gate to always-true.

- src/Bindings/Resolver.php: process_eq + process_in registered as
  built-in processors
- src/Renderer/WhenRenderer.php: trim() before the empty check
- blocks/_shared/processor-suggestions.js: eq / in surfaced in the |
  autocomplete with arg hints
- Unit tests: eq / in equality, trim, list semantics, empty-arg edge
- Integration tests: when block with eq sanity-checks trashed-post
  gating, and a regression test that whitespace-only expressions stay
  closed
- docs/requirements.md §13.6.2 (whitespace tolerance) + §14.6.1
  (processor table)
- ja translation strings added
@mt8 mt8 merged commit fb308b7 into main Apr 28, 2026
6 of 7 checks passed
@mt8 mt8 deleted the feature/31-eq-in-processors branch April 28, 2026 11:45
@mt8 mt8 mentioned this pull request Apr 28, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: eq / in プロセッサを追加して等価判定を直感的に書けるようにする

1 participant