The personal finance app for everyone (by everyone)
Ruby
Generate plain ERB from the provider view templates (#4099)
jaysbeekay148b007b6602
diff --git a/lib/generators/provider/family/templates/item_partial.html.erb.tt b/lib/generators/provider/family/templates/item_partial.html.erb.ttindex 4e53e5a4be..5f6c35cef2 100644--- a/lib/generators/provider/family/templates/item_partial.html.erb.tt+++ b/lib/generators/provider/family/templates/item_partial.html.erb.tt@@ -1,130 +1,130 @@-<%%= "<" + "%# locals: (#{file_name}_item:, visible_accounts:) %" + ">" %>+<%%# locals: (<%= file_name %>_item:, visible_accounts:) %>-<%%= "<" + "%= tag.div id: dom_id(#{file_name}_item) do %" + ">" %>+<%%= tag.div id: dom_id(<%= file_name %>_item) do %><details open class="group bg-container p-4 shadow-border-xs rounded-xl"><summary class="flex items-center justify-between gap-2 focus-visible:outline-hidden"><div class="flex items-center gap-2">- <%%= "<" + "%= icon \"chevron-right\", class: \"group-open:transform group-open:rotate-90\" %" + ">" %>+ <%%= icon "chevron-right", class: "group-open:transform group-open:rotate-90" %>- <%%= "<" + "%= render ProviderLogo.new(provider_key: :#{file_name}) %" + ">" %>+ <%%= render ProviderLogo.new(provider_key: :<%= file_name %>) %><div class="pl-1 text-sm"><div class="flex items-center gap-2">- <%%= "<" + "%= tag.p #{file_name}_item.name, class: \"font-medium text-primary\" %" + ">" %>- <%%= "<" + "% if #{file_name}_item.scheduled_for_deletion? %" + ">" %>- <p class="text-destructive text-sm animate-pulse"><%%= "<" + "%= t(\".deletion_in_progress\") %" + ">" %></p>- <%%= "<" + "% end %" + ">" %>+ <%%= tag.p <%= file_name %>_item.name, class: "font-medium text-primary" %>+ <%% if <%= file_name %>_item.scheduled_for_deletion? %>+ <p class="text-destructive text-sm animate-pulse"><%%= t(".deletion_in_progress") %></p>+ <%% end %></div>- <p class="text-xs text-secondary"><%%= "<" + "%= t(\".provider_name\") %" + ">" %></p>- <%%= "<" + "% if #{file_name}_item.syncing? %" + ">" %>+ <p class="text-xs text-secondary"><%%= t(".provider_name") %></p>+ <%% if <%= file_name %>_item.syncing? %><div class="text-secondary flex items-center gap-1">- <%%= "<" + "%= icon \"loader\", size: \"sm\", class: \"animate-spin\" %" + ">" %>- <%%= "<" + "%= tag.span t(\".syncing\") %" + ">" %>+ <%%= icon "loader", size: "sm", class: "animate-spin" %>+ <%%= tag.span t(".syncing") %></div>- <%%= "<" + "% elsif #{file_name}_item.requires_update? %" + ">" %>+ <%% elsif <%= file_name %>_item.requires_update? %><div class="text-warning flex items-center gap-1">- <%%= "<" + "%= icon \"alert-triangle\", size: \"sm\", color: \"warning\" %" + ">" %>- <%%= "<" + "%= tag.span t(\".requires_update\") %" + ">" %>+ <%%= icon "alert-triangle", size: "sm", color: "warning" %>+ <%%= tag.span t(".requires_update") %></div>- <%%= "<" + "% else %" + ">" %>+ <%% else %><p class="text-secondary">- <%%= "<" + "% if #{file_name}_item.last_synced_at %" + ">" %>- <%%= "<" + "% if #{file_name}_item.sync_status_summary %" + ">" %>- <%%= "<" + "%= t(\".status_with_summary\", timestamp: time_ago_in_words(#{file_name}_item.last_synced_at), summary: #{file_name}_item.sync_status_summary) %" + ">" %>- <%%= "<" + "% else %" + ">" %>- <%%= "<" + "%= t(\".status\", timestamp: time_ago_in_words(#{file_name}_item.last_synced_at)) %" + ">" %>- <%%= "<" + "% end %" + ">" %>- <%%= "<" + "% else %" + ">" %>- <%%= "<" + "%= t(\".status_never\") %" + ">" %>- <%%= "<" + "% end %" + ">" %>+ <%% if <%= file_name %>_item.last_synced_at %>+ <%% if <%= file_name %>_item.sync_status_summary %>+ <%%= t(".status_with_summary", timestamp: time_ago_in_words(<%= file_name %>_item.last_synced_at), summary: <%= file_name %>_item.sync_status_summary) %>+ <%% else %>+ <%%= t(".status", timestamp: time_ago_in_words(<%= file_name %>_item.last_synced_at)) %>+ <%% end %>+ <%% else %>+ <%%= t(".status_never") %>+ <%% end %></p>- <%%= "<" + "% end %" + ">" %>+ <%% end %></div></div><div class="flex items-center gap-2">- <%%= "<" + "% if #{file_name}_item.requires_update? %" + ">" %>- <%%= "<" + "%= render DS::Link.new(" %>+ <%% if <%= file_name %>_item.requires_update? %>+ <%%= render DS::Link.new(text: t(".update_credentials"),icon: "refresh-cw",variant: "secondary",href: settings_providers_path,frame: "_top"- ) <%%= "%" + ">" %>- <%%= "<" + "% else %" + ">" %>- <%%= "<" + "%= icon(" %>+ ) %>+ <%% else %>+ <%%= icon("refresh-cw",as_button: true,href: sync_<%= file_name %>_item_path(<%= file_name %>_item),disabled: <%= file_name %>_item.syncing?- ) <%%= "%" + ">" %>- <%%= "<" + "% end %" + ">" %>+ ) %>+ <%% end %>- <%%= "<" + "%= render DS::Menu.new do |menu| %" + ">" %>- <%%= "<" + "% menu.with_item(" %>+ <%%= render DS::Menu.new do |menu| %>+ <%% menu.with_item(variant: "button",text: t(".delete"),icon: "trash-2",href: <%= file_name %>_item_path(<%= file_name %>_item),method: :delete,confirm: CustomConfirm.for_resource_deletion(<%= file_name %>_item.name, high_severity: true)- ) <%%= "%" + ">" %>- <%%= "<" + "% end %" + ">" %>+ ) %>+ <%% end %></div></summary>- <%%= "<" + "% unless #{file_name}_item.scheduled_for_deletion? %" + ">" %>+ <%% unless <%= file_name %>_item.scheduled_for_deletion? %><div class="space-y-4 mt-4">- <%%= "<" + "% if visible_accounts.any? %" + ">" %>- <%%= "<" + "%= render \"accounts/index/account_groups\", accounts: visible_accounts %" + ">" %>- <%%= "<" + "% end %" + ">" %>+ <%% if visible_accounts.any? %>+ <%%= render "accounts/index/account_groups", accounts: visible_accounts %>+ <%% end %>- <%%= "<" + "%# Sync summary (collapsible) - using shared ProviderSyncSummary component %" + ">" %>- <%%= "<" + "% stats = if defined?(@#{file_name}_sync_stats_map) && @#{file_name}_sync_stats_map" %>+ <%%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>+ <%% stats = if defined?(@<%= file_name %>_sync_stats_map) && @<%= file_name %>_sync_stats_map@<%= file_name %>_sync_stats_map[<%= file_name %>_item.id] || {}else<%= file_name %>_item.syncs.ordered.first&.sync_stats || {}- end <%%= "%" + ">" %>- <%%= "<" + "%= render ProviderSyncSummary.new(" %>+ end %>+ <%%= render ProviderSyncSummary.new(stats: stats,provider_item: <%= file_name %>_item,show_account_details: visible_accounts.size == <%= file_name %>_item.accounts.size- ) <%%= "%" + ">" %>+ ) %>- <%%= "<" + "%# Compute unlinked accounts (no AccountProvider link) %" + ">" %>- <%%= "<" + "% unlinked_count = #{file_name}_item.unlinked_#{file_name}_accounts&.count || 0 %" + ">" %>+ <%%# Compute unlinked accounts (no AccountProvider link) %>+ <%% unlinked_count = <%= file_name %>_item.unlinked_<%= file_name %>_accounts&.count || 0 %>- <%%= "<" + "% if unlinked_count.to_i > 0 && #{file_name}_item.accounts.empty? %" + ">" %>- <%%= "<" + "%# No accounts imported yet - show prominent setup prompt %" + ">" %>+ <%% if unlinked_count.to_i > 0 && <%= file_name %>_item.accounts.empty? %>+ <%%# No accounts imported yet - show prominent setup prompt %><div class="p-4 flex flex-col gap-3 items-center justify-center">- <p class="text-primary font-medium text-sm"><%%= "<" + "%= t(\".setup_needed\") %" + ">" %></p>- <p class="text-secondary text-sm"><%%= "<" + "%= t(\".setup_description\", linked: #{file_name}_item.accounts.count, total: #{file_name}_item.#{file_name}_accounts.count) %" + ">" %></p>- <%%= "<" + "%= render DS::Link.new(" %>+ <p class="text-primary font-medium text-sm"><%%= t(".setup_needed") %></p>+ <p class="text-secondary text-sm"><%%= t(".setup_description", linked: <%= file_name %>_item.accounts.count, total: <%= file_name %>_item.<%= file_name %>_accounts.count) %></p>+ <%%= render DS::Link.new(text: t(".setup_action"),icon: "plus",variant: "primary",href: setup_accounts_<%= file_name %>_item_path(<%= file_name %>_item),frame: :modal- ) <%%= "%" + ">" %>+ ) %></div>- <%%= "<" + "% elsif unlinked_count.to_i > 0 %" + ">" %>- <%%= "<" + "%# Some accounts imported, more available - show subtle link %" + ">" %>+ <%% elsif unlinked_count.to_i > 0 %>+ <%%# Some accounts imported, more available - show subtle link %><div class="pt-2 border-t border-primary">- <%%= "<" + "%= link_to setup_accounts_#{file_name}_item_path(#{file_name}_item)," %>+ <%%= link_to setup_accounts_<%= file_name %>_item_path(<%= file_name %>_item),data: { turbo_frame: :modal },- class: "flex items-center gap-2 text-sm text-secondary hover:text-primary transition-colors" do <%%= "%" + ">" %>- <%%= "<" + "%= icon \"plus\", size: \"sm\" %" + ">" %>- <span><%%= "<" + "%= t(\".more_accounts_available\", count: unlinked_count) %" + ">" %></span>- <%%= "<" + "% end %" + ">" %>+ class: "flex items-center gap-2 text-sm text-secondary hover:text-primary transition-colors" do %>+ <%%= icon "plus", size: "sm" %>+ <span><%%= t(".more_accounts_available", count: unlinked_count) %></span>+ <%% end %></div>- <%%= "<" + "% elsif #{file_name}_item.accounts.empty? && #{file_name}_item.#{file_name}_accounts.none? %" + ">" %>- <%%= "<" + "%# No provider accounts at all - waiting for sync %" + ">" %>+ <%% elsif <%= file_name %>_item.accounts.empty? && <%= file_name %>_item.<%= file_name %>_accounts.none? %>+ <%%# No provider accounts at all - waiting for sync %><div class="p-4 flex flex-col gap-3 items-center justify-center">- <p class="text-primary font-medium text-sm"><%%= "<" + "%= t(\".no_accounts_title\") %" + ">" %></p>- <p class="text-secondary text-sm"><%%= "<" + "%= t(\".no_accounts_description\") %" + ">" %></p>+ <p class="text-primary font-medium text-sm"><%%= t(".no_accounts_title") %></p>+ <p class="text-secondary text-sm"><%%= t(".no_accounts_description") %></p></div>- <%%= "<" + "% end %" + ">" %>+ <%% end %></div>- <%%= "<" + "% end %" + ">" %>+ <%% end %></details>-<%%= "<" + "% end %" + ">" %>+<%% end %>diff --git a/lib/generators/provider/family/templates/select_existing_account.html.erb.tt b/lib/generators/provider/family/templates/select_existing_account.html.erb.ttindex f08e3ada02..9238f9eac1 100644--- a/lib/generators/provider/family/templates/select_existing_account.html.erb.tt+++ b/lib/generators/provider/family/templates/select_existing_account.html.erb.tt@@ -1,64 +1,64 @@-<%%= "<" + "% content_for :title, t(\"#{file_name}_items.select_existing_account.title\") %" + ">" %>+<%% content_for :title, t("<%= file_name %>_items.select_existing_account.title") %>-<%%= "<" + "%= render DS::Dialog.new do |dialog| %" + ">" %>- <%%= "<" + "% dialog.with_header(title: t(\"#{file_name}_items.select_existing_account.header\")) do %" + ">" %>+<%%= render DS::Dialog.new do |dialog| %>+ <%% dialog.with_header(title: t("<%= file_name %>_items.select_existing_account.header")) do %><div class="flex items-center gap-2">- <%%= "<" + "%= icon \"link\", class: \"text-primary\" %" + ">" %>- <span class="text-primary"><%%= "<" + "%= t(\"#{file_name}_items.select_existing_account.subtitle\", account_name: @account.name) %" + ">" %></span>+ <%%= icon "link", class: "text-primary" %>+ <span class="text-primary"><%%= t("<%= file_name %>_items.select_existing_account.subtitle", account_name: @account.name) %></span></div>- <%%= "<" + "% end %" + ">" %>+ <%% end %>- <%%= "<" + "% dialog.with_body do %" + ">" %>- <%%= "<" + "% if @#{file_name}_accounts.blank? %" + ">" %>+ <%% dialog.with_body do %>+ <%% if @<%= file_name %>_accounts.blank? %><div class="text-center py-8">- <%%= "<" + "%= icon \"alert-circle\", class: \"text-warning mx-auto mb-4\", size: \"lg\" %" + ">" %>- <p class="text-secondary"><%%= "<" + "%= t(\"#{file_name}_items.select_existing_account.no_accounts\") %" + ">" %></p>- <p class="text-sm text-secondary mt-2"><%%= "<" + "%= t(\"#{file_name}_items.select_existing_account.connect_hint\") %" + ">" %></p>- <%%= "<" + "%= link_to t(\"#{file_name}_items.select_existing_account.settings_link\"), settings_providers_path, class: \"btn btn--primary btn--sm mt-4\" %" + ">" %>+ <%%= icon "alert-circle", class: "text-warning mx-auto mb-4", size: "lg" %>+ <p class="text-secondary"><%%= t("<%= file_name %>_items.select_existing_account.no_accounts") %></p>+ <p class="text-sm text-secondary mt-2"><%%= t("<%= file_name %>_items.select_existing_account.connect_hint") %></p>+ <%%= link_to t("<%= file_name %>_items.select_existing_account.settings_link"), settings_providers_path, class: "btn btn--primary btn--sm mt-4" %></div>- <%%= "<" + "% else %" + ">" %>+ <%% else %><div class="space-y-4"><div class="bg-surface border border-primary p-4 rounded-lg mb-4"><p class="text-sm text-primary">- <strong><%%= "<" + "%= t(\"#{file_name}_items.select_existing_account.linking_to\") %" + ">" %></strong>- <%%= "<" + "%= @account.name %" + ">" %>+ <strong><%%= t("<%= file_name %>_items.select_existing_account.linking_to") %></strong>+ <%%= @account.name %></p></div>- <%%= "<" + "% @#{file_name}_accounts.each do |#{file_name}_account| %" + ">" %>- <%%= "<" + "%= form_with url: link_existing_account_#{file_name}_items_path," %>+ <%% @<%= file_name %>_accounts.each do |<%= file_name %>_account| %>+ <%%= form_with url: link_existing_account_<%= file_name %>_items_path,method: :post,local: true,- class: "border border-primary rounded-lg p-4 hover:bg-surface transition-colors" do |form| <%%= "%" + ">" %>- <%%= "<" + "%= hidden_field_tag :account_id, @account.id %" + ">" %>- <%%= "<" + "%= hidden_field_tag :#{file_name}_account_id, #{file_name}_account.id %" + ">" %>+ class: "border border-primary rounded-lg p-4 hover:bg-surface transition-colors" do |form| %>+ <%%= hidden_field_tag :account_id, @account.id %>+ <%%= hidden_field_tag :<%= file_name %>_account_id, <%= file_name %>_account.id %><div class="flex items-center justify-between"><div>- <h4 class="font-medium text-primary"><%%= "<" + "%= #{file_name}_account.name %" + ">" %></h4>+ <h4 class="font-medium text-primary"><%%= <%= file_name %>_account.name %></h4><p class="text-sm text-secondary">- <%%= "<" + "%= t(\"#{file_name}_items.select_existing_account.balance_label\") %" + ">" %>- <%%= "<" + "%= number_to_currency(#{file_name}_account.current_balance || 0, unit: Money::Currency.new(#{file_name}_account.currency || \"USD\").symbol) %" + ">" %>+ <%%= t("<%= file_name %>_items.select_existing_account.balance_label") %>+ <%%= number_to_currency(<%= file_name %>_account.current_balance || 0, unit: Money::Currency.new(<%= file_name %>_account.currency || "USD").symbol) %></p></div>- <%%= "<" + "%= render DS::Button.new(" %>+ <%%= render DS::Button.new(text: t("<%= file_name %>_items.select_existing_account.link_button"),variant: "primary",size: "sm",type: "submit"- ) <%%= "%" + ">" %>+ ) %></div>- <%%= "<" + "% end %" + ">" %>- <%%= "<" + "% end %" + ">" %>+ <%% end %>+ <%% end %></div><div class="mt-6">- <%%= "<" + "%= render DS::Link.new(" %>+ <%%= render DS::Link.new(text: t("<%= file_name %>_items.select_existing_account.cancel_button"),variant: "secondary",href: account_path(@account)- ) <%%= "%" + ">" %>+ ) %></div>- <%%= "<" + "% end %" + ">" %>- <%%= "<" + "% end %" + ">" %>-<%%= "<" + "% end %" + ">" %>+ <%% end %>+ <%% end %>+<%% end %>diff --git a/lib/generators/provider/family/templates/setup_accounts.html.erb.tt b/lib/generators/provider/family/templates/setup_accounts.html.erb.ttindex d52c4282e2..7bec6b41c7 100644--- a/lib/generators/provider/family/templates/setup_accounts.html.erb.tt+++ b/lib/generators/provider/family/templates/setup_accounts.html.erb.tt@@ -1,15 +1,15 @@-<%%= "<" + "% content_for :title, t(\"#{file_name}_items.setup_accounts.title\") %" + ">" %>+<%% content_for :title, t("<%= file_name %>_items.setup_accounts.title") %>-<%%= "<" + "%= render DS::Dialog.new do |dialog| %" + ">" %>- <%%= "<" + "% dialog.with_header(title: t(\"#{file_name}_items.setup_accounts.title\")) do %" + ">" %>+<%%= render DS::Dialog.new do |dialog| %>+ <%% dialog.with_header(title: t("<%= file_name %>_items.setup_accounts.title")) do %><div class="flex items-center gap-2">- <%%= "<" + "%= icon \"settings\", class: \"text-primary\" %" + ">" %>- <span class="text-primary"><%%= "<" + "%= t(\"#{file_name}_items.setup_accounts.subtitle\") %" + ">" %></span>+ <%%= icon "settings", class: "text-primary" %>+ <span class="text-primary"><%%= t("<%= file_name %>_items.setup_accounts.subtitle") %></span></div>- <%%= "<" + "% end %" + ">" %>+ <%% end %>- <%%= "<" + "% dialog.with_body do %" + ">" %>- <%%= "<" + "%= form_with url: complete_account_setup_#{file_name}_item_path(@#{file_name}_item)," %>+ <%% dialog.with_body do %>+ <%%= form_with url: complete_account_setup_<%= file_name %>_item_path(@<%= file_name %>_item),method: :post,local: true,id: "<%= file_name %>-setup-form",@@ -19,84 +19,84 @@loading_button_loading_text_value: t("<%= file_name %>_items.setup_accounts.creating"),turbo_frame: "_top"},- class: "space-y-6" do |form| <%%= "%" + ">" %>+ class: "space-y-6" do |form| %><div class="space-y-4"><div class="bg-surface border border-primary p-4 rounded-lg"><div class="flex items-start gap-3">- <%%= "<" + "%= icon \"info\", size: \"sm\", class: \"text-primary mt-0.5 flex-shrink-0\" %" + ">" %>+ <%%= icon "info", size: "sm", class: "text-primary mt-0.5 flex-shrink-0" %><div><p class="text-sm text-primary">- <%%= "<" + "%= t(\"#{file_name}_items.setup_accounts.instructions\") %" + ">" %>+ <%%= t("<%= file_name %>_items.setup_accounts.instructions") %></p></div></div></div>- <%%= "<" + "% if @unlinked_accounts.empty? %" + ">" %>+ <%% if @unlinked_accounts.empty? %><div class="text-center py-8">- <%%= "<" + "%= icon \"alert-circle\", class: \"text-warning mx-auto mb-4\", size: \"lg\" %" + ">" %>- <p class="text-secondary"><%%= "<" + "%= t(\"#{file_name}_items.setup_accounts.no_accounts\") %" + ">" %></p>+ <%%= icon "alert-circle", class: "text-warning mx-auto mb-4", size: "lg" %>+ <p class="text-secondary"><%%= t("<%= file_name %>_items.setup_accounts.no_accounts") %></p></div>- <%%= "<" + "% else %" + ">" %>+ <%% else %><div data-controller="select-all"><div class="flex items-center justify-between mb-2"><span class="text-sm text-secondary">- <%%= "<" + "%= t(\"#{file_name}_items.setup_accounts.accounts_count\", count: @unlinked_accounts.count) %" + ">" %>+ <%%= t("<%= file_name %>_items.setup_accounts.accounts_count", count: @unlinked_accounts.count) %></span><label class="flex items-center gap-2 text-sm cursor-pointer"><input type="checkbox"id="<%= file_name %>-select-all"data-action="change->select-all#toggle"class="checkbox checkbox--dark">- <span class="text-secondary"><%%= "<" + "%= t(\"#{file_name}_items.setup_accounts.select_all\") %" + ">" %></span>+ <span class="text-secondary"><%%= t("<%= file_name %>_items.setup_accounts.select_all") %></span></label></div><div class="space-y-2 max-h-96 overflow-y-auto">- <%%= "<" + "% @unlinked_accounts.each do |#{file_name}_account| %" + ">" %>- <%%= "<" + "%= tag.label for: dom_id(#{file_name}_account, :acc), class: \"flex items-center gap-3 p-3 border border-primary rounded-lg hover:bg-surface transition-colors cursor-pointer\" do %" + ">" %>- <%%= "<" + "%= check_box_tag \"selected_accounts[]\", #{file_name}_account.id, false, id: dom_id(#{file_name}_account, :acc), class: \"checkbox checkbox--dark\", data: { select_all_target: \"checkbox\" } %" + ">" %>+ <%% @unlinked_accounts.each do |<%= file_name %>_account| %>+ <%%= tag.label for: dom_id(<%= file_name %>_account, :acc), class: "flex items-center gap-3 p-3 border border-primary rounded-lg hover:bg-surface transition-colors cursor-pointer" do %>+ <%%= check_box_tag "selected_accounts[]", <%= file_name %>_account.id, false, id: dom_id(<%= file_name %>_account, :acc), class: "checkbox checkbox--dark", data: { select_all_target: "checkbox" } %><div class="flex-1 min-w-0"><p class="font-medium text-primary truncate">- <%%= "<" + "%= #{file_name}_account.name %" + ">" %>+ <%%= <%= file_name %>_account.name %></p>- <%%= "<" + "% if #{file_name}_account.account_type.present? %" + ">" %>+ <%% if <%= file_name %>_account.account_type.present? %><p class="text-xs text-secondary">- <%%= "<" + "%= #{file_name}_account.account_type.titleize %" + ">" %>+ <%%= <%= file_name %>_account.account_type.titleize %></p>- <%%= "<" + "% end %" + ">" %>+ <%% end %></div><div class="text-right flex-shrink-0"><p class="text-sm font-medium text-primary">- <%%= "<" + "%= number_to_currency(#{file_name}_account.current_balance || 0, unit: Money::Currency.new(#{file_name}_account.currency || \"USD\").symbol) %" + ">" %>+ <%%= number_to_currency(<%= file_name %>_account.current_balance || 0, unit: Money::Currency.new(<%= file_name %>_account.currency || "USD").symbol) %></p><p class="text-xs text-secondary">- <%%= "<" + "%= #{file_name}_account.currency || \"USD\" %" + ">" %>+ <%%= <%= file_name %>_account.currency || "USD" %></p></div>- <%%= "<" + "% end %" + ">" %>- <%%= "<" + "% end %" + ">" %>+ <%% end %>+ <%% end %></div></div>- <%%= "<" + "% end %" + ">" %>+ <%% end %></div><div class="flex gap-3">- <%%= "<" + "%= render DS::Button.new(" %>+ <%%= render DS::Button.new(text: t("<%= file_name %>_items.setup_accounts.import_selected"),variant: "primary",icon: "plus",type: "submit",class: "flex-1",data: { loading_button_target: "button" }- ) <%%= "%" + ">" %>- <%%= "<" + "%= render DS::Link.new(" %>+ ) %>+ <%%= render DS::Link.new(text: t("<%= file_name %>_items.setup_accounts.cancel"),variant: "secondary",href: accounts_path- ) <%%= "%" + ">" %>+ ) %></div>- <%%= "<" + "% end %" + ">" %>- <%%= "<" + "% end %" + ">" %>-<%%= "<" + "% end %" + ">" %>+ <%% end %>+ <%% end %>+<%% end %>diff --git a/test/lib/generators/provider/family_generator_test.rb b/test/lib/generators/provider/family_generator_test.rbindex 057b69f3bf..fd274d2353 100644--- a/test/lib/generators/provider/family_generator_test.rb+++ b/test/lib/generators/provider/family_generator_test.rb@@ -22,6 +22,38 @@ class Provider::FamilyGeneratorTest < ActiveSupport::TestCaseERB.new(template, trim_mode: "-").result(context.instance_eval { binding })end+ # A generated view must be plain ERB once Thor has rendered it: no Ruby string+ # building its tags, at either end, and source that Action View can compile.+ def assert_plain_erb(generated)+ # A tag built from strings renders as text: refuse a string that opens one+ # ("<" + ..., "<%..."), or a concatenation that closes one (..." + ">").+ assert_no_match(/["']<["'] \+|["']<%|%["'] \+ ["']>/, generated)+ assert_parses ActionView::Template::Handlers::ERB::Erubi.new(generated).src+ end++ # Renders a generated view the way Rails would, from a real view path, so relative+ # translation keys and strict locals behave as they do in the app. Redbark has the+ # model, routes, fixtures and translations the generated views call, so it stands+ # in for a new provider here. The view sits at the app's own path, prepended so it+ # renders instead of Redbark's: under any other prefix its relative keys would+ # resolve in a scope the app does not have.+ def render_generated_view(generated, partial: nil, template: nil, **options)+ Dir.mktmpdir do |dir|+ virtual_path = partial ? partial.sub(%r{([^/]+)\z}, '_\\1') : template+ file = File.join(dir, "#{virtual_path}.html.erb")+ FileUtils.mkdir_p(File.dirname(file))+ File.write(file, generated)++ controller = Class.new(ApplicationController) { prepend_view_path dir }+ target = partial ? { partial: partial } : { template: template, layout: false }+ html = controller.renderer.render(**target, **options)+ # Missing keys render a placeholder rather than raising in test, so a key+ # the app does not define would otherwise pass unnoticed.+ assert_not_includes html, "translation_missing"+ html+ end+ end+test "the unlinking scaffold renders to valid Ruby and carries the disposition seam" dorendered = render_template("unlinking_concern.rb.tt", class_name: "Gocardless", file_name: "gocardless")@@ -39,8 +71,8 @@ class Provider::FamilyGeneratorTest < ActiveSupport::TestCasecard = render_template("item_partial.html.erb.tt", file_name: "gocardless")job = render_template("activities_fetch_job.rb.tt", class_name: "Gocardless", file_name: "gocardless")- assert_includes card.lines.first, 'locals: (#{file_name}_item:, visible_accounts:)'- assert_includes card, 'render \\"accounts/index/account_groups\\", accounts: visible_accounts'+ assert_equal "<%# locals: (gocardless_item:, visible_accounts:) %>\n", card.lines.first+ assert_includes card, '<%= render "accounts/index/account_groups", accounts: visible_accounts %>'assert_parses jobassert_not_includes job, '"gocardless_items/gocardless_item"'assert_includes job, "@gocardless_account.gocardless_item&.family&.broadcast_sync_complete"@@ -214,4 +246,79 @@ class Provider::FamilyGeneratorTest < ActiveSupport::TestCaseassert_includes Provider::FamilyGenerator::RESERVED_ITEM_COLUMNS, "family_id"assert_includes Provider::FamilyGenerator::RESERVED_ITEM_COLUMNS, "institution_id"end++ # The old templates built opening tags with "<" + and closing ones with "%" + ">".+ # A string-built closer that ends a multi-line tag breaks the compiled Ruby, so+ # the parse check catches it, but one standing alone still parses and renders a+ # stray %> as text. The check refuses string building at either end.+ test "the plain ERB check refuses a tag built from strings at either end" do+ [+ %(<div>\n<%= "<" + "%= t(\".title\") %" + ">" %>\n</div>\n),+ %(<%= render DS::Link.new(\n text: "x"\n) <%= "%" + ">" %>\n),+ %(<p>x</p>\n<%= "%" + ">" %>\n),+ %(<div>\n<%= "<%" + "= t(\\".title\\") %" + ">" %>\n</div>\n),+ %(<p>x</p>\n<%= '%' + '>' %>\n),+ %(<div>\n<%= "<%" + "= t(\\".title\\") %" + "" + ">" %>\n</div>\n),+ %(<div>\n<%= "<" + "%= t(\\".title\\") %" + "" + ">" %>\n</div>\n)+ ].each do |generated|+ assert_raises(Minitest::Assertion) { assert_plain_erb generated }+ end+ end++ test "the generated item card is plain ERB" do+ generated = render_template("item_partial.html.erb.tt", file_name: "gocardless")++ assert_plain_erb generated+ assert_equal "<%# locals: (gocardless_item:, visible_accounts:) %>\n", generated.lines.first+ assert_includes generated, "<%= tag.div id: dom_id(gocardless_item) do %>"+ end++ test "the generated item card renders the visible accounts it is given" do+ Current.session = Session.create!(user: users(:family_admin))+ item = redbark_items(:one)+ linked = accounts(:depository)+ generated = render_template("item_partial.html.erb.tt", file_name: "redbark")+ render_card = lambda do |visible|+ render_generated_view(generated, partial: "redbark_items/redbark_item",+ locals: { redbark_item: item.reload, visible_accounts: visible.call })+ end++ before = render_card.call(-> { item.accounts.to_a })+ AccountProvider.create!(account: linked, provider: redbark_accounts(:savings_account))+ after = render_card.call(-> { item.accounts.to_a })+ other = render_card.call(-> { [ accounts(:investment) ] })++ assert_includes after, item.name+ assert_not_includes before, linked.name+ assert_includes after, linked.name+ assert_not_includes after, accounts(:investment).name+ # The card lists the accounts it is given, not every account on the connection.+ assert_includes other, accounts(:investment).name+ assert_not_includes other, linked.name+ end++ test "the generated setup accounts view is plain ERB that renders" do+ assert_plain_erb render_template("setup_accounts.html.erb.tt", file_name: "gocardless")++ item = redbark_items(:one)+ html = render_generated_view(render_template("setup_accounts.html.erb.tt", file_name: "redbark"),+ template: "redbark_items/setup_accounts",+ assigns: { redbark_item: item, unlinked_accounts: item.redbark_accounts })++ assert_includes html, redbark_accounts(:savings_account).name+ assert_includes html, "/redbark_items/#{item.id}/complete_account_setup"+ end++ test "the generated select existing account view is plain ERB that renders" do+ assert_plain_erb render_template("select_existing_account.html.erb.tt", file_name: "gocardless")++ account = accounts(:depository)+ html = render_generated_view(render_template("select_existing_account.html.erb.tt", file_name: "redbark"),+ template: "redbark_items/select_existing_account",+ assigns: { account: account, redbark_accounts: [ redbark_accounts(:savings_account) ] })++ assert_includes html, account.name+ assert_includes html, redbark_accounts(:savings_account).name+ assert_includes html, "/redbark_items/link_existing_account"+ endend