-
-
Notifications
You must be signed in to change notification settings - Fork 423
Add custom MIME types to display_dict. #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0451835
Add custom MIME types to display_dict.
twavv a708a62
Add tests, fix markdown/latex priority.
twavv 30a462c
Improve documentation.
twavv 883fe82
Update MIME priority of png/jpeg and html.
twavv c1fc7e3
register_ijulia_mime -> register_mime
twavv e735ac4
Vector -> AbstractVector, add test cases for vector-of-MIMEs
twavv 3511bd5
Fix more types!
twavv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
|---|---|---|
| @@ -1,9 +1,57 @@ | ||
| using Test | ||
| using Base64, JSON | ||
|
|
||
| import IJulia | ||
| import IJulia: helpmode, error_content, docdict | ||
|
|
||
| content = error_content(UndefVarError(:a)) | ||
| @test "UndefVarError" == content["ename"] | ||
|
|
||
| @test haskey(docdict("import"), "text/plain") | ||
| @test haskey(docdict("sum"), "text/plain") | ||
|
|
||
| struct FriendlyData | ||
| name::AbstractString | ||
| end | ||
|
|
||
| @testset "Custom MIME types" begin | ||
| friend = FriendlyData("world") | ||
|
|
||
| FRIENDLY_MIME_TYPE = MIME"application/vnd.ijulia.friendly-text" | ||
| FRIENDLY_MIME = FRIENDLY_MIME_TYPE() | ||
| Base.Multimedia.istextmime(::FRIENDLY_MIME_TYPE) = true | ||
| Base.show(io, ::FRIENDLY_MIME_TYPE, x::FriendlyData) = write(io, "Hello, $(x.name)!") | ||
| IJulia.register_mime(FRIENDLY_MIME) | ||
|
|
||
| BINARY_MIME_TYPE = MIME"application/vnd.ijulia.friendly-binary" | ||
| BINARY_MIME = BINARY_MIME_TYPE() | ||
| Base.Multimedia.istextmime(::BINARY_MIME_TYPE) = false | ||
| Base.show(io, ::BINARY_MIME_TYPE, x::FriendlyData) = write(io, "Hello, $(x.name)!") | ||
| IJulia.register_mime(BINARY_MIME) | ||
|
|
||
| JSON_MIME_TYPE = MIME"application/vnd.ijulia.friendly-json" | ||
| JSON_MIME = JSON_MIME_TYPE() | ||
| Base.Multimedia.istextmime(::JSON_MIME_TYPE) = true | ||
| Base.show(io, ::JSON_MIME_TYPE, x::FriendlyData) = write(io, JSON.json(Dict("name" => x.name))) | ||
| IJulia.register_jsonmime(JSON_MIME) | ||
|
|
||
| FRIENDLY_MIME_TYPE_1 = MIME"application/vnd.ijulia.friendly-text-1" | ||
| FRIENDLY_MIME_TYPE_2 = MIME"application/vnd.ijulia.friendly-text-2" | ||
| FRIENDLY_MIME_1 = FRIENDLY_MIME_TYPE_1() | ||
| FRIENDLY_MIME_2 = FRIENDLY_MIME_TYPE_2() | ||
| FRIENDLY_MIME_TYPE_UNION = Union{FRIENDLY_MIME_TYPE_1, FRIENDLY_MIME_TYPE_2} | ||
| Base.Multimedia.istextmime(::FRIENDLY_MIME_TYPE_UNION) = true | ||
| Base.show(io, ::FRIENDLY_MIME_TYPE_UNION, x::FriendlyData) = write(io, "Hello, $(x.name)!") | ||
| IJulia.register_mime([FRIENDLY_MIME_1, FRIENDLY_MIME_2]) | ||
|
|
||
| # We stringify then re-parse the dict so that JSONText's are parsed as | ||
| # actual JSON objects and we can index into them. | ||
| data = JSON.parse(JSON.json(IJulia.display_dict(friend))) | ||
| @test data[string(FRIENDLY_MIME)] == "Hello, world!" | ||
| @test data[string(BINARY_MIME)] == base64encode("Hello, world!") | ||
| @test data[string(JSON_MIME)]["name"] == "world" | ||
| @test data[string(FRIENDLY_MIME_1)] == "Hello, world!" | ||
| @test !haskey(data, string(FRIENDLY_MIME_2)) | ||
|
|
||
|
|
||
| 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.
Uh oh!
There was an error while loading. Please reload this page.