Git Product home page Git Product logo

phoenix_view's People

Contributors

benjamintanweihao avatar boone avatar bryansray avatar chrismccord avatar doomspork avatar fertapric avatar gazler avatar gjaldon avatar gmile avatar holandes22 avatar inoas avatar jakgajtk avatar jayjun avatar josevalim avatar koudelka avatar lancehalvorsen avatar lexmag avatar maclover7 avatar michallepicki avatar michalmuskala avatar mmartinson avatar mnussbaumer avatar mosic avatar richardkmichael avatar rktjmp avatar snewcomer avatar sparkertime avatar szajbus avatar szymon-jez avatar wojtekmach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phoenix_view's Issues

[question] Should the `:as` option of render_one/4 and render_many/4 be passed to render?

I noticed that when we call render_one/4 or render_many/4 with the :as option it gets passed down to render.

Is this intentional? If not, would you welcome a PR to remove it?

Example:

render_many([user], MyApp.UserView, "data.text", as: :data)

Diff to quickly reproduce with the tests of this repo:

diff --git a/test/fixtures/views.exs b/test/fixtures/views.exs
index 1cec333..b8302f4 100644
--- a/test/fixtures/views.exs
+++ b/test/fixtures/views.exs
@@ -44,7 +44,8 @@ defmodule MyApp.UserView do
     "show user: " <> user.name
   end

-  def render("data.text", %{data: data}) do
+  def render("data.text", %{data: data} = some) do
+    IO.inspect(some)
     "show data: " <> data.name
   end

It prints:

%{as: :data, data: %MyApp.User{name: "name"}}
#   ^--- wasn't expecting to see an :as key here

Migration guide doesn't address controller breakage

I'm trying to migrate a Phoenix.View to Phoenix.Component as described in the migration guide.

A small obstacle is that the guide says embed_template "../templates/my" but the correct code seems to be embed_templates "../templates/my/*".

The larger obstacle is that Phoenix.Controller.render/3 breaks because MyAppWeb.MyView.render/2 is undefined, and the guide doesn't offer any way to resolve this problem. The guide should explain what to do to handle this.

Phoenix.view.render_to_string/3 not working for text files

System

Elixir 1.12.2 - OTP 24
phoenix 1.6.6
phoenix_view 1.1.0

ArchLinux 5.15.7-arch1-1

Problem

Phoenix.View.render_to_string/3 fails when template filename does not have .html.(h)eex extension with the following stacktrace:

** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an iodata term

    :erlang.iolist_to_binary({:safe, ["Hello from TEXT\n"]})
    (phoenix_view 1.1.0) lib/phoenix/view.ex:480: Phoenix.View.render_to_string/3

This behavior is consistent whether I use template files or define render methods directly in view module.

example

defmodule SomeAppWeb.EmailView do
  @moduledoc """
  Email view
  """

  use SomeAppWeb, :view

  # WORKS!
  # iex > Phoenix.View.render(SomeAppWeb.EmailView, "contact_form.html", %{})
  #   "Hello from HTML\n"
  def render("contact_form.html", assigns) do
    ~H"""
    Hello from HTML
    """
  end

  # DOES NOT WORK!
  # iex > Phoenix.View.render(SomeAppWeb.EmailView, "contact_form.text", %{})
  #   ** (ArgumentError) errors were found at the given arguments:
  #
  # * 1st argument: not an iodata term
  #
  #   :erlang.iolist_to_binary({:safe, ["Hello from TEXT\n"]})
  #   (phoenix_view 1.1.0) lib/phoenix/view.ex:480: Phoenix.View.render_to_string/3
  def render("contact_form.text", assigns) do
    ~H"""
    Hello from TEXT
    """
  end
end

Expectation

Phoenix.View.render_to_string/3 should render heex regardless of the extension.

Missing changelog / suggest creating a specific upgrade guide.

๐Ÿ‘‹ Thanks for all your work, from investigating the changes in version 2 I noticed that there is no changelog entry, it'd be great if there could be one put together with all the changes, it'd also be nice if there was a seperate pulled out upgrade guide for the docs, so its easy to find the info on how to upgrade from 1.x to 2.x.

Render issues

Phoenix 1.6.2
PhoenixLiveView 0.17.1
Elixir 1.12.3
MacOS 11

Provided a gist for reference at the bottom.

Problem

Template is rendering incorrectly. It's duplicating lines instead.

If I run this multiple time I get duplication repeating at different places rather than the actual render call rendering the specific file reference. It seems to happen on gettext calls.

The bread crumbs work in different places throughout the project, for some reason this specific location is broken.

<%= render(AdminWeb.BreadcrumbsView, "view.html", %{conn: @conn, breadcrumbs: breadcrumbs}) %>
<%= render(AdminWeb.BreadcrumbsView, "view.html", %{conn: @conn, breadcrumbs: breadcrumbs}) %>
<%= render(AdminWeb.BreadcrumbsView, "view.html", %{conn: @conn, breadcrumbs: breadcrumbs}) %>
<%= render(AdminWeb.BreadcrumbsView, "view.html", %{conn: @conn, breadcrumbs: breadcrumbs}) %>

This is part of what gets rendered:

Draft Details

      <span class="badge badge-warning" style="float:right;">
Draft
      </span>

Name
 value="Form 1"
Schema
<br><br>
<form action="/team/Bf41mGmPuIGOwl4y/draft/update/zxrZ3U4UFNCWBom5" method="post"><input name="_csrf_token" type="hidden" value="BhkEJzJSDgoFDhYIOExDLB0lBD0jEwInuXwux3JbpGsxVxskwiBlpXEt">
  <h2>
Draft Details

      <span class="badge badge-warning" style="float:right;">
Draft
      </span>

  </h2>
  <br>
  <div class="table-responsive">
    <table class="table table-striped">
      <tbody>
        <tr>
          <th>Name</th>
          <td><input type="text" name="data[draft][name]" value="Form 1" class='form-control'></td>
        </tr>
        <tr>
          <th>Schema</th>
          <td>
            <textarea rows="10" name="data[draft][schema]" class='form-control'>
               redacted
            </textarea>
          </td>
        </tr>
      </tbody>
    </table>
  </div>

This initial piece

Draft Details

      <span class="badge badge-warning" style="float:right;">
Draft
      </span>

Name
 value="Form 1"
Schema

should be what's written in the breadcrumbs file shown in the gist.

Expectation

The code that's supposed to be rendered gets executed, rendered, and placed in the right location.

https://gist.github.com/k-cross/3f8eaf7f5d9e40e78b2b025a47f8cc76

Thank you for the project and your help! Let me know if there's anything else I can do to provide context.

first release?

I am reviewing the docs for the Phoenix guide, and I would like to link to the docs.
Is there any planned release in the near feature?
If note I can leave an internal note and update later the docs when the first version of this library is published.
Thank you.

Dialyzer is complaining after version update

After these changes: v1.1.0...v1.1.1

Dialyzer started complaining that template_not_found/2 has no local return:

lib/namespace_web/views/error_view.ex:2:no_return
Function template_not_found/2 has no local return.
________________________________________________________________________________
lib/namespace_web/views/layout_view.ex:2:no_return
Function template_not_found/2 has no local return.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

It complains about this method for every single :view file.

Should we add this method to all view files?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.