This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork20
feat(editor-export): quote block#292
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletionslib/helper/converter/editor_to_html/class.ex
This file contains hidden or 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
57 changes: 57 additions & 0 deletionslib/helper/converter/editor_to_html/frags/quote.ex
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
defmodule Helper.Converter.EditorToHTML.Frags.Quote do | ||
@moduledoc """ | ||
parse editor.js's block fragments, use for test too | ||
see https://editorjs.io/ | ||
""" | ||
import Helper.Validator.Guards, only: [g_none_empty_str: 1] | ||
alias Helper.Types, as: T | ||
alias Helper.Converter.EditorToHTML.Class | ||
@class get_in(Class.article(), ["quote"]) | ||
@spec get(T.editor_quote()) :: T.html() | ||
def get(%{"mode" => "short", "text" => text}) do | ||
wrapper_class = @class["short_wrapper"] | ||
text_class = @class["text"] | ||
~s(<blockquote class="#{wrapper_class}"> | ||
<div class="#{text_class}">#{text}</div> | ||
</blockquote>) | ||
end | ||
def get(%{"mode" => "long", "text" => text, "caption" => caption}) | ||
when g_none_empty_str(caption) do | ||
wrapper_class = @class["long_wrapper"] | ||
text_class = @class["text"] | ||
caption = frag(:caption, caption) | ||
~s(<blockquote class="#{wrapper_class}"> | ||
<div class="#{text_class}">#{text}</div> | ||
#{caption} | ||
</blockquote>) | ||
end | ||
def get(%{"mode" => "long", "text" => text}) do | ||
wrapper_class = @class["long_wrapper"] | ||
text_class = @class["text"] | ||
~s(<blockquote class="#{wrapper_class}"> | ||
<div class="#{text_class}">#{text}</div> | ||
</blockquote>) | ||
end | ||
@spec frag(:caption, String.t()) :: T.html() | ||
def frag(:caption, caption) do | ||
caption_class = @class["caption"] | ||
caption_line_class = @class["caption_line"] | ||
caption_text_class = @class["caption_text"] | ||
~s(<div class="#{caption_class}"> | ||
<div class="#{caption_line_class}"/> | ||
<div class="#{caption_text_class}">#{caption}</div> | ||
</div>) | ||
end | ||
end |
7 changes: 5 additions & 2 deletionslib/helper/converter/editor_to_html/frontend_test/script.js
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
89 changes: 89 additions & 0 deletionslib/helper/converter/editor_to_html/frontend_test/styles.css
This file contains hidden or 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
2 changes: 2 additions & 0 deletionslib/helper/converter/editor_to_html/index.ex
This file contains hidden or 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
13 changes: 13 additions & 0 deletionslib/helper/converter/editor_to_html/validator/editor_schema.ex
This file contains hidden or 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
4 changes: 2 additions & 2 deletionslib/helper/converter/editor_to_html/validator/index.ex
This file contains hidden or 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
3 changes: 3 additions & 0 deletionslib/helper/converter/html_sanitizer.ex
This file contains hidden or 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
10 changes: 10 additions & 0 deletionslib/helper/types.ex
This file contains hidden or 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
2 changes: 2 additions & 0 deletionslib/helper/validator/guards.ex
This file contains hidden or 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
125 changes: 125 additions & 0 deletionstest/helper/converter/editor_to_html_test/quote_test.exs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Quote do | ||
@moduledoc false | ||
use GroupherServerWeb.ConnCase, async: true | ||
alias Helper.Converter.EditorToHTML.Class | ||
alias Helper.Converter.EditorToHTML, as: Parser | ||
alias Helper.Utils | ||
@root_class Class.article() | ||
@class get_in(@root_class, ["quote"]) | ||
describe "[quote block]" do | ||
defp set_data(mode, text, caption \\ nil) do | ||
data = | ||
case caption do | ||
nil -> | ||
%{ | ||
"mode" => mode, | ||
"text" => text | ||
} | ||
_ -> | ||
%{ | ||
"mode" => mode, | ||
"text" => text, | ||
"caption" => caption | ||
} | ||
end | ||
%{ | ||
"time" => 1_567_250_876_713, | ||
"blocks" => [ | ||
%{ | ||
"type" => "quote", | ||
"data" => data | ||
} | ||
], | ||
"version" => "2.15.0" | ||
} | ||
end | ||
@tag :wip2 | ||
test "short quote parse should work" do | ||
editor_json = set_data("short", "short quote") | ||
{:ok, editor_string} = Jason.encode(editor_json) | ||
{:ok, converted} = Parser.to_html(editor_string) | ||
short_wrapper_class = @class["short_wrapper"] | ||
caption_class = @class["caption"] | ||
assert Utils.str_occurence(converted, short_wrapper_class) == 1 | ||
assert Utils.str_occurence(converted, "</blockquote>") == 1 | ||
assert Utils.str_occurence(converted, caption_class) == 0 | ||
end | ||
@tag :wip2 | ||
test "long quote parse should work" do | ||
editor_json = set_data("long", "long quote", "caption") | ||
{:ok, editor_string} = Jason.encode(editor_json) | ||
{:ok, converted} = Parser.to_html(editor_string) | ||
long_wrapper_class = @class["long_wrapper"] | ||
caption_text_class = @class["caption_text"] | ||
assert Utils.str_occurence(converted, long_wrapper_class) == 1 | ||
assert Utils.str_occurence(converted, "</blockquote>") == 1 | ||
assert Utils.str_occurence(converted, caption_text_class) == 1 | ||
end | ||
@tag :wip2 | ||
test "long quote without caption parse should work" do | ||
editor_json = set_data("long", "long quote") | ||
{:ok, editor_string} = Jason.encode(editor_json) | ||
{:ok, converted} = Parser.to_html(editor_string) | ||
long_wrapper_class = @class["long_wrapper"] | ||
caption_text_class = @class["caption_text"] | ||
assert Utils.str_occurence(converted, long_wrapper_class) == 1 | ||
assert Utils.str_occurence(converted, "</blockquote>") == 1 | ||
assert Utils.str_occurence(converted, caption_text_class) == 0 | ||
end | ||
@tag :wip2 | ||
test "long quote without empty caption parse should work" do | ||
editor_json = set_data("long", "long quote", "") | ||
{:ok, editor_string} = Jason.encode(editor_json) | ||
{:ok, converted} = Parser.to_html(editor_string) | ||
long_wrapper_class = @class["long_wrapper"] | ||
caption_text_class = @class["caption_text"] | ||
assert Utils.str_occurence(converted, long_wrapper_class) == 1 | ||
assert Utils.str_occurence(converted, "</blockquote>") == 1 | ||
assert Utils.str_occurence(converted, caption_text_class) == 0 | ||
end | ||
# @editor_json %{ | ||
# "time" => 1_567_250_876_713, | ||
# "blocks" => [ | ||
# %{ | ||
# "type" => "paragraph", | ||
# "data" => %{ | ||
# "text" => [] | ||
# } | ||
# } | ||
# ], | ||
# "version" => "2.15.0" | ||
# } | ||
@tag :wip2 | ||
test "invalid quote should have invalid hint" do | ||
editor_json = set_data("none_exsit", "long quote", "") | ||
{:ok, editor_string} = Jason.encode(editor_json) | ||
{:error, error} = Parser.to_html(editor_string) | ||
assert error == [ | ||
%{block: "quote", field: "mode", message: "should be: short | long"} | ||
] | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.