Skip to content

Commit 61412ad

Browse files
authored
warnings on unmatched files (#87)
1 parent 66a7917 commit 61412ad

File tree

7 files changed

+34
-5
lines changed

7 files changed

+34
-5
lines changed

src/preview.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function preview_demos(demo_path::String;
5757
copy_assets_and_configs(page_dir, build_dir)
5858

5959
cd(build_dir) do
60-
page = DemoPage(page_dir)
60+
page = @suppress_err DemoPage(page_dir)
6161

6262
if theme === missing
6363
theme = page.theme

src/types/card.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
abstract type AbstractDemoCard end
22

3+
struct UnmatchedCard <: AbstractDemoCard
4+
path::String
5+
end
6+
37
"""
48
democard(path::String)::T
59
@@ -8,8 +12,9 @@ Constructs a concrete AbstractDemoCard instance.
812
The return type `T` is determined by the extension of the path
913
to your demofile. Currently supported types are:
1014
11-
* [`MarkdownDemoCard`](@ref)
12-
* [`JuliaDemoCard`](@ref)
15+
* [`MarkdownDemoCard`](@ref) for markdown files
16+
* [`JuliaDemoCard`](@ref) for julia files
17+
* [`UnmatchedCard`](@ref) for unmatched files
1318
1419
"""
1520
function democard(path::String)::AbstractDemoCard
@@ -20,7 +25,7 @@ function democard(path::String)::AbstractDemoCard
2025
elseif ext in julia_exts
2126
return JuliaDemoCard(path)
2227
else
23-
throw(ArgumentError("unrecognized democard format $(path)"))
28+
return UnmatchedCard(path)
2429
end
2530
end
2631

src/types/section.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,23 @@ function DemoSection(root::String)::DemoSection
9494
config_file = joinpath(root, config_filename)
9595
config = isfile(config_file) ? JSON.parsefile(config_file) : Dict()
9696

97+
# For files that `democard` fails to recognized, dummy
98+
# `UnmatchedCard` will be generated. Currently, we only
99+
# throw warnings for it.
100+
cards = map(democard, card_paths)
101+
unmatches = filter(cards) do x
102+
x isa UnmatchedCard
103+
end
104+
if !isempty(unmatches)
105+
msg = join(map(basename, unmatches), "\", \"")
106+
@warn "skip unmatched file: \"$msg\"" section_dir=root
107+
end
108+
cards = filter!(cards) do x
109+
!(x isa UnmatchedCard)
110+
end
111+
97112
section = DemoSection(root,
98-
map(democard, card_paths),
113+
cards,
99114
map(DemoSection, section_paths),
100115
"",
101116
"")

test/assets/section/dirty/card_2.md

Whitespace-only changes.

test/assets/section/dirty/data.csv

Whitespace-only changes.

test/assets/section/dirty/script.py

Whitespace-only changes.

test/types/section.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,13 @@
3636
# invalid cases
3737
@test_throws ArgumentError @suppress_err DemoSection(joinpath(root, "partial_order"))
3838
@test_throws ArgumentError @suppress_err DemoSection(joinpath(root, "cards_and_subsections"))
39+
40+
@testset "unmatched dirty files" begin
41+
msg = @capture_err DemoSection(joinpath(root, "dirty"))
42+
@test occursin("skip unmatched file: \"data.csv\", \"script.py\"", msg)
43+
sec = @suppress_err DemoSection(joinpath(root, "dirty"))
44+
45+
# unmatched files are excluded during the structure building stage.
46+
@test length(sec.cards) == 1
47+
end
3948
end

0 commit comments

Comments
 (0)