Skip to content

Commit 1668567

Browse files
authored
Add README and LICENSE (#68)
* Add README and LICENSE to make it possible to splice in the package README.md and LICENSE.md in docstrings. * Updates for Documenter v0.20.
1 parent 8e9da56 commit 1668567

File tree

7 files changed

+75
-9
lines changed

7 files changed

+75
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.jl.mem
44
docs/build
55
docs/site
6+
docs/Manifest.toml

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ after_success:
1919

2020
jobs:
2121
include:
22-
- stage: "Deploy docs"
22+
- stage: "Documentation"
2323
julia: 1.0
2424
os: linux
2525
script:
26-
- julia -e 'using Pkg; Pkg.add([PackageSpec("Documenter"), PackageSpec(path=pwd())])'
27-
- julia docs/make.jl
26+
- julia --project=docs/ -e 'using Pkg; Pkg.add(PackageSpec(path=pwd()));
27+
Pkg.instantiate()'
28+
- julia --project=docs/ docs/make.jl
2829
after_success: skip

docs/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
4+
[compat]
5+
Documenter = "~0.20"

docs/make.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@ using Documenter, DocStringExtensions
33
makedocs(
44
sitename = "DocStringExtensions.jl",
55
modules = [DocStringExtensions],
6-
format = :html,
76
clean = false,
87
pages = Any["Home" => "index.md"],
98
)
109

1110
deploydocs(
12-
target = "build",
13-
deps = nothing,
14-
make = nothing,
1511
repo = "github.com/JuliaDocs/DocStringExtensions.jl.git",
16-
julia = "1.0",
1712
)
18-

src/DocStringExtensions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ module DocStringExtensions
7878
# Exports.
7979

8080
export @template, FIELDS, EXPORTS, METHODLIST, IMPORTS, SIGNATURES, TYPEDEF, DOCSTRING, FUNCTIONNAME
81+
export README, LICENSE
8182

8283
# Includes.
8384

src/abbreviations.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,60 @@ function format(::TypeDefinition, buf, doc)
445445
end
446446
end
447447

448+
"""
449+
The singleton type for [`README`](@ref) abbreviations.
450+
"""
451+
struct Readme <: Abbreviation end
452+
"""
453+
README
454+
455+
An [`Abbreviation`](@ref) for including the package README.md.
456+
457+
!!! note
458+
The README.md file is interpreted as ["Julia flavored Markdown"]
459+
(https://docs.julialang.org/en/v1/manual/documentation/#Markdown-syntax-1),
460+
which has some differences compared to GitHub flavored markdown, and,
461+
for example, [][] link shortcuts are not supported.
462+
"""
463+
const README = Readme()
464+
"""
465+
The singleton type for [`LICENSE`](@ref) abbreviations.
466+
"""
467+
struct License <: Abbreviation end
468+
"""
469+
LICENSE
470+
471+
An [`Abbreviation`](@ref) for including the package LICENSE.md.
472+
473+
!!! note
474+
The LICENSE.md file is interpreted as ["Julia flavored Markdown"]
475+
(https://docs.julialang.org/en/v1/manual/documentation/#Markdown-syntax-1),
476+
which has some differences compared to GitHub flavored markdown, and,
477+
for example, [][] link shortcuts are not supported.
478+
"""
479+
const LICENSE = License()
480+
481+
function format(::T, buf, doc) where T <: Union{Readme,License}
482+
m = get(doc.data, :module, nothing)
483+
m === nothing && return
484+
path = pathof(m)
485+
path === nothing && return
486+
try # wrap in try/catch since we shouldn't error in case some IO operation goes wrong
487+
r = T === Readme ? r"(?i)readme(?-i)" : r"(?i)license(?-i)"
488+
# assume README/LICENSE is located in the root of the repo
489+
root = normpath(joinpath(path, "..", ".."))
490+
for file in readdir(root)
491+
if occursin(r, file)
492+
str = read(joinpath(root, file), String)
493+
write(buf, str)
494+
return
495+
end
496+
end
497+
catch
498+
end
499+
end
500+
501+
448502
#
449503
# `DocStringTemplate`
450504
#

test/tests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ end
230230
str = String(take!(buf))
231231
@test str == "\n```julia\nprimitive type BitType32 <: Real 32\n```\n\n"
232232
end
233+
234+
@testset "README/LICENSE" begin
235+
doc.data = Dict(:module => DocStringExtensions)
236+
DSE.format(README, buf, doc)
237+
str = String(take!(buf))
238+
@test occursin("*Extensions for Julia's docsystem.*", str)
239+
DSE.format(LICENSE, buf, doc)
240+
str = String(take!(buf))
241+
@test occursin("MIT \"Expat\" License", str)
242+
end
233243
end
234244
@testset "templates" begin
235245
let fmt = expr -> Markdown.plain(eval(:(@doc $expr)))

0 commit comments

Comments
 (0)