From fe0cfcd753fe17d05aeda30bdf76963260a4c219 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 7 Jul 2023 15:55:10 +0200 Subject: [PATCH] elia/syntax-tree-erb: [wip] --- Gemfile | 3 + test/fixtures/case_when.html.expected.erb | 24 ++-- test/fixtures/comments-2.html.expected.erb | 2 +- test/fixtures/comments.html.expected.erb | 130 ++++++++++-------- .../complex_case_when.html.expected.erb | 21 ++- .../empty-text-between-erb.html.expected.erb | 3 +- test/fixtures/formatted.html.expected.erb | 10 +- test/fixtures/front-matter.html.expected.erb | 1 - .../long_deep_nested.html.expected.erb | 10 +- test/fixtures/single-2.html.expected.erb | 2 + test/fixtures/single.html.expected.erb | 2 + test/fixtures/with_block.html.expected.erb | 6 +- 12 files changed, 130 insertions(+), 84 deletions(-) diff --git a/Gemfile b/Gemfile index 36e0268..d6261fd 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,6 @@ gemspec gem "rake", "~> 13.0" gem "minitest", "~> 5.0" + +# Dir['test/fixtures/*.expected.erb'].each { File.write _1, SyntaxTree::ERB.format(File.read(p _1.sub('.expected', ''))) rescue puts $! } +gem "w_syntax_tree-erb", "~> 0.9.5" diff --git a/test/fixtures/case_when.html.expected.erb b/test/fixtures/case_when.html.expected.erb index 25b018e..7aa92e6 100644 --- a/test/fixtures/case_when.html.expected.erb +++ b/test/fixtures/case_when.html.expected.erb @@ -1,10 +1,18 @@ -<% case 'fake' %> -<% when 'fake' %> - there -<% when 'something' %> - there -<% when 'else' %> - hi +<% case "fake" %> +<% when "fake" %> + + there + +<% when "something" %> + + there + +<% when "else" %> + + hi + <% else %> - there + + there + <% end %> diff --git a/test/fixtures/comments-2.html.expected.erb b/test/fixtures/comments-2.html.expected.erb index 441c788..d2d5358 100644 --- a/test/fixtures/comments-2.html.expected.erb +++ b/test/fixtures/comments-2.html.expected.erb @@ -1,7 +1,7 @@ <%# link_to 'Approve', some_path, class: 'something', disabled: disabled %> <%#= link_to 'Approve', some_path, class: 'something', disabled: disabled %> <%#- link_to 'Approve', some_path, class: 'something', disabled: disabled %> -<%-# link_to 'Approve', some_path, class: 'something', disabled: disabled %> +<%- # link_to 'Approve', some_path, class: 'something', disabled: disabled %> <%# if smth %> <%#else %> diff --git a/test/fixtures/comments.html.expected.erb b/test/fixtures/comments.html.expected.erb index a4b7c62..1b0ee6b 100644 --- a/test/fixtures/comments.html.expected.erb +++ b/test/fixtures/comments.html.expected.erb @@ -1,64 +1,86 @@ -<%# -This fails -hey -hey -hey -hey %> +<% + # + This fails + hey + hey + hey + hey +%> -<%# -This fails -hey -hey -hey -hey %> +<% + # + This fails + hey + hey + hey + hey +%> -<%# -This fails -hey -hey -hey -hey %> +<% + # + This fails + hey + hey + hey + hey +%> -<%# This fails -This fails -hey -hey -hey -hey %> +<% + # This fails + This fails + hey + hey + hey + hey +%> -<%# This fails -This fails -hey -hey -hey -hey %> +<% + # This fails + This fails + hey + hey + hey + hey +%> -<%# This fails -This fails -hey -hey -hey -hey %> +<% + # This fails + This fails + hey + hey + hey + hey +%> -<%#This fails -This fails -hey -hey -hey -hey %> +<% + #This fails + This fails + hey + hey + hey + hey +%> -<%# This fails -This fails -hey -hey -hey -hey %> +<% + # This fails + This fails + hey + hey + hey + hey +%> -<%# -hey %> +<% + # + hey +%> -<%# -hey %> +<% + # + hey +%> -<%# -hey %> +<% + # + hey +%> diff --git a/test/fixtures/complex_case_when.html.expected.erb b/test/fixtures/complex_case_when.html.expected.erb index efb2be4..6e3a32a 100644 --- a/test/fixtures/complex_case_when.html.expected.erb +++ b/test/fixtures/complex_case_when.html.expected.erb @@ -1,18 +1,25 @@
<% if payment_method.present? %> <% case payment_method.class.to_s %> - <% when 'Foo::PaymentMethod::FooCreditCard' %> + <% when "Foo::PaymentMethod::FooCreditCard" %> <% if payment_method.active %> - *<%= payment_source.last_digits %> - <%= payment_source.month %>/<%= payment_source.year %> + * + <%= payment_source.last_digits %> + <%= payment_source.month %> + / + <%= payment_source.year %> <% else %> <%= t(".payment.card_removed_or_expired") %> <% end %> - <% when 'Foo::PaymentMethod::Bar' %> - <%= t(".payment.invoice") %> - <% when 'Foo::PaymentMethod' %> - <%= t(".payment.stripe_invoice") %> + <% when "Foo::PaymentMethod::Bar" %> + + <%= t(".payment.invoice") %> + + <% when "Foo::PaymentMethod" %> + + <%= t(".payment.stripe_invoice") %> + <% else %> <% Rails.logger.error.report( StandardError.new( diff --git a/test/fixtures/empty-text-between-erb.html.expected.erb b/test/fixtures/empty-text-between-erb.html.expected.erb index b83f97c..6103c78 100644 --- a/test/fixtures/empty-text-between-erb.html.expected.erb +++ b/test/fixtures/empty-text-between-erb.html.expected.erb @@ -1,3 +1,4 @@ <%= render Component.new do %> ยท - <%= link_to "foo", bar_path %><% end %> + <%= link_to "foo", bar_path %> +<% end %> diff --git a/test/fixtures/formatted.html.expected.erb b/test/fixtures/formatted.html.expected.erb index 2adfd9c..d770e1b 100644 --- a/test/fixtures/formatted.html.expected.erb +++ b/test/fixtures/formatted.html.expected.erb @@ -1,6 +1,6 @@ <% link_to "Very long string here and there", -very_very_very_long_long_long_pathhhhhh_here, -opt: "212", -options: "222sdasdasd", -class: " 322 ", -dis: diss %> + very_very_very_long_long_long_pathhhhhh_here, + opt: "212", + options: "222sdasdasd", + class: " 322 ", + dis: diss %> diff --git a/test/fixtures/front-matter.html.expected.erb b/test/fixtures/front-matter.html.expected.erb index 3400f12..c1f5142 100644 --- a/test/fixtures/front-matter.html.expected.erb +++ b/test/fixtures/front-matter.html.expected.erb @@ -6,7 +6,6 @@ Baz: | foo-bar foo bar --- - <% flash.each do |type, data| %> <%= render AlertComponent.new(type: type, data: data) %> diff --git a/test/fixtures/long_deep_nested.html.expected.erb b/test/fixtures/long_deep_nested.html.expected.erb index 17d219d..84e5807 100644 --- a/test/fixtures/long_deep_nested.html.expected.erb +++ b/test/fixtures/long_deep_nested.html.expected.erb @@ -17,11 +17,11 @@
<% link_to "Very long long long long long long long long string here and there", - very_very_very_long_long_long_pathhhhhh_here, - opt: "212", - options: "222sdasdasd", - class: " 322 ", - dis: diss %> + very_very_very_long_long_long_pathhhhhh_here, + opt: "212", + options: "222sdasdasd", + class: " 322 ", + dis: diss %> <% link_to "string", path, opt: "212", options: "222sdasdasd" %> diff --git a/test/fixtures/single-2.html.expected.erb b/test/fixtures/single-2.html.expected.erb index 7400881..48719e9 100644 --- a/test/fixtures/single-2.html.expected.erb +++ b/test/fixtures/single-2.html.expected.erb @@ -1 +1,3 @@ + <%= link_to "New Order", class: "btn btn-success" %> + diff --git a/test/fixtures/single.html.expected.erb b/test/fixtures/single.html.expected.erb index 4cd8f11..be8d197 100644 --- a/test/fixtures/single.html.expected.erb +++ b/test/fixtures/single.html.expected.erb @@ -1 +1,3 @@ + <%= link_to "New Order", new_order_path, class: "btn btn-success" %> + diff --git a/test/fixtures/with_block.html.expected.erb b/test/fixtures/with_block.html.expected.erb index 81eab35..501eebe 100644 --- a/test/fixtures/with_block.html.expected.erb +++ b/test/fixtures/with_block.html.expected.erb @@ -1,3 +1,5 @@ -<% foo.each do |bar| %> -

<%= baz %>

+<% foo.each do |bar|%> +

+ <%= baz %> +

<% end %>