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.

Commit39ff354

Browse files
committed
fix(editor): add list to validator workflow as general
1 parent50d6108 commit39ff354

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

‎lib/helper/converter/editor_to_html/validator/index.ex‎

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ defmodule Helper.Converter.EditorToHTML.Validator do
77

88
# blocks with no children items
99
@simple_blocks["header","paragraph"]
10+
# blocks with "mode" and "items" fields
11+
@complex_blocks["list"]
1012

1113
@valid_list_mode["checklist","order_list","unorder_list"]
1214
@valid_list_label_type["success","done","todo"]
@@ -53,32 +55,11 @@ defmodule Helper.Converter.EditorToHTML.Validator do
5355
validate_with(type,Schema.get(type),data)
5456
end
5557

56-
defpvalidate_block(%{"type"=>"list","data"=>%{"mode"=>mode,"items"=>items}=data})
57-
whenmodein@valid_list_modeandis_list(items)do
58-
# mode_schema = %{mode: [enum: @valid_list_mode]}
59-
# {:ok, _} = ValidateBySchema.cast(mode_schema, data)
60-
61-
item_schema=%{
62-
"checked"=>[:boolean],
63-
"hideLabel"=>[:boolean],
64-
"label"=>[:string],
65-
"labelType"=>[enum:@valid_list_label_type],
66-
"indent"=>[enum:@valid_list_indent],
67-
"text"=>[:string]
68-
}
69-
70-
Enum.each(items,fnitem->
71-
caseValidateBySchema.cast(item_schema,item)do
72-
{:error,errors}->
73-
{:error,message}=format_parse_error("list(#{mode})",errors)
74-
raise%MatchError{term:{:error,message}}
75-
76-
_->
77-
{:ok,:pass}
78-
end
79-
end)
80-
81-
{:ok,:pass}
58+
# validate block which has mode and items
59+
defpvalidate_block(%{"type"=>type,"data"=>%{"mode"=>mode,"items"=>items}=data})
60+
whentypein@complex_blocksdo
61+
[parent:parent_schema,item:item_schema]=Schema.get(type)
62+
validate_with(type,parent_schema,item_schema,data)
8263
end
8364

8465
defpvalidate_block(%{"type"=>"code"})do
@@ -107,6 +88,31 @@ defmodule Helper.Converter.EditorToHTML.Validator do
10788
end
10889
end
10990

91+
defpvalidate_with(block,parent_schema,item_schema,data)do
92+
caseValidateBySchema.cast(parent_schema,data)do
93+
{:error,errors}->
94+
format_parse_error(block,errors)
95+
96+
_->
97+
{:ok,:pass}
98+
end
99+
100+
%{"mode"=>mode,"items"=>items}=data
101+
102+
Enum.each(items,fnitem->
103+
caseValidateBySchema.cast(item_schema,item)do
104+
{:error,errors}->
105+
{:error,message}=format_parse_error("#{block}(#{mode})",errors)
106+
raise%MatchError{term:{:error,message}}
107+
108+
_->
109+
{:ok,:pass}
110+
end
111+
end)
112+
113+
{:ok,:pass}
114+
end
115+
110116
# check if the given map has the right key-value fmt of the editorjs structure
111117
defpis_valid_editorjs_fmt(map)whenis_map(map)do
112118
Map.has_key?(map,"time")and

‎lib/helper/converter/editor_to_html/validator/schema.ex‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
defmoduleHelper.Converter.EditorToHTML.Validator.Schemado
22
@moduledocfalse
33

4+
# header
45
@valid_header_level[1,2,3]
56

7+
# list
8+
@valid_list_mode["checklist","order_list","unorder_list"]
9+
@valid_list_label_type["success","done","todo"]
10+
@valid_list_indent[0,1,2,3,4]
11+
612
defget("header")do
713
%{
814
"text"=>[:string],
@@ -12,8 +18,20 @@ defmodule Helper.Converter.EditorToHTML.Validator.Schema do
1218
}
1319
end
1420

15-
defget("paragraph")do
16-
%{"text"=>[:string]}
21+
defget("paragraph"),do:%{"text"=>[:string]}
22+
23+
defget("list")do
24+
[
25+
parent:%{"mode"=>[enum:@valid_list_mode]},
26+
item:%{
27+
"checked"=>[:boolean],
28+
"hideLabel"=>[:boolean],
29+
"label"=>[:string],
30+
"labelType"=>[enum:@valid_list_label_type],
31+
"indent"=>[enum:@valid_list_indent],
32+
"text"=>[:string]
33+
}
34+
]
1735
end
1836

1937
defget(_)do

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp