parent
a5370d94a3
commit
8699c7f928
@ -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…
Reference in new issue