Browse Source

bugfixes

pull/1/head
Fredrik Ekre 8 years ago
parent
commit
182b0d63fa
  1. 41
      src/Examples.jl

41
src/Examples.jl

@ -83,19 +83,22 @@ function parse(content)
return chunks return chunks
end end
filename(str) = first(splitext(last(splitdir(str))))
""" """
Examples.script(input, output; kwargs...) Examples.script(input, output; kwargs...)
Create a script file. Create a script file.
""" """
function script(input, output; kwargs...) function script(input, output; name = filename(input), kwargs...)
str = script(input; kwargs...) str = script(input; name = name, kwargs...)
write(output, str) out = isdir(output) ? joinpath(output, name * ".jl") : output
return output write(out, str)
return out
end end
function script(input; preprocess = identity, postprocess = identity, function script(input; preprocess = identity, postprocess = identity,
name = first(splitext(last(splitdir(input)))), kwargs...) name = filename(input), kwargs...)
# read content # read content
content = read(input, String) content = read(input, String)
@ -140,14 +143,15 @@ end
Generate a markdown file from the `input` file and write the result to the `output` file. Generate a markdown file from the `input` file and write the result to the `output` file.
""" """
function markdown(input, output; kwargs...) function markdown(input, output; name = filename(input), kwargs...)
str = markdown(input; kwargs...) str = markdown(input; name = name, kwargs...)
write(output, str) out = isdir(output) ? joinpath(output, name * ".md") : output
return output write(out, str)
return out
end end
function markdown(input; preprocess = identity, postprocess = identity, function markdown(input; preprocess = identity, postprocess = identity,
name = first(splitext(last(splitdir(input)))), name = filename(input),
codefence::Pair = "```@example $(name)" => "```", kwargs...) codefence::Pair = "```@example $(name)" => "```", kwargs...)
# read content # read content
content = read(input, String) content = read(input, String)
@ -205,23 +209,24 @@ end
Generate a notebook from the `input` file and write the result to the `output` file. Generate a notebook from the `input` file and write the result to the `output` file.
""" """
function notebook(input, output; execute::Bool=false, kwargs...) function notebook(input, output; execute::Bool=false,
str = notebook(input; kwargs...) name = filename(input), kwargs...)
# return str str = notebook(input; name = name, kwargs...)
write(output, str) out = isdir(output) ? joinpath(output, name * ".ipynb") : output
write(out, str)
if execute if execute
try try
run(`jupyter nbconvert --ExecutePreprocessor.timeout=-1 --to notebook --execute $(abspath(output)) --output $(first(splitext(last(splitdir(output))))).ipynb`) run(`jupyter nbconvert --ExecutePreprocessor.timeout=-1 --to notebook --execute $(abspath(out)) --output $(first(splitext(last(splitdir(out))))).ipynb`)
catch err catch err
@error("Error while executing notebook") print("Error while executing notebook.")
rethrow(err) rethrow(err)
end end
end end
return output return out
end end
function notebook(input; preprocess = identity, postprocess = identity, function notebook(input; preprocess = identity, postprocess = identity,
name = first(splitext(last(splitdir(input)))), kwargs...) name = filename(input), kwargs...)
# read content # read content
content = read(input, String) content = read(input, String)

Loading…
Cancel
Save