Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use syntax-tree-erb #25

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 16 additions & 8 deletions test/fixtures/case_when.html.expected.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<% case 'fake' %>
<% when 'fake' %>
<span>there</span>
<% when 'something' %>
<span>there</span>
<% when 'else' %>
<span>hi</span>
<% case "fake" %>
<% when "fake" %>
<span>
there
</span>
<% when "something" %>
<span>
there
</span>
<% when "else" %>
<span>
hi
</span>
<% else %>
<span>there</span>
<span>
there
</span>
<% end %>
2 changes: 1 addition & 1 deletion test/fixtures/comments-2.html.expected.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
130 changes: 76 additions & 54 deletions test/fixtures/comments.html.expected.erb
Original file line number Diff line number Diff line change
@@ -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
%>
21 changes: 14 additions & 7 deletions test/fixtures/complex_case_when.html.expected.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<div>
<% if payment_method.present? %>
<% case payment_method.class.to_s %>
<% when 'Foo::PaymentMethod::FooCreditCard' %>
<% when "Foo::PaymentMethod::FooCreditCard" %>
<% if payment_method.active %>
<span class="card-icon <%= payment_source.cc_type %>"></span>
*<%= 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' %>
<span><%= t(".payment.invoice") %></span>
<% when 'Foo::PaymentMethod' %>
<span><%= t(".payment.stripe_invoice") %></span>
<% when "Foo::PaymentMethod::Bar" %>
<span>
<%= t(".payment.invoice") %>
</span>
<% when "Foo::PaymentMethod" %>
<span>
<%= t(".payment.stripe_invoice") %>
</span>
<% else %>
<% Rails.logger.error.report(
StandardError.new(
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/empty-text-between-erb.html.expected.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= render Component.new do %>
·
<%= link_to "foo", bar_path %><% end %>
<%= link_to "foo", bar_path %>
<% end %>
10 changes: 5 additions & 5 deletions test/fixtures/formatted.html.expected.erb
Original file line number Diff line number Diff line change
@@ -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 %>
1 change: 0 additions & 1 deletion test/fixtures/front-matter.html.expected.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Baz: |
foo-bar
foo bar
---

<body class="h-full">
<% flash.each do |type, data| %>
<%= render AlertComponent.new(type: type, data: data) %>
Expand Down
10 changes: 5 additions & 5 deletions test/fixtures/long_deep_nested.html.expected.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<div>
<div>
<% 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" %>

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/single-2.html.expected.erb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

<%= link_to "New Order", class: "btn btn-success" %>

2 changes: 2 additions & 0 deletions test/fixtures/single.html.expected.erb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

<%= link_to "New Order", new_order_path, class: "btn btn-success" %>

6 changes: 4 additions & 2 deletions test/fixtures/with_block.html.expected.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% foo.each do |bar| %>
<p><%= baz %></p>
<% foo.each do |bar|%>
<p>
<%= baz %>
</p>
<% end %>