Skip to content

Commit 9896ed4

Browse files
committed
move file validation to the constructor
some other small changes: - validate_order: make sure `order` field is unique - show: remove extra new line for AbstractDemoCard
1 parent 189b79a commit 9896ed4

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

src/show.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Base: show
33
const indent_spaces = " "
44

55
function show(io::IO, card::AbstractDemoCard)
6-
println(io, basename(card))
6+
print(io, basename(card))
77
end
88

99
function show(io::IO, sec::DemoSection; level=1)
@@ -15,6 +15,7 @@ function show(io::IO, sec::DemoSection; level=1)
1515
foreach(sec.cards) do x
1616
print(io, repeat(indent_spaces, level))
1717
show(io, x)
18+
println(io)
1819
end
1920

2021
foreach(x->show(io, x; level=level+1), sec.subsections)

src/types/card.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ to your demofile. Currently supported types are:
1818
1919
"""
2020
function democard(path::String)::AbstractDemoCard
21-
validate_file(path)
2221
_, ext = splitext(path)
2322
if ext in markdown_exts
2423
return MarkdownDemoCard(path)

src/types/julia.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ mutable struct JuliaDemoCard <: AbstractDemoCard
7474
date::DateTime
7575
julia::VersionNumber
7676
hidden::Bool
77+
function JuliaDemoCard(
78+
path::String,
79+
cover::Union{String, Nothing},
80+
id::String,
81+
title::String,
82+
description::String,
83+
author::String,
84+
date::DateTime,
85+
julia::VersionNumber,
86+
hidden::Bool
87+
)
88+
isfile(path) || throw(ArgumentError("$(path) is not a valid file"))
89+
new(path, cover, id, title, description, author, date, julia, hidden)
90+
end
7791
end
7892

7993
function JuliaDemoCard(path::String)::JuliaDemoCard

src/types/markdown.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ mutable struct MarkdownDemoCard <: AbstractDemoCard
6767
author::String
6868
date::DateTime
6969
hidden::Bool
70+
function MarkdownDemoCard(
71+
path::String,
72+
cover::Union{String, Nothing},
73+
id::String,
74+
title::String,
75+
description::String,
76+
author::String,
77+
date::DateTime,
78+
hidden::Bool
79+
)
80+
isfile(path) || throw(ArgumentError("$(path) is not a valid file"))
81+
new(path, cover, id, title, description, author, date, hidden)
82+
end
7083
end
7184

7285
function MarkdownDemoCard(path::String)::MarkdownDemoCard

src/utils.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
function validate_file(path, filetype = :text)
2-
isfile(path) || throw(ArgumentError("$(path) is not a valid file"))
3-
check_ext(path, filetype)
4-
end
5-
6-
71
function check_ext(path, filetype = :text)
82
_, ext = splitext(path)
93
if filetype == :text
@@ -19,6 +13,7 @@ end
1913
### common utils for DemoPage and DemoSection
2014

2115
function validate_order(order::AbstractArray, x::Union{DemoPage, DemoSection})
16+
length(unique(order)) == length(order) || throw(ArgumentError("`\"order\"` entry should be unique."))
2217
default_order = get_default_order(x)
2318
if intersect(order, default_order) == union(order, default_order)
2419
return true

0 commit comments

Comments
 (0)