Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/code_corps/presenters/image_presenter.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
defmodule CodeCorps.Presenters.ImagePresenter do
alias CodeCorps.{Project, User}
alias CodeCorps.{Organization, Project, User}
alias CodeCorps.Cloudex.CloudinaryUrl

@large_options %{crop: "fill", height: 500, width: 500}

def large(%Organization{} = organization), do: do_large(organization, "organization")
def large(%Project{} = project), do: do_large(project, "project")
def large(%User{} = user), do: do_large(user, "user")

Expand All @@ -12,6 +13,7 @@ defmodule CodeCorps.Presenters.ImagePresenter do

@thumb_options %{crop: "fill", height: 100, width: 100}

def thumbnail(%Organization{} = organization), do: do_thumbnail(organization, "organization")
def thumbnail(%Project{} = project), do: do_thumbnail(project, "project")
def thumbnail(%User{} = user), do: do_thumbnail(user, "user")

Expand Down
10 changes: 3 additions & 7 deletions lib/code_corps_web/views/organization_view.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule CodeCorpsWeb.OrganizationView do
@moduledoc false
alias CodeCorps.Cloudex.CloudinaryUrl
alias CodeCorps.Presenters.ImagePresenter
use CodeCorpsWeb, :view
use JaSerializer.PhoenixView

Expand All @@ -16,11 +16,7 @@ defmodule CodeCorpsWeb.OrganizationView do
has_many :organization_github_app_installations, serializer: CodeCorpsWeb.OrganizationGithubAppInstallationView, identifiers: :always
has_many :projects, serializer: CodeCorpsWeb.ProjectView, identifiers: :always

def icon_large_url(organization, _conn) do
CloudinaryUrl.for(organization.cloudinary_public_id, %{crop: "fill", height: 500, width: 500}, "large", organization.default_color, "organization")
end
def icon_large_url(organization, _conn), do: ImagePresenter.large(organization)

def icon_thumb_url(organization, _conn) do
CloudinaryUrl.for(organization.cloudinary_public_id, %{crop: "fill", height: 100, width: 100}, "thumb", organization.default_color, "organization")
end
def icon_thumb_url(organization, _conn), do: ImagePresenter.thumbnail(organization)
end
10 changes: 5 additions & 5 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ defmodule SeedChangeset do
@moduledoc false

alias CodeCorps.{
TaskList,
Helpers.RandomIconColor,
Helpers.Slug,
Organization,
Services.MarkdownRendererService,
SluggedRoute,
Helpers.Slug,
Helpers.RandomIconColor,
Services.MarkdownRendererService
TaskList
}
alias Ecto.Changeset

Expand All @@ -76,7 +76,7 @@ defmodule SeedChangeset do
|> Changeset.assoc_constraint(:owner)
|> Changeset.put_change(:approved, true)
|> Slug.generate_slug(:name, :slug)
|> RandomIconColor.generate_icon_color(:slugged_route_changeset)
|> RandomIconColor.generate_icon_color(:default_color)

slug = changeset |> Changeset.get_field(:slug)
slugged_route_changeset =
Expand Down
11 changes: 11 additions & 0 deletions test/lib/code_corps/presenters/image_presenter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,33 @@ defmodule CodeCorps.Presenters.ImagePresenterTest do

alias CodeCorps.Presenters.ImagePresenter

@organization build(:organization)
@project build(:project)
@user build(:user)

describe "large/1" do
test "returns proper large image defaults for organization" do
assert ImagePresenter.large(@organization) == "#{Application.get_env(:code_corps, :asset_host)}/icons/organization_default_large_.png"
end

test "returns proper large image defaults for project" do
assert ImagePresenter.large(@project) == "#{Application.get_env(:code_corps, :asset_host)}/icons/project_default_large_.png"
end

test "returns proper large image defaults for user" do
assert ImagePresenter.large(@user) == "#{Application.get_env(:code_corps, :asset_host)}/icons/user_default_large_.png"
end
end

describe "thumbnail/1" do
test "returns proper thumbnail image defaults for organization" do
assert ImagePresenter.thumbnail(@organization) == "#{Application.get_env(:code_corps, :asset_host)}/icons/organization_default_thumb_.png"
end

test "returns proper thumbnail image defaults for project" do
assert ImagePresenter.thumbnail(@project) == "#{Application.get_env(:code_corps, :asset_host)}/icons/project_default_thumb_.png"
end

test "returns proper thumbnail image defaults for user" do
assert ImagePresenter.thumbnail(@user) == "#{Application.get_env(:code_corps, :asset_host)}/icons/user_default_thumb_.png"
end
Expand Down