Rename to RenderHelpers to be more specific about usage

pull/816/head
Stamates 6 years ago
parent a5370d94a3
commit 8699c7f928
  1. 2
      apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex
  2. 4
      apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex
  3. 6
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex
  4. 4
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_token_transfer.html.eex
  5. 4
      apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex
  6. 21
      apps/block_scout_web/lib/block_scout_web/views/render_helpers.ex
  7. 16
      apps/block_scout_web/lib/block_scout_web/views/view_helpers.ex
  8. 22
      apps/block_scout_web/test/block_scout_web/views/render_helpers_test.exs
  9. 48
      apps/block_scout_web/test/block_scout_web/views/view_helpers_test.exs

@ -21,7 +21,7 @@
<div class="col-10 col-md-11"> <div class="col-10 col-md-11">
<div class="row"> <div class="row">
<div class="col-md-7 d-flex flex-column mt-3 mt-md-0"> <div class="col-md-7 d-flex flex-column mt-3 mt-md-0">
<%= address |> BlockScoutWeb.AddressView.address_partial_selector(nil, nil) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= address |> BlockScoutWeb.AddressView.address_partial_selector(nil, nil) |> BlockScoutWeb.RenderHelpers.render_partial() %>
<!-- number of txns for this address --> <!-- number of txns for this address -->
<span> <span>
<span data-test="transaction_count"><%= transaction_count(address) %></span> <span data-test="transaction_count"><%= transaction_count(address) %></span>

@ -6,9 +6,9 @@
<div class="col-md-7 col-lg-8 d-flex flex-column text-nowrap pr-2 pr-sm-2 pr-md-0"> <div class="col-md-7 col-lg-8 d-flex flex-column text-nowrap pr-2 pr-sm-2 pr-md-0">
<%= render BlockScoutWeb.TransactionView, "_link.html", transaction_hash: @internal_transaction.transaction_hash %> <%= render BlockScoutWeb.TransactionView, "_link.html", transaction_hash: @internal_transaction.transaction_hash %>
<span class="text-nowrap"> <span class="text-nowrap">
<%= @internal_transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, assigns[:current_address]) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @internal_transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, assigns[:current_address]) |> BlockScoutWeb.RenderHelpers.render_partial() %>
&rarr; &rarr;
<%= @internal_transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, assigns[:current_address]) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @internal_transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, assigns[:current_address]) |> BlockScoutWeb.RenderHelpers.render_partial() %>
</span> </span>
<span class="tile-title text-truncate mt-3 mt-md-0"> <span class="tile-title text-truncate mt-3 mt-md-0">
<%= BlockScoutWeb.TransactionView.value(@internal_transaction, include_label: false) %> <%= BlockScoutWeb.TransactionView.value(@internal_transaction, include_label: false) %>

@ -17,9 +17,9 @@
<div class="col-md-7 col-lg-8 d-flex flex-column pr-2 pr-sm-2 pr-md-0"> <div class="col-md-7 col-lg-8 d-flex flex-column pr-2 pr-sm-2 pr-md-0">
<%= render "_link.html", transaction_hash: @transaction.hash %> <%= render "_link.html", transaction_hash: @transaction.hash %>
<span class="text-nowrap"> <span class="text-nowrap">
<%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, assigns[:current_address]) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, assigns[:current_address]) |> BlockScoutWeb.RenderHelpers.render_partial() %>
&rarr; &rarr;
<%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, assigns[:current_address]) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, assigns[:current_address]) |> BlockScoutWeb.RenderHelpers.render_partial() %>
</span> </span>
<span class="d-flex flex-md-row flex-column mt-3 mt-md-0"> <span class="d-flex flex-md-row flex-column mt-3 mt-md-0">
<span class="tile-title"> <span class="tile-title">
@ -32,7 +32,7 @@
</div> </div>
<div class="col-md-3 col-lg-2 d-flex flex-row flex-md-column flex-nowrap justify-content-start text-md-right mt-3 mt-md-0"> <div class="col-md-3 col-lg-2 d-flex flex-row flex-md-column flex-nowrap justify-content-start text-md-right mt-3 mt-md-0">
<span class="mr-2 mr-md-0 order-1"> <span class="mr-2 mr-md-0 order-1">
<%= @transaction |> block_number() |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @transaction |> block_number() |> BlockScoutWeb.RenderHelpers.render_partial() %>
</span> </span>
<span class="mr-2 mr-md-0 order-2" data-from-now="<%= block_timestamp(@transaction) %>"></span> <span class="mr-2 mr-md-0 order-2" data-from-now="<%= block_timestamp(@transaction) %>"></span>
<%= if from_or_to_address?(@transaction, assigns[:current_address]) do %> <%= if from_or_to_address?(@transaction, assigns[:current_address]) do %>

