-
-
Save scrogson/e31216e71b1bfbdc871f to your computer and use it in GitHub Desktop.
Revisions
-
Paul Smith revised this gist
Mar 18, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,9 @@ defmodule MyApp.Web do def view do quote do # Default code. # You would probably extract these functions to a module. def put_assoc(map, :user, user) do Map.put(map, :user, UserView.render("show.json", %{data: user}) end -
Paul Smith revised this gist
Mar 18, 2015 . 2 changed files with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,11 @@ defmodule MyApp.CommentView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("index.json", %{data: comments}) do for comment <- comments, do: render("show.json", %{data: comment}) end def render("show.json", %{data: comment}) do comment |> Map.take(@attributes) 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ defmodule MyApp.UserView do use MyApp.Web, :view @attributes ~W(id name inserted_at) -
Paul Smith revised this gist
Mar 18, 2015 . 3 changed files with 26 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,6 @@ defmodule MyApp.CommentView do def render("show.json", %{data: comment}) do comment |> Map.take(@attributes) |> put_assoc(:user, comment.user) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,14 @@ defmodule MyApp.MyModelView do use MyApp.Web, :view @attributes ~W(id body title inserted_at) def render("show.json", %{data: my_model}) my_model |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) |> put_assoc(:user, my_model.user) # Or you could do # |> put_assoc(:user, my_model.user, :lite) |> put_assoc(:comments, my_model.comments) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ defmodule MyApp.Web do def view do quote do # Default code def put_assoc(map, :user, user) do Map.put(map, :user, UserView.render("show.json", %{data: user}) end # Need to customize more? def put_assoc(map, :user, user, :lite) do Map.put(map, :user, UserView.render("show_lite.json", %{data: user}) end def put_assoc(map, :comments, comments) do Map.put(map, :comments, CommentView.render("index.json", %{data: comments}) end end end end -
Paul Smith revised this gist
Mar 18, 2015 . 3 changed files with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,12 +2,12 @@ defmodule MyApp.CommentView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("index.json", %{data: comments}) do for comment <- comments, do: render("show.json", %{data: comment}) end def render("show.json", %{data: comment}) do comment |> Map.take(@attributes) |> Map.put(:user, UserView.render('show_lite.json', %{data: data.user}) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,6 @@ defmodule MyApp.MyModelView do |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) |> Map.put(:user, UserView.render("show.json", %{data: my_model.user}) |> Map.put(:comments, CommentView.render("index.json", %{data: my_model.comments}) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ defmodule MyApp.UserView do def render("show.json", %{data: user}) render("show_lite.json", %{data: user}) |> Map.put(:image, ImageView.render("show.json", %{data: user.image}) end def render("show_lite.json", %{data: user}) -
Paul Smith revised this gist
Mar 18, 2015 . 3 changed files with 5 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,7 @@ defmodule MyApp.CommentView do @attributes ~W(id name inserted_at) def render("show.json", %{data: comments}) when is_list(comments) do for comment <- comments, do: render("show.json", %{data: comment}) end def render("show.json", %{data: comment}) do comment 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ defmodule MyApp.MyModelView do my_model |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) |> Map.put(:user, UserView.render("show.json", %{data: my_model.user}) |> Map.put(:comments, CommentView.render("show.json", %{data: my_model.comments}) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -3,11 +3,11 @@ defmodule MyApp.UserView do @attributes ~W(id name inserted_at) def render("show.json", %{data: user}) render("show_lite.json", %{data: user}) |> Map.put(:image, ImageView.render("show.json", data: user.image) end def render("show_lite.json", %{data: user}) user |> Map.take(@attributes) end -
Paul Smith revised this gist
Mar 18, 2015 . 3 changed files with 6 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,12 @@ defmodule MyApp.CommentView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", %{data: comments}) when is_list(comments) do for comment <- comments do render("show.json", data: comment) end end def render("show.json", %{data: comment}) do comment |> Map.take(@attributes) |> Map.put(:user, UserView.render('show_lite.json', data: data.user) 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ defmodule MyApp.MyModelView do use MyApp.Web, :view @attributes ~W(id body title inserted_at) def render("show.json", %{data: my_model}) my_model |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) 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 charactersOriginal file line number Diff line number Diff line change @@ -2,12 +2,12 @@ defmodule MyApp.UserView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", %{data: user}) render("show.json", %{data: user}, :lite) |> Map.put(:image, ImageView.render("show.json", data: user.image) end def render("show.json", %{data: user}, :lite) user |> Map.take(@attributes) end -
Paul Smith revised this gist
Mar 18, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,8 @@ defmodule MyApp.CommentView do @attributes ~W(id name inserted_at) def render("show.json", data: comments) when is_list(comments) do for comment <- comments do render("show.json", data: comment) end end -
Paul Smith revised this gist
Mar 18, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,9 +2,9 @@ defmodule MyApp.CommentView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", data: comments) when is_list(comments) do for c <- comments do render("show.json", data: c) end end -
Paul Smith revised this gist
Mar 18, 2015 . 3 changed files with 12 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,14 +2,14 @@ defmodule MyApp.CommentView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", data: comment) when is_list(comment) do for c <- data do render("show.json", data: data) end end def render("show.json", data: comment) do comment |> Map.take(@attributes) |> Map.put(:user, UserView.render('show_lite.json', data: data.user) end 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 charactersOriginal file line number Diff line number Diff line change @@ -2,11 +2,11 @@ defmodule MyApp.MyModelView do use MyApp.Web, :view @attributes ~W(id body title inserted_at) def render("show.json", data: my_model) my_model |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) |> Map.put(:user, UserView.render("show.json", data: my_model.user) |> Map.put(:comments, CommentView.render("show.json", data: my_model.comments) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,13 @@ defmodule MyApp.UserView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", data: user) render("show_lite.json", data: user) |> Map.put(:image, ImageView.render("show.json", data: user.image) end def render("show_lite.json", data: user) user |> Map.take(@attributes) end end -
Jason S. revised this gist
Mar 18, 2015 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,4 @@ defmodule MyApp.UserView do data |> Map.take(@attributes) end end -
Jason S. revised this gist
Mar 18, 2015 . 3 changed files with 13 additions and 18 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,17 +2,15 @@ defmodule MyApp.CommentView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", data: data) when is_list(data) do for c <- data do render("show.json", data: data) end end def render("show.json", data: data) do data |> Map.take(@attributes) |> Map.put(:user, UserView.render('show_lite.json', data: data.user) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,11 @@ defmodule MyApp.MyModelView do use MyApp.Web, :view @attributes ~W(id body title inserted_at) def render("show.json", data: data) data |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) |> Map.put(:user, UserView.render("show.json", data: data.user) |> Map.put(:comments, CommentView.render("show.json", data: data.comments) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -2,16 +2,15 @@ defmodule MyApp.UserView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", data: data) render("show_lite.json", data: data) |> Map.put(:image, ImageView.render("show.json", data: data.image) end def render("show_lite.json", data: data) data |> Map.take(@attributes) end end -
Jason S. revised this gist
Mar 17, 2015 . 3 changed files with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,6 @@ defmodule MyApp.CommentView do def encode(data) do data |> Map.take(@attributes) |> Map.put(:user, UserView.encode_lite(data.user) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ defmodule MyApp.MyModelView do data |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) |> Map.put(:user, UserView.encode(data.user) |> Map.put(:comments, CommentView.encode(data.comments) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,6 @@ defmodule MyApp.UserView do def encode(data) do data |> encode_lite() |> Map.put(:image, ImageView.encode(data.image) end end -
Jason S. revised this gist
Mar 17, 2015 . 3 changed files with 11 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,5 +13,6 @@ defmodule MyApp.CommentView do def encode(data) do data |> Map.take(@attributes) |> Map.put(:user, MyApp.UserView.encode_lite(data.user) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,14 @@ defmodule MyApp.MyModelView do use MyApp.Web, :view @attributes ~W(id body title inserted_at) def render("show.json", data: data), do: encode(data) def encode(data) do data |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) |> Map.put(:user, MyApp.UserView.encode(data.user) |> Map.put(:comments, MyApp.CommentView.encode(data.comments) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,14 @@ defmodule MyApp.UserView do def render("show.json", data: data), do: encode(data) def encode_lite(data) do data |> Map.take(@attributes) end def encode(data) do data |> encode_lite() |> Map.put(:image, MyApp.ImageView.encode(data.image) end end -
Jason S. revised this gist
Mar 17, 2015 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ defmodule MyApp.CommentView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", data: data), do: encode(data) def encode(data) when is_list(data) do for c <- data do encode(data) end end def encode(data) do data |> Map.take(@attributes) end end -
Jason S. revised this gist
Mar 17, 2015 . 2 changed files with 14 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,9 @@ defmodule MyApp.MyModelView do use MyApp.Web, :view @attributes ~W(id body title user comments inserted_at) def render("show.json", data: data), do: encode(data) def encode(data) do data |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ defmodule MyApp.UserView do use MyApp.Web, :view @attributes ~W(id name inserted_at) def render("show.json", data: data), do: encode(data) def encode(data) do data |> Map.take(@attributes) end end -
Jason S. revised this gist
Mar 17, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ defmodule MyApp.MyModelView do @attributes ~W(id body title user comments inserted_at) def render("show.json", data: data) do data |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) end -
Jason S. created this gist
Mar 17, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ defmodule MyApp.MyModelView do use MyApp.Web, :view @attributes ~W(id body title user comments inserted_at) def render("show.json", data: data) do comment |> Map.take(@attributes) |> Map.update!(:title, &String.capitalize) end end