From ab6d9674a305722da6b0f74ed1b0f4d674d3da88 Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 21 May 2022 00:24:47 +0800 Subject: [PATCH] Add text/org show method for survey => result --- lib/Surveys.jl | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Surveys.jl b/lib/Surveys.jl index 96f9930..5bc3287 100644 --- a/lib/Surveys.jl +++ b/lib/Surveys.jl @@ -770,6 +770,11 @@ function show(io::IO, ::MIME"text/org", q::Question{T}) where {T} end end +function show(io::IO, ::MIME"text/org", (q, a)::Pair{<:Question, <:Answer}) + printstyled(io, "- ", q.prompt, " :: ", color=:blue) + println(io, join(split(string(a.value), '\n'), "\n ")) +end + function show(io::IO, m::MIME"text/org", part::SurveyPart) printstyled(io, "* ", if isnothing(part.label) "Unlabeled part" @@ -780,7 +785,16 @@ function show(io::IO, m::MIME"text/org", part::SurveyPart) print(io, '\n') for q in part.questions show(io, m, q) - q === last(part.questions) || print(io, "\n") + end +end + +function show(io::IO, m::MIME"text/org", (part, response)::Pair{SurveyPart, Response}) + printstyled(io, "* ", if isnothing(part.label) + "Unlabeled part" + else part.label end, "\n\n", color=:yellow) + foreach(part.questions) do q + show(io, m, q => response[q.id]) + last(part.questions) === q || print(io, '\n') end end @@ -797,4 +811,13 @@ function show(io::IO, m::MIME"text/org", s::Survey) end end +function show(io::IO, m::MIME"text/org", (s, response)::Pair{Survey, Response}) + printstyled(io, "#+title: ", s.name, "\n\n", color=:magenta) + parts = [s[p] for p in 1:length(s)] + for part in parts + show(io, m, part => response) + part === last(parts) || print(io, "\n\n") + end +end + end