@ -11,9 +11,9 @@
</span> </span>
<% end %> <% end %>
<% end %> <% end %>
<%= @token_transfer |> BlockScoutWeb.AddressView.address_partial_selector(:from, @address, true) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @token_transfer |> BlockScoutWeb.AddressView.address_partial_selector(:from, @address, true) |> BlockScoutWeb.RenderHelpers.render_partial() %>
&rarr; &rarr;
<%= @token_transfer |> BlockScoutWeb.AddressView.address_partial_selector(:to, @address, true) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @token_transfer |> BlockScoutWeb.AddressView.address_partial_selector(:to, @address, true) |> BlockScoutWeb.RenderHelpers.render_partial() %>
</span> </span>
<span class="col-12 col-md-7 ml-3 ml-sm-0"> <span class="col-12 col-md-7 ml-3 ml-sm-0">
<%= token_transfer_amount(@token_transfer) %> <%= token_transfer_amount(@token_transfer) %>

@ -26,9 +26,9 @@
<h3 data-test="transaction_detail_hash"><%= @transaction %> </h3> <h3 data-test="transaction_detail_hash"><%= @transaction %> </h3>
<span class="d-block mb-2 text-muted"> <span class="d-block mb-2 text-muted">
<%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, nil) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, nil) |> BlockScoutWeb.RenderHelpers.render_partial() %>
<span class="text-muted"> &rarr; </span> <span class="text-muted"> &rarr; </span>
<%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, nil) |> BlockScoutWeb.ViewHelpers.render_partial() %> <%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, nil) |> BlockScoutWeb.RenderHelpers.render_partial() %>
</span> </span>
<div class="d-flex flex-row justify-content-start text-muted"> <div class="d-flex flex-row justify-content-start text-muted">
<span class="mr-4 text-<%= BlockScoutWeb.TransactionView.type_suffix(@transaction) %>"><%= BlockScoutWeb.TransactionView.transaction_display_type(@transaction) %></span> <span class="mr-4 text-<%= BlockScoutWeb.TransactionView.type_suffix(@transaction) %>"><%= BlockScoutWeb.TransactionView.transaction_display_type(@transaction) %></span>

@ -0,0 +1,21 @@
defmodule BlockScoutWeb.RenderHelpers do
@moduledoc """
Helper functions to render partials from view modules
"""
use BlockScoutWeb, :view
@doc """
Renders html using:
* A list of args including `:view_module` and `:partial` to render a partial with the required keyword list.
* Text that will pass directly through to the template
"""
def render_partial(args) when is_list(args) do
render(
Keyword.get(args, :view_module),
Keyword.get(args, :partial),
args
)
end
def render_partial(text), do: text
end

@ -1,16 +0,0 @@
defmodule BlockScoutWeb.ViewHelpers do
@moduledoc """
Helper functions for views
"""
use BlockScoutWeb, :view
def render_partial(args) when is_list(args) do
render(
Keyword.get(args, :view_module),
Keyword.get(args, :partial),
args
)
end
def render_partial(text), do: text
end

@ -0,0 +1,22 @@
defmodule BlockScoutWeb.RenderHelpersTest do
use BlockScoutWeb.ConnCase, async: true
alias BlockScoutWeb.{BlockView, RenderHelpers}
describe "render_partial/1" do
test "renders text" do
assert "test" == RenderHelpers.render_partial("test")
end
test "renders the proper partial when view_module, partial and args are given" do
block = build(:block)
assert {:safe, _} =
RenderHelpers.render_partial(
view_module: BlockView,
partial: "_link.html",
block: block
)
end
end
end

@ -1,48 +0,0 @@
defmodule BlockScoutWeb.ViewHelpersTest do
use BlockScoutWeb.ConnCase, async: true
alias BlockScoutWeb.{AddressView, BlockView, ViewHelpers}
describe "render_partial/1" do
test "renders text" do
assert "test" == ViewHelpers.render_partial("test")
end
test "renders address _link partial" do
address = build(:address)
assert {:safe, _} =
ViewHelpers.render_partial(
view_module: AddressView,
partial: "_link.html",
address: address,
contract: false,
truncate: false
)
end
test "renders address _responsive_hash partial" do
address = build(:address)
assert {:safe, _} =
ViewHelpers.render_partial(
view_module: AddressView,
partial: "_responsive_hash.html",
address: address,
contract: false,
truncate: false
)
end
test "renders block _link partial" do
block = build(:block)
assert {:safe, _} =
ViewHelpers.render_partial(
view_module: BlockView,
partial: "_link.html",
block: block
)
end
end
end
Loading…
Cancel
Save