1
votes

I am working in Spree, and I am trying to use Deface to change this

<% if order.has_step?("delivery") %>
  <div class="columns alpha four" data-hook="order-ship-address">
    <h6><%= Spree.t(:shipping_address) %> <%= link_to "(#{Spree.t(:edit)})", checkout_state_path(:address) unless @order.completed? %></h6>
    <%= render :partial => 'spree/shared/address', :locals => { :address => order.ship_address } %>
  </div>
<% end %>

<% if @order.has_step?("delivery") %>
  <div class="columns alpha four">
    <h6><%= Spree.t(:shipments) %> <%= link_to "(#{Spree.t(:edit)})", checkout_state_path(:delivery) unless @order.completed? %></h6>
    <div class="delivery">
      <% order.shipments.each do |shipment| %>
        <div>
          <i class='fa fa-truck'></i>
          <%= Spree.t(:shipment_details, :stock_location => shipment.stock_location.name, :shipping_method => shipment.selected_shipping_rate.name) %>
        </div>
      <% end %>
    </div>
    <%= render(:partial => 'spree/shared/shipment_tracking', :locals => {:order => @order}) if @order.shipped? %>
  </div>
<% end %>

..into this.

<div class="columns alpha four" data-hook="order-ship-address">
  <h6><%= Spree.t(:shipping_address) %> <%= link_to "(#{Spree.t(:edit)})", checkout_state_path(:address) unless @order.completed? %></h6>
  <%= render :partial => 'spree/shared/address', :locals => { :address => order.ship_address } %>
</div>

I've already submitted a pull request about the redundant if statement and adding a data-hook to the second if @order.has_step?("delivery"), but in the meantime I need to write a deface override that will change the page to how I need it to look. I might be able to remove the first if @order.has_step?("delivery") since I think Deface will target the first instance of what I'm talking about on the page if I write

:remove => "erb[silent]:contains('if order.has_step?(\"delivery\"')")

although to be honest the documentation is not very good on that point. Anyway, how can I remove the entirety of the second if statement? There's no data-hook to target it, and using

:remove_content => "erb[silent]:contains('if order.has_step?(\"delivery\"')")

just removes the content of the first if statement. I can't target the first div in the second if statement since there's already a div class="columns alpha four" in the first if statement. I don't want to leave an empty div on the page, so what can I do?

2

2 Answers

0
votes

The two if statements in the referenced code do not refer to the same variable. The first if refers to order, and the second to @order.

When using deface to remove existing sections of erb, the string passed in to contains must exactly match the code you want to move in order for the override to properly locate it. Since the second if statement uses @order, and your matcher doesn't include the @ symbol, it won't remove that particular if statement.

Based on the rspec tests in the deface repo, it doesn't appear that you can currently use multiple matching strings with one override in the remove action. Instead, you'll have to use a second override to mach the second if statement and remove it.

0
votes

The pull request I posted to Spree made this whole issue moot (which you can find here if you're interested: https://github.com/spree/spree/pull/5692 ). Also, it turns out that @order and order function in exactly the same way in that document, and all references to @order are in the process of getting removed from Spree anyway.