This file contains 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 characters
defmodule App.ModelHelpers.HasImageHelper do | |
alias App.Repo | |
alias App.Image | |
defmacro __using__(_) do | |
quote do | |
def get_image_url(model, field, base_path \\ "", default_image \\ nil) do | |
field = if is_bitstring(field), do: String.to_atom(field), else: field |
This file contains 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 characters
defmodule App.Helpers.ImageHelper do | |
#https://github.com/route/mogrify | |
import Mogrify | |
def thumb(src, dest, width, height) do | |
open(src) | |
|> resize_to_fill("#{width}x#{height}") | |
|> gravity("center") | |
|> save(path: dest) |
This file contains 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 characters
defmodule App.Image do | |
use App.Web, :model | |
alias App.Image | |
alias App.Repo | |
alias App.Helpers.FileHelper | |
alias App.Helpers.ImageHelper | |
schema "images" do | |
field :type, :string |
This file contains 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 characters
defmodule App.Image do | |
# updates from part #1 | |
# full image code https://gist.github.com/radzserg/3abc7a6fdac6fb98af8607d1b5a0cdaf | |
alias App.Helpers.FileHelper | |
alias App.Helpers.ImageHelper | |
@doc """ | |
Return resized image from parent image | |
""" |
This file contains 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 characters
defmodule App.Helpers.FileHelper do | |
def get_mime!(path) do | |
{result, 0} = System.cmd("file", ["--mime-type"|[path]]) | |
result | |
|> String.split(":") | |
|> List.last | |
|> String.trim | |
|> String.downcase | |
end |
This file contains 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 characters
defmodule App.ModelHelpers.HasImageHelper do | |
alias App.Repo | |
alias App.Image | |
import Ecto.Changeset, only: [cast: 3] | |
defmacro __using__(config) do | |
quote do |
This file contains 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 characters
defmodule App.Helpers.ViewHelpers do | |
alias App.Repo | |
alias App.Image | |
defmacro __using__(_) do | |
quote do | |
def image_url(model, field, options \\ %{}) do | |
module = model.__struct__ |
This file contains 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 characters
<?php | |
if (!empty($filterParams['q'])) { | |
$query = CMap::mergeArray($query, [ | |
[ | |
'bool' => [ | |
'should' => [ | |
['match' => ['name' => ['query' => $filterParams['q'], 'boost' => 5]]], | |
['match' => ['short_description' => ['query' => $filterParams['q'], 'boost' => 3]]], | |
['match' => ['tag_names' => ['query' => $filterParams['q'], 'boost' => 1]]] | |
] |
This file contains 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 characters
defmodule App.Es.EsClient do | |
@config Application.get_env(:app, :es) | |
@doc """ | |
Builds index/type/id|action URL. Like index-prefix/index/id|action | |
""" | |
def build_url(index, id_or_action \\ nil, type \\ nil) do | |
host = @config[:host] | |
index_prefix = @config[:index_prefix] |
This file contains 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 characters
defmodule App.Es.DocumentBehavior do | |
@doc """ | |
Build es document body | |
""" | |
@callback index() :: string | |
@doc """ | |
Build es document body | |
""" |