Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

refactor: seeds generator#428

Merged
mydearxym merged 8 commits intodevfromseeds
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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
3 changes: 3 additions & 0 deletionslib/groupher_server/cms/cms.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,6 +196,9 @@ defmodule GroupherServer.CMS do

# seeds
defdelegate seed_communities(opt), to: Seeds
defdelegate seed_community(raw, type), to: Seeds
defdelegate seed_community(raw), to: Seeds
defdelegate seed_set_category(communities, category), to: Seeds

defdelegate seed_bot, to: Seeds
end
61 changes: 61 additions & 0 deletionslib/groupher_server/cms/delegates/Seeds/categories.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
defmodule GroupherServer.CMS.Delegate.Seeds.Categories do
@doc """
default categories seeds for general community
"""
def get() do
[
%{
title: "编程语言",
raw: "pl",
index: 0
},
%{
title: "框架 & 库",
raw: "framework",
index: 1
},
%{
title: "数据库",
raw: "database",
index: 2
},
%{
title: "devops",
raw: "devops",
index: 3
},
%{
title: "开发工具",
raw: "tools",
index: 4
},
%{
title: "城市",
raw: "city",
index: 5
},
%{
title: "人工智能",
raw: "ai",
index: 6
},
%{
title: "作品",
raw: "works",
index: 7
},
%{
# blackhole, Feedback, dev
title: "站务",
raw: "feedback",
index: 8
},
%{
# Makers, Adwall, Outwork
title: "其他",
raw: "others",
index: 9
}
]
end
end
130 changes: 130 additions & 0 deletionslib/groupher_server/cms/delegates/Seeds/communities.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
defmodule GroupherServer.CMS.Delegate.Seeds.Communities do
@moduledoc """
communities seeds
"""

def get(:pl) do
[
"c",
"clojure",
"cpp",
"csharp",
"dart",
"delphi",
"elm",
"erlang",
"fsharp",
"go",
"gradle",
"groovy",
"java",
"javascript",
"julia",
"kotlin",
"lisp",
"lua",
"ocaml",
"perl",
"php",
"python",
"ruby",
"r",
"racket",
"red",
"reason",
"rust",
"scala",
"haskell",
"swift",
"typescript",
"elixir",
# new
"deno",
"crystal",
"hack",
"nim",
"fasm",
"zig",
"prolog"
]
end

def get(:framework) do
[
"backbone",
"d3",
"django",
"drupal",
"eggjs",
"electron",
"laravel",
"meteor",
"nestjs",
"nuxtjs",
"nodejs",
"phoenix",
"rails",
"react",
"sails",
"zend",
"vue",
"angular",
"tensorflow",
# mobile
"android",
"ios",
"react-native",
"weex",
"xamarin",
"nativescript",
"ionic",
# new
"rxjs",
"flutter",
"taro",
"webrtc",
"wasm"
]
end

def get(:editor) do
["vim", "atom", "emacs", "vscode", "visualstudio", "jetbrains"]
end

def get(:database) do
[
"oracle",
"hive",
"spark",
"hadoop",
"cassandra",
"elasticsearch",
"sql-server",
"neo4j",
"mongodb",
"mysql",
"postgresql",
"redis"
]
end

def get(:city) do
[
"beijing",
"shanghai",
"shenzhen",
"hangzhou",
"guangzhou",
"chengdu",
"wuhan",
"xiamen",
"nanjing"
]
end

def get(:devops) do
# gcp -> google-cloud-platform
# search google: devops tools
["git", "docker", "kubernetes", "jenkins", "puppet", "aws", "azure", "aliyun", "gcp"]
end
end
101 changes: 101 additions & 0 deletionslib/groupher_server/cms/delegates/Seeds/domain.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
defmodule GroupherServer.CMS.Delegate.Seeds.Domain do
@moduledoc """
seeds data for init, should be called ONLY in new database, like migration
"""

import Ecto.Query, warn: false

import GroupherServer.CMS.Delegate.Seeds.Helper,
only: [
threadify_communities: 2,
tagfy_threads: 4,
categorify_communities: 3,
seed_bot: 0,
seed_threads: 1,
seed_categories_ifneed: 1
]

alias Helper.ORM
alias GroupherServer.CMS

alias CMS.Model.Community

@oss_endpoint "https://cps-oss.oss-cn-shanghai.aliyuncs.com"

# seed community
@doc """
seed community for home
"""
def seed_community(:home) do
with {:error, _} <- ORM.find_by(Community, %{raw: "home"}),
{:ok, bot} <- seed_bot(),
{:ok, threads} <- seed_threads(:home),
{:ok, categories} <- seed_categories_ifneed(bot) do
args = %{
title: "coderplanets",
desc: "the most sexy community for developers, ever.",
logo: "#{@oss_endpoint}/icons/cmd/keyboard_logo.png",
raw: "home",
user_id: bot.id
}

{:ok, community} = Community |> ORM.create(args)
threadify_communities([community], threads.entries)
tagfy_threads([community], threads.entries, bot, :home)

{:ok, community}
# home 不设置分类,比较特殊
end
end

@doc """
seed community for blackhole
"""
def seed_community(:blackhole) do
with {:error, _} <- ORM.find_by(Community, %{raw: "blackhole"}),
{:ok, bot} <- seed_bot(),
{:ok, threads} <- seed_threads(:blackhole),
{:ok, categories} <- seed_categories_ifneed(bot) do
args = %{
title: "黑洞",
desc: "这里收录不适合出现在本站的内容。",
logo: "#{@oss_endpoint}/icons/cmd/keyboard_logo.png",
raw: "blackhole",
user_id: bot.id
}

{:ok, community} = Community |> ORM.create(args)
threadify_communities([community], threads.entries)
tagfy_threads([community], threads.entries, bot, :blackhole)
categorify_communities([community], categories, :feedback)

{:ok, community}
end
end

@doc """
seed community for feedback
"""
def seed_community(:feedback) do
with {:error, _} <- ORM.find_by(Community, %{raw: "feedback"}),
{:ok, bot} <- seed_bot(),
{:ok, threads} <- seed_threads(:feedback),
{:ok, categories} <- seed_categories_ifneed(bot) do
args = %{
title: "反馈与建议",
desc: "关于本站的建议和反馈请发布在这里,谢谢。",
logo: "#{@oss_endpoint}/icons/cmd/keyboard_logo.png",
raw: "feedback",
user_id: bot.id
}

{:ok, community} = Community |> ORM.create(args)
threadify_communities([community], threads.entries)
tagfy_threads([community], threads.entries, bot, :feedback)
categorify_communities([community], categories, :feedback)

{:ok, community}
# home 不设置分类,比较特殊
end
end
end
Loading

[8]ページ先頭

©2009-2025 Movatter.jp