Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit b1db245

Browse files
committed
Merge branch 'new-editor' into dev
2 parents fd5664c + 4c86d02 commit b1db245

37 files changed

+1503
-45
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ test:
166166
test.watch:
167167
mix test.watch
168168
test.watch.wip:
169-
mix test.watch --only wip
169+
# work around, see: https://elixirforum.com/t/mix-test-file-watch/12298/2
170+
mix test --listen-on-stdin --stale --trace --only wip
171+
# test.watch not work now, see: https://github.com/lpil/mix-test.watch/issues/116
172+
# mix test.watch --only wip --stale
170173
test.watch.wip2:
174+
mix test --listen-on-stdin --stale --trace --only wip2
175+
# mix test.watch --only wip2
171176
mix test.watch --only wip2
172177
test.watch.bug:
173178
mix test.watch --only bug

config/config.exs

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ config :groupher_server, GroupherServerWeb.Endpoint,
1313
url: [host: "localhost"],
1414
secret_key_base: "Ru3N3sehqeuFjBV2Z6k7FuyA59fH8bWm8D4aZWu2RifP3xKMBYo3YRILrnXAGezM",
1515
render_errors: [view: GroupherServerWeb.ErrorView, accepts: ~w(json)],
16-
pubsub: [name: GroupherServer.PubSub, adapter: Phoenix.PubSub.PG2]
16+
pubsub_server: GroupherServer.PubSub
1717

1818
# Configures Elixir's Logger
1919
config :logger, :console,
@@ -22,7 +22,9 @@ config :logger, :console,
2222

2323
config :phoenix, :json_library, Jason
2424

25-
config :groupher_server, :mix_test_watch, exclude: [~r/docs\/.*/, ~r/deps\/.*/, ~r/mix.exs/]
25+
config :groupher_server, :mix_test_watch,
26+
exclude: [~r/docs\/.*/, ~r/deps\/.*/, ~r/mix.exs/],
27+
clear: true
2628

2729
config :pre_commit, commands: ["format"], verbose: false
2830
# Import environment specific config. This must remain at the bottom

lib/groupher_server/accounts/delegates/customization.ex

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ defmodule GroupherServer.Accounts.Delegate.Customization do
4545
@doc """
4646
add custom setting to user
4747
"""
48+
4849
# for map_size
4950
# see https://stackoverflow.com/questions/33248816/pattern-match-function-against-empty-map
5051

lib/groupher_server/application.ex

+3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ defmodule GroupherServer.Application do
44

55
# See https://hexdocs.pm/elixir/Application.html
66
# for more information on OTP Applications
7+
@spec start(any, any) :: {:error, any} | {:ok, pid}
78
def start(_type, _args) do
89
import Supervisor.Spec
910
import Cachex.Spec
1011

