Notre avis
Compare les sorties des templates ERB et JavaScript convertis pour vérifier leur parité dans une SPA de scoring hors ligne.
Points forts
- Automatise la comparaison des templates ERB et JS en une seule commande.
- Sauvegarde les fichiers de sortie pour une analyse de diff approfondie.
- Identifie les différences attendues (encodage HTML, blocs link_to) pour éviter les faux positifs.
Limites
- Nécessite une base de données SQLite et un serveur Rails en cours d'exécution.
- Ne couvre que les templates de scoring, pas toute l'application.
- Les différences de formatage (whitespace) peuvent être ignorées, mais certains écarts réels peuvent être masqués.
Lors de la conversion de templates ERB en JS ou du débogage de disparités entre les deux rendus dans la SPA.
Si vous travaillez sur des parties de l'application qui n'utilisent pas de templates doubles ERB/JS.
Analyse de sécurité
SûrThe skill instructs running a development script for template comparison, which involves local Ruby scripts, bundle exec, and file output to /tmp. There are no destructive commands, network exfiltration, or obfuscation. It is safe to use as an AI instruction.
Aucun point d'attention détecté
Exemples
Compare ERB and JS template outputs for heat 83 in the Barcelona November database.Render and compare the individual heat 1 for judge 83 with style parameter 'radio' to check for differences.Run the compare script and then diff the href attributes between the ERB and JS outputs.name: compare-erb-js description: Compare ERB and JavaScript template outputs for the offline scoring SPA. Use when working on ERB-to-JS conversion, debugging template parity issues, or verifying that changes to scoring views work correctly in both ERB and SPA modes.
Compare ERB vs JavaScript Template Output
Use scripts/render_erb_and_js.rb to verify that ERB templates and their JavaScript-converted equivalents produce matching output. This is essential for the offline scoring SPA which uses auto-converted ERB templates.
Basic Usage
# Compare heat list
bundle exec ruby scripts/render_erb_and_js.rb db/2025-barcelona-november.sqlite3 83
# Compare individual heat
bundle exec ruby scripts/render_erb_and_js.rb db/2025-barcelona-november.sqlite3 83 1
# With style parameter
bundle exec ruby scripts/render_erb_and_js.rb db/2025-barcelona-november.sqlite3 83 1 radio
Or using environment variable:
RAILS_APP_DB=2025-barcelona-november bundle exec ruby scripts/render_erb_and_js.rb 83 1
What It Does
- Renders the ERB template via Rails routing (extracts
<main>content) - Fetches converted JavaScript templates from
/templates/scoring.js - Fetches normalized data from
/scores/:judge/heats/data - Hydrates the data using
heat_hydrator.js(for individual heats) - Renders using the JavaScript template
- Compares row counts and saves both outputs for diff analysis
Output Files
All files are saved to /tmp/ for analysis:
/tmp/erb_rendered.html- ERB template output (main content only)/tmp/js_rendered.html- JavaScript template output/tmp/scoring_templates.js- Converted templates from/templates/scoring.js/tmp/heats_data.json- Raw normalized data from server/tmp/js_template_data.json- Hydrated data passed to JS template
Analyzing Differences
# Quick diff
diff /tmp/erb_rendered.html /tmp/js_rendered.html
# Side-by-side comparison
diff -y /tmp/erb_rendered.html /tmp/js_rendered.html | less
# Compare specific attributes
diff <(grep -o 'href="[^"]*"' /tmp/erb_rendered.html | sort) \
<(grep -o 'href="[^"]*"' /tmp/js_rendered.html | sort)
Common Differences
Some differences are expected due to ERB-to-JS conversion limitations:
- HTML entity encoding: ERB uses
"while JS uses" - link_to blocks: Block form of
link_tomay render differently - Whitespace: Minor whitespace differences are normal
Architecture
This tool supports the "Server computes, hydration joins, templates filter" principle:
- Server: Computes derived values and paths (respects RAILS_APP_SCOPE)
- Hydration:
heat_hydrator.jsjoins normalized data by resolving IDs - Templates: ERB and JS templates filter/format data identically
Key Source Files
Server-side (Rails)
-
app/controllers/scores_controller.rbheats_dataaction: Returns normalized JSON data for SPAheataction: Sets instance variables for ERB templates- Computes
paths:hash with server-computed URLs
-
app/controllers/templates_controller.rbscoringaction: Converts ERB templates to JavaScript on-the-fly- Defines path helper stubs for JS templates
- Uses
ErbPrismConverterfor conversion
-
lib/erb_prism_converter.rb- Converts ERB templates to JavaScript functions using Ruby's Prism parser
- Handles Ruby-to-JS translation (loops, conditionals, method calls)
Client-side (JavaScript)
-
app/javascript/lib/heat_hydrator.jsbuildLookupTables(): Creates Maps for O(1) entity lookuphydrateHeat(): Resolves IDs to full objectsbuildHeatTemplateData(): Prepares complete data for templates
-
app/javascript/controllers/heat_app_controller.js- Main Stimulus controller for the offline scoring SPA
- Loads templates and data, handles navigation
- Manages offline/online state transitions
ERB Templates (source of truth)
app/views/scores/heat.html.erb- Main heat viewapp/views/scores/heatlist.html.erb- Heat list viewapp/views/scores/_heat_header.html.erb- Heat header partialapp/views/scores/_info_box.html.erb- Info box with feedback errorsapp/views/scores/_navigation_footer.html.erb- Prev/next navigationapp/views/scores/_table_heat.html.erb- Standard heat tableapp/views/scores/_rank_heat.html.erb- Finals ranking viewapp/views/scores/_solo_heat.html.erb- Solo heat viewapp/views/scores/_cards_heat.html.erb- Card-based scoring view
Scripts
scripts/render_erb_and_js.rb- This comparison toolscripts/hydrate_heats.mjs- Node.js script for hydrating data (used by comparison tool)
Expert Next.js App Router
Developpement
Un skill qui transforme Claude en expert Next.js App Router.
Générateur de README
Developpement
Crée des README.md professionnels et complets pour vos projets.
Rédacteur de Documentation API
Developpement
Génère de la documentation API complète au format OpenAPI/Swagger.