Skip to content

Commit

Permalink
Merge pull request #395 from MichaelHatherly/mh/backports
Browse files Browse the repository at this point in the history
Backports for 0.8.8
  • Loading branch information
MichaelHatherly authored Dec 30, 2016
2 parents 7059478 + 808ec29 commit 9d5883b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
7 changes: 1 addition & 6 deletions src/DocChecks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,7 @@ end

# Remove terminal colors.

const TERM_COLOR_REGEX =
let _1 = map(escape_string, values(Base.text_colors)),
_2 = map(each -> replace(each, "[", "\\["), _1)
Regex(string("(\\e\\[31m|\\e\\[22m|", join(_2, "|"), ")"))
end

const TERM_COLOR_REGEX = r"\e\[[0-9;]*m"
remove_term_colors(s) = replace(s, TERM_COLOR_REGEX, "")

# REPL doctest splitter.
Expand Down
16 changes: 7 additions & 9 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,22 @@ Returns the set of submodules of a given root module/s.
function submodules(modules::Vector{Module})
out = Set{Module}()
for each in modules
union!(out, submodules(each))
submodules(each, out)
end
out
end
function submodules(root::Module, out = Set([root]))
function submodules(root::Module, seen = Set{Module}())
push!(seen, root)
for name in names(root, true)
if isdefined(root, name) && !isdeprecated(root, name)
if Base.isidentifier(name) && isdefined(root, name) && !isdeprecated(root, name)
object = getfield(root, name)
if isvalidmodule(root, object)
push!(out, object)
submodules(object, out)
if isa(object, Module) && !(object in seen)
submodules(object, seen)
end
end
end
out
return seen
end
isvalidmodule(a::Module, b::Module) = a !== b && b !== Main
isvalidmodule(a, b) = false

# Compat for `isdeprecated` which does not exist in Julia 0.4.
if isdefined(Base, :isdeprecated)
Expand Down
10 changes: 10 additions & 0 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ module UnitTests
Base.length(::T) = 1
end

module OuterModule
module InnerModule
import ..OuterModule
export OuterModule
end
end

@testset "Utilities" begin
let doc = @doc(length)
a = Documenter.Utilities.filterdocs(doc, Set{Module}())
Expand Down Expand Up @@ -55,6 +62,9 @@ end
@test UnitTests.A.B in Documenter.Utilities.submodules(UnitTests.A)
@test UnitTests.A.B.C in Documenter.Utilities.submodules(UnitTests.A)
@test UnitTests.A.B.C.D in Documenter.Utilities.submodules(UnitTests.A)
@test OuterModule in Documenter.Utilities.submodules(OuterModule)
@test OuterModule.InnerModule in Documenter.Utilities.submodules(OuterModule)
@test length(Documenter.Utilities.submodules(OuterModule)) == 2
end

end

0 comments on commit 9d5883b

Please sign in to comment.