1112
# Define workers and child supervisors to be supervised
1213
children = [
14+
# Start the PubSub system
15+
{Phoenix.PubSub, name: MyApp.PubSub},
1316
# Start the Ecto repository
1417
supervisor(GroupherServer.Repo, []),
1518
# Start the endpoint when the application starts

lib/groupher_server/mailer/email.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule GroupherServer.Email do
1111

1212
alias Accounts.User
1313
alias Billing.BillRecord
14-
alias CMS.{Post, Job, Repo, Video}
14+
# alias CMS.{Post, Job, Repo, Video}
1515
alias Email.Templates
1616
alias Mailer
1717

lib/groupher_server/mailer/templates/thanks_donation.ex

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule GroupherServer.Email.Templates.ThanksDonation do
33
template for thanks user's donation, if you want change style or debug the template
44
just copy and paste raw string to: https://mjml.io/try-it-live
55
"""
6+
67
# alias GroupherServer.Billing.BillRecord
78

89
def html(user, record) do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
defmodule GroupherServerWeb.Controller.OG do
2+
@moduledoc """
3+
handle open-graph info
4+
"""
5+
use GroupherServerWeb, :controller
6+
# alias Todos.Todo
7+
# plug(:action)
8+
9+
def index(conn, %{"url" => url}) do
10+
fetch_opengraph_info(conn, url)
11+
end
12+
13+
# return editor-js flavor fmt
14+
# see https://github.com/editor-js/link
15+
defp fetch_opengraph_info(conn, url) do
16+
case OpenGraph.fetch(url) do
17+
{:ok, info} ->
18+
ok_response(conn, url, info)
19+
20+
{:error, reason} ->
21+
error_response(conn, url, reason)
22+
end
23+
end
24+
25+
defp ok_response(conn, url, %OpenGraph{title: nil, description: nil}) do
26+
error_response(conn, url)
27+
end
28+
29+
defp ok_response(conn, url, %OpenGraph{title: nil, description: description} = info)
30+
when not is_nil(description) do
31+
json(conn, %{
32+
success: 1,
33+
meta: %{
34+
title: info.description |> String.slice(0, 8),
35+
description: info.description,
36+
image: %{
37+
url: nil
38+
}
39+
}
40+
})
41+
end
42+
43+
defp ok_response(conn, url, info) do
44+
json(conn, %{
45+
success: 1,
46+
meta: %{
47+
title: info.title,
48+
description: info.description,
49+
image: %{
50+
url: info.image
51+
}
52+
}
53+
})
54+
end
55+
56+
defp error_response(conn, url) do
57+
json(conn, %{
58+
success: 1,
59+
meta: %{
60+
title: url,
61+
description: url,
62+
image: %{
63+
url: nil
64+
}
65+
}
66+
})
67+
end
68+
69+
defp error_response(conn, _url, :nxdomain) do
70+
json(conn, %{
71+
success: 0,
72+
meta: %{
73+
title: "domain-not-exsit",
74+
description: "--",
75+
image: %{
76+
url: nil
77+
}
78+
}
79+
})
80+
end
81+
82+
defp error_response(conn, _url, :timeout) do
83+
json(conn, %{
84+
success: 0,
85+
meta: %{
86+
title: "timeout",
87+
description: "--",
88+
image: %{
89+
url: nil
90+
}
91+
}
92+
})
93+
end
94+
95+
defp error_response(conn, url, "Not found :(") do
96+
json(conn, %{
97+
success: 1,
98+
meta: %{
99+
title: url,
100+
description: "--",
101+
image: %{
102+
url: nil
103+
}
104+
}
105+
})
106+
end
107+
108+
defp error_response(conn, _url, _reason) do
109+
json(conn, %{
110+
success: 0,
111+
meta: %{
112+
title: "unknown-error",
113+
description: nil,
114+
image: %{
115+
url: nil
116+
}
117+
}
118+
})
119+
end
120+
end

lib/groupher_server_web/resolvers/billing_resolver.ex

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule GroupherServerWeb.Resolvers.Billing do
22
@moduledoc """
33
accounts resolvers
44
"""
5+
56
# import ShortMaps
67
# import Helper.ErrorCode
78

lib/groupher_server_web/router.ex

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ defmodule GroupherServerWeb.Router do
1010
plug(GroupherServerWeb.Context)
1111
end
1212

13+
alias GroupherServerWeb.Controller
14+
15+
scope "/api" do
16+
pipe_through(:api)
17+
18+
# get "/og-info", TodoController, only: [:index]
19+
# resources("/og-info", OG, only: [:index])
20+
get("/og-info", Controller.OG, :index)
21+
end
22+
1323
scope "/graphiql" do
1424
pipe_through(:api)
1525

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
defmodule Helper.Converter.EditorToHtml.Assets.DelimiterIcons do
2+
@moduledoc """
3+
svg icons for delimiter block
4+
NOTE: those svg should be sync with frontend svg
5+
"""
6+
7+
@pen_svg """
8+
<svg height="22px" width="22px" t="1572155354182" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="14479" width="200" height="200"><path d="M812.586667 331.306667h79.850666a71.338667 71.338667 0 0 1 71.317334 71.317333v86.784a158.122667 158.122667 0 0 1-158.101334 158.122667h-5.568c-38.890667 130.624-159.893333 225.877333-303.146666 225.877333h-120.469334c-174.656 0-316.224-141.589333-316.224-316.224V342.4a101.44 101.44 0 0 1 101.44-101.461333h550.037334a101.461333 101.461333 0 0 1 100.864 90.346666zM240.938667 60.224c16.64 0 30.122667 13.482667 30.122666 30.101333V150.613333a30.122667 30.122667 0 0 1-60.245333 0V90.346667c0-16.64 13.482667-30.101333 30.122667-30.101334z m180.693333 0c16.64 0 30.122667 13.482667 30.122667 30.101333V150.613333a30.122667 30.122667 0 0 1-60.224 0V90.346667c0-16.64 13.482667-30.101333 30.122666-30.101334z m180.714667 0c16.64 0 30.122667 13.482667 30.122666 30.101333V150.613333a30.122667 30.122667 0 0 1-60.224 0V90.346667c0-16.64 13.482667-30.101333 30.101334-30.101334zM161.706667 301.184a41.216 41.216 0 0 0-41.216 41.216v214.784c0 141.376 114.624 256 256 256h120.469333c141.397333 0 256-114.624 256-256V342.4a41.216 41.216 0 0 0-41.216-41.216H161.706667z m741.845333 188.224v-86.784a11.093333 11.093333 0 0 0-11.093333-11.093333h-79.253334v195.477333a97.898667 97.898667 0 0 0 90.346667-97.6z" p-id="14480"></path></svg>
9+
"""
10+
11+
@coffee_svg """
12+
<svg height="22px" width="22px" t="1572155354182" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="14479" width="200" height="200"><path d="M812.586667 331.306667h79.850666a71.338667 71.338667 0 0 1 71.317334 71.317333v86.784a158.122667 158.122667 0 0 1-158.101334 158.122667h-5.568c-38.890667 130.624-159.893333 225.877333-303.146666 225.877333h-120.469334c-174.656 0-316.224-141.589333-316.224-316.224V342.4a101.44 101.44 0 0 1 101.44-101.461333h550.037334a101.461333 101.461333 0 0 1 100.864 90.346666zM240.938667 60.224c16.64 0 30.122667 13.482667 30.122666 30.101333V150.613333a30.122667 30.122667 0 0 1-60.245333 0V90.346667c0-16.64 13.482667-30.101333 30.122667-30.101334z m180.693333 0c16.64 0 30.122667 13.482667 30.122667 30.101333V150.613333a30.122667 30.122667 0 0 1-60.224 0V90.346667c0-16.64 13.482667-30.101333 30.122666-30.101334z m180.714667 0c16.64 0 30.122667 13.482667 30.122666 30.101333V150.613333a30.122667 30.122667 0 0 1-60.224 0V90.346667c0-16.64 13.482667-30.101333 30.101334-30.101334zM161.706667 301.184a41.216 41.216 0 0 0-41.216 41.216v214.784c0 141.376 114.624 256 256 256h120.469333c141.397333 0 256-114.624 256-256V342.4a41.216 41.216 0 0 0-41.216-41.216H161.706667z m741.845333 188.224v-86.784a11.093333 11.093333 0 0 0-11.093333-11.093333h-79.253334v195.477333a97.898667 97.898667 0 0 0 90.346667-97.6z" p-id="14480"></path></svg>
13+
"""
14+
15+
@keyboard_svg """
16+
<svg height="20px" width="20px" t="1572104029920" class="icon" viewBox="0 0 1152 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="25920" width="200" height="200"><path d="M1056 128H96C42.98 128 0 170.98 0 224v576c0 53.02 42.98 96 96 96h960c53.02 0 96-42.98 96-96V224c0-53.02-42.98-96-96-96z m16 672c0 8.822-7.178 16-16 16H96c-8.822 0-16-7.178-16-16V224c0-8.822 7.178-16 16-16h960c8.822 0 16 7.178 16 16v576zM340 540v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m192 0v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m192 0v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m192 0v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m-672 164v-56c0-13.254-10.746-24-24-24H164c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m768 0v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24zM244 376v-56c0-13.254-10.746-24-24-24H164c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m192 0v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m192 0v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m192 0v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m192 0v-56c0-13.254-10.746-24-24-24h-56c-13.254 0-24 10.746-24 24v56c0 13.254 10.746 24 24 24h56c13.254 0 24-10.746 24-24z m-196 316v-32c0-13.254-10.746-24-24-24H360c-13.254 0-24 10.746-24 24v32c0 13.254 10.746 24 24 24h432c13.254 0 24-10.746 24-24z" p-id="25921"></path></svg>
17+
"""
18+
19+
@moon_svg """
20+
<svg height="20px" width="22px" t="1572093894756" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="21571" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M923.306667 554.666667a42.666667 42.666667 0 0 0-44.8-5.973334 343.466667 343.466667 0 0 1-143.786667 31.146667 347.733333 347.733333 0 0 1-347.306667-345.6 366.506667 366.506667 0 0 1 10.666667-85.333333A42.666667 42.666667 0 0 0 341.333333 100.693333a432.64 432.64 0 1 0 597.333334 498.773334 42.666667 42.666667 0 0 0-15.36-44.8z m-405.333334 285.44A347.306667 347.306667 0 0 1 302.08 222.72v11.52a433.066667 433.066667 0 0 0 432.64 432.64 417.706667 417.706667 0 0 0 89.6-9.386667 346.026667 346.026667 0 0 1-306.346667 184.32z" p-id="21572"></path></svg>
21+
"""
22+
23+
@planet_svg """
24+
<svg height="22px" width="22px" t="1572094486716" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="34210" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M271.4 302c-5 6-9.8 12-14.4 18.4 64.4 72.6 152.2 153 248.4 227.4 75.6 58.4 152.6 110.4 222.8 150.2 11.8 6.6 23.4 13 34.6 18.8 5-6 9.8-12 14.4-18.4 23.4-32.2 36.2-66.4 46.6-107.2 1.6-6.4 3-12.8 4.2-19 31.6-166-71.2-329.8-237-371.8-74-18.8-148.2-10.2-212.6 19.4-42.8 19.8-76.4 45.8-107 82.2z" p-id="34211"></path><path d="M836.4 653.6c-8.2 22-14.8 35-14.8 35 36.4 42.2 49.2 67.8 63.8 92.8 4.8 8.2 14.8 26.2 1.8 24.8-3.4-0.6-7-1.4-11-2.6-42.6-10.8-102.4-37.4-168.6-74.8-71.6-40.6-149.8-93.4-226.6-152.6-102.2-79-195-164.6-261.2-241-30.6-35.2-55.2-68.4-71.4-95.8-4.8-8.2-7.8-12.6-11.2-20.8-5-12.4 10-10.2 14-9.2 29.8 7.6 70 19.8 116.4 47.6 0 0 8.6-9.6 27.8-22.8-45.6-30.8-89.2-55.4-130.4-71-46.2-17.6-82.2-13.6-95 7.4-24.4 39.8 28 144.6 130.6 264-43 172 61.2 346.6 233 390 82.2 20.8 164.8 7.8 233.6-30 76.2 35.2 144.2 57.2 193.8 69.8 47.8 12.2 80.8 11 93.6-9.8 22.2-36.4-24.2-103.6-118.2-201z" p-id="34212"></path></svg>
25+
"""
26+
27+
@foot_svg """
28+
<svg height="20px" width="20px" t="1572104143510" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3430" width="200" height="200"><path d="M960 174.08c-27.648-162.816-138.24-160.256-262.144-129.024-171.008 48.128-90.112 241.152-15.36 392.704 35.84 70.656 17.408 108.544 17.408 108.544l260.096-8.704s-3.584-104.448 2.56-211.968c3.072-49.664 6.656-98.304-2.56-151.552zM342.528 281.088C218.112 249.856 107.52 246.784 79.872 410.112c-9.216 52.736-5.632 101.376-3.072 151.04 6.144 107.52 2.56 211.968 2.56 211.968l261.12 8.704s-18.432-37.888 17.408-108.544c74.752-151.04 156.16-344.064-15.36-392.192zM76.8 826.88c30.208 206.848 169.472 166.4 237.568 141.824 68.608-25.088 30.208-141.824 30.208-141.824H76.8zM726.016 733.184c68.096 24.576 206.848 65.024 237.056-141.824h-267.264c-0.512 0-38.4 116.736 30.208 141.824z" p-id="3431"></path></svg>
29+
"""
30+
31+
def svg("pen"), do: @pen_svg
32+
33+
def svg("coffee"), do: @coffee_svg
34+
35+
def svg("keyboard"), do: @keyboard_svg
36+
37+
def svg("moon"), do: @moon_svg
38+
39+
def svg("planet"), do: @planet_svg
40+
41+
def svg("foot"), do: @foot_svg
42+
43+
def svg(_default), do: @pen_svg
44+
end
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
defmodule Helper.Converter.ChineseConvention do
2+
@moduledoc """
3+
follow's https://github.com/sparanoid/chinese-copywriting-guidelines
4+
遵循中文排版指南
5+
6+
- 自动添加空格
7+
- 中文状态下输入的的 "" 和 '' 会被自动转换成「」以及 『』
8+
9+
inspired by wordpress plugin cover-lover:
10+
https://cn.wordpress.org/plugins/corner-bracket-lover/
11+
"""
12+
13+
require Pangu
14+
15+
@doc """
16+
format chinese stirng follows github: sparanoid/chinese-copywriting-guidelines.
17+
18+
example: "Sephiroth見他”這等’神情‘“,也是悚然一驚:不知我這Ultimate Destructive Magic是否對付得了?"
19+
to: "Sephiroth 見他「這等『神情』」, 也是悚然一驚: 不知我這 Ultimate Destructive Magic 是否對付得了?"
20+
"""
21+
@spec format(binary) :: binary
22+
def format(text) do
23+
text
24+
|> Pangu.spacing()
25+
|> cover_brackets
26+
end
27+
28+
# covert chinese "" and '' to 「」& 『』
29+
defp cover_brackets(text) do
30+
text
31+
|> String.replace("“", "「")
32+
|> String.replace("”", "」")
33+
|> String.replace("‘", "『")
34+
|> String.replace("’", "』")
35+
end
36+
end

0 commit comments

Comments
 (0)