Skip to content

Commit

Permalink
rename mimewritable to showable
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Feb 21, 2018
1 parent 3835029 commit b9159da
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ end
@deprecate IOBuffer(maxsize::Integer) IOBuffer(read=true, write=true, maxsize=maxsize)

@deprecate reprmime(mime, x) repr(mime, x)
@deprecate mimewritable(mime, x) showable(mime, x)

# PR #23332
@deprecate ^(x, p::Integer) Base.power_by_squaring(x,p)
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,10 @@ export
istextmime,
MIME,
@MIME_str,
mimewritable,
popdisplay,
pushdisplay,
redisplay,
showable,
HTML,
Text,

Expand Down
24 changes: 12 additions & 12 deletions base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Multimedia

export AbstractDisplay, display, pushdisplay, popdisplay, displayable, redisplay,
MIME, @MIME_str, istextmime,
mimewritable, TextDisplay
showable, TextDisplay

###########################################################################
# We define a singleton type MIME{mime symbol} for each MIME type, so
Expand All @@ -25,23 +25,26 @@ print(io::IO, ::MIME{mime}) where {mime} = print(io, mime)
# in order to provide a way to export T as a given mime type.

"""
mimewritable(mime, x)
showable(mime, x)
Returns a boolean value indicating whether or not the object `x` can be written as the given
`mime` type. (By default, this is determined automatically by the existence of the
corresponding [`show`](@ref) method for `typeof(x)`.)
Returns a boolean value indicating whether or not the object `x` can be written
as the given `mime` type.
(By default, this is determined automatically by the existence of the
corresponding [`show`](@ref) method for `typeof(x)`. Some types provide custom `showable`
methods; for example, if the available MIME formats depend on the *value* of `x`.)
# Examples
```jldoctest
julia> mimewritable(MIME("text/plain"), rand(5))
julia> showable(MIME("text/plain"), rand(5))
true
julia> mimewritable(MIME("img/png"), rand(5))
julia> showable("img/png", rand(5))
false
```
"""
mimewritable(::MIME{mime}, x) where {mime} =
hasmethod(show, Tuple{IO, MIME{mime}, typeof(x)})
showable(::MIME{mime}, x) where {mime} = hasmethod(show, Tuple{IO, MIME{mime}, typeof(x)})
showable(m::AbstractString, x) = showable(MIME(m), x)

"""
show(io, mime, x)
Expand Down Expand Up @@ -73,10 +76,7 @@ The first argument to `show` can be an [`IOContext`](@ref) specifying output for
See [`IOContext`](@ref) for details.
"""
show(stream, mime, x)

# it is convenient to accept strings instead of ::MIME
show(io::IO, m::AbstractString, x) = show(io, MIME(m), x)
mimewritable(m::AbstractString, x) = mimewritable(MIME(m), x)

"""
repr(mime, x; context=nothing)
Expand Down
4 changes: 2 additions & 2 deletions doc/src/base/io-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Base.Multimedia.display
Base.Multimedia.redisplay
Base.Multimedia.displayable
Base.show(::Any, ::Any, ::Any)
Base.Multimedia.mimewritable
Base.Multimedia.showable
Base.repr(::Any, ::Any)
```

Expand All @@ -107,7 +107,7 @@ define a function `display(d::D, ::MIME"mime", x) = ...` that displays `x` as th
usually by calling [`show(io, mime, x)`](@ref) or [`repr(io, mime, x)`](@ref).
A `MethodError` should be thrown if `x` cannot be displayed
as that MIME type; this is automatic if one calls `show` or `repr`. Finally, one should define a function
`display(d::D, x)` that queries [`mimewritable(mime, x)`](@ref) for the `mime` types supported by `D`
`display(d::D, x)` that queries [`showable(mime, x)`](@ref) for the `mime` types supported by `D`
and displays the "best" one; a `MethodError` should be thrown if no supported MIME types are found
for `x`. Similarly, some subtypes may wish to override [`redisplay(d::D, ...)`](@ref Base.Multimedia.redisplay). (Again, one should
`import Base.display` to add new methods to `display`.) The return values of these functions are
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/render/rich.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

function bestmime(val)
for mime in ("text/html", "image/svg+xml", "image/png", "text/plain")
mimewritable(mime, val) && return MIME(Symbol(mime))
showable(mime, val) && return MIME(Symbol(mime))
end
error("Cannot render $val to Markdown.")
end
Expand Down

0 comments on commit b9159da

Please sign in to comment.