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.

Commit50d6108

Browse files
committed
fix(editor): re-org validate workflow by using config
1 parent0ea6c34 commit50d6108

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

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

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ defmodule Helper.Converter.EditorToHTML.Validator do
33

44
aliasHelper.{Utils,ValidateBySchema}
55

6-
@valid_header_level[1,2,3]
6+
aliasHelper.Converter.EditorToHTML.Validator.Schema
7+
8+
# blocks with no children items
9+
@simple_blocks["header","paragraph"]
710

811
@valid_list_mode["checklist","order_list","unorder_list"]
912
@valid_list_label_type["success","done","todo"]
@@ -45,33 +48,9 @@ defmodule Helper.Converter.EditorToHTML.Validator do
4548
{:ok,:pass}
4649
end
4750

48-
defpvalidate_block(%{"type"=>"paragraph","data"=>%{"text"=>text}=data})do
49-
schema=%{"text"=>[:string]}
50-
51-
caseValidateBySchema.cast(schema,data)do
52-
{:error,errors}->
53-
format_parse_error("paragraph",errors)
54-
55-
_->
56-
{:ok,:pass}
57-
end
58-
end
59-
60-
defpvalidate_block(%{"type"=>"header","data"=>%{"text"=>text,"level"=>level}=data})do
61-
schema=%{
62-
"text"=>[:string],
63-
"level"=>[enum:@valid_header_level],
64-
"eyebrowTitle"=>[:string,required:false],
65-
"footerTitle"=>[:string,required:false]
66-
}
67-
68-
caseValidateBySchema.cast(schema,data)do
69-
{:error,errors}->
70-
format_parse_error("header",errors)
71-
72-
_->
73-
{:ok,:pass}
74-
end
51+
# validate block which have no nested items
52+
defpvalidate_block(%{"type"=>type,"data"=>data})whentypein@simple_blocksdo
53+
validate_with(type,Schema.get(type),data)
7554
end
7655

7756
defpvalidate_block(%{"type"=>"list","data"=>%{"mode"=>mode,"items"=>items}=data})
@@ -117,6 +96,17 @@ defmodule Helper.Converter.EditorToHTML.Validator do
11796
defpvalidate_block(%{"type"=>type}),do:raise("undown#{type} block")
11897
defpvalidate_block(_),do:raise("undown block")
11998

99+
# validate with given schema
100+
defpvalidate_with(block,schema,data)do
101+
caseValidateBySchema.cast(schema,data)do
102+
{:error,errors}->
103+
format_parse_error(block,errors)
104+
105+
_->
106+
{:ok,:pass}
107+
end
108+
end
109+
120110
# check if the given map has the right key-value fmt of the editorjs structure
121111
defpis_valid_editorjs_fmt(map)whenis_map(map)do
122112
Map.has_key?(map,"time")and
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmoduleHelper.Converter.EditorToHTML.Validator.Schemado
2+
@moduledocfalse
3+
4+
@valid_header_level[1,2,3]
5+
6+
defget("header")do
7+
%{
8+
"text"=>[:string],
9+
"level"=>[enum:@valid_header_level],
10+
"eyebrowTitle"=>[:string,required:false],
11+
"footerTitle"=>[:string,required:false]
12+
}
13+
end
14+
15+
defget("paragraph")do
16+
%{"text"=>[:string]}
17+
end
18+
19+
defget(_)do
20+
%{}
21+
end
22+
end

‎test/helper/converter/editor_to_html_test/list_test.exs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do
7373
],
7474
"version"=>"2.15.0"
7575
}
76-
@tag:wip2
76+
@tag:wip
7777
test"valid list parse should work"do
7878
{:ok,editor_string}=Jason.encode(@editor_json)
7979
assert{:ok,_}=Parser.to_html(editor_string)
@@ -101,7 +101,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do
101101
],
102102
"version"=>"2.15.0"
103103
}
104-
@tag:wip2
104+
@tag:wip
105105
test"invalid indent field should get error"do
106106
{:ok,editor_string}=Jason.encode(@editor_json)
107107
{:error,error}=Parser.to_html(editor_string)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp