Last active
July 7, 2020 21:08
-
-
Save benoittgt/0190f373c0fcad6a78b82f704d618861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
expected = %{ | |
<ul> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
</ul> | |
} | |
template_unindented = %{ | |
<ul> | |
<% list = [1,2,3] %> | |
<% for item in list %> | |
<% if item %> | |
<li><%= item %></li> | |
<% end %> | |
<% end %> | |
</ul> | |
} # space is needed for correct formating | |
template_indented = %{ | |
<ul> | |
<% list = [1,2,3] %> | |
<% for item in list %> | |
<% if item %> | |
<li><%= item %></li> | |
<% end %> | |
<% end %> | |
</ul> | |
} | |
template_indented_with_surrounded_dash = %{ | |
<ul> | |
<%- list = [1,2,3] -%> | |
<%- for item in list -%> | |
<%- if item -%> | |
<li><%= item %></li> | |
<%- end -%> | |
<%- end -%> | |
</ul> | |
} | |
template_indented_with_ending_dash = %{ | |
<ul> | |
<% list = [1,2,3] -%> | |
<% for item in list -%> | |
<% if item -%> | |
<li><%= item %></li> | |
<% end -%> | |
<% end -%> | |
</ul> | |
} | |
templates = [ | |
{ | |
name: 'template_unindented', | |
trim_mode: '<>', | |
content: template_unindented | |
}, | |
{ | |
name: 'template_indented', | |
trim_mode: '<>', | |
content: template_indented | |
}, | |
{ | |
name: 'template_indented', | |
trim_mode: '%>', | |
content: template_indented | |
}, | |
{ | |
name: 'template_indented', | |
trim_mode: '-', | |
content: template_indented | |
}, | |
{ | |
name: 'template_indented_with_surrounded_dash', | |
trim_mode: '-', | |
content: template_indented_with_surrounded_dash | |
}, | |
{ | |
name: 'template_indented_with_ending_dash', | |
trim_mode: '-', | |
content: template_indented_with_ending_dash | |
} | |
] | |
templates.each do |template| | |
puts "π² With trim_mode: #{template[:trim_mode]}, for #{template[:name]}\n\n" | |
pp ERB.new(template[:content], trim_mode: template[:trim_mode]).result | |
puts | |
end | |
puts "π² Expected\n\n" | |
pp expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.