Browse Source

s/Examples/Literate

pull/5/head
Fredrik Ekre 8 years ago
parent
commit
f464e53fab
  1. 4
      .travis.yml
  2. 2
      LICENSE.md
  3. 18
      README.md
  4. 4
      appveyor.yml
  5. 14
      docs/make.jl
  6. 8
      docs/src/customprocessing.md
  7. 10
      docs/src/documenter.md
  8. 14
      docs/src/fileformat.md
  9. 18
      docs/src/index.md
  10. 6
      docs/src/outputformats.md
  11. 2
      examples/example.jl
  12. 8
      src/Literate.jl
  13. 86
      test/runtests.jl

4
.travis.yml

@ -18,6 +18,6 @@ git:
depth: 99999999 depth: 99999999
after_success: after_success:
# build docs # build docs
- julia -e 'Pkg.add("Documenter"); Pkg.checkout("Documenter"); cd(Pkg.dir("Examples")); include("docs/make.jl")' - julia -e 'Pkg.add("Documenter"); Pkg.checkout("Documenter"); cd(Pkg.dir("Literate")); include("docs/make.jl")'
# push coverage results to Codecov # push coverage results to Codecov
- julia -e 'cd(Pkg.dir("Examples")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' - julia -e 'cd(Pkg.dir("Literate")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

2
LICENSE.md

@ -1,4 +1,4 @@
The Examples.jl package is licensed under the MIT "Expat" License: The Literate.jl package is licensed under the MIT "Expat" License:
> Copyright (c) 2018: Fredrik Ekre. > Copyright (c) 2018: Fredrik Ekre.
> >

18
README.md

@ -1,26 +1,26 @@
# Examples # Literate
| **Documentation** | **Build Status** | | **Documentation** | **Build Status** |
|:--------------------------------------- |:----------------------------------------------------------------------------------------------- | |:--------------------------------------- |:----------------------------------------------------------------------------------------------- |
| [![][docs-latest-img]][docs-latest-url] | [![][travis-img]][travis-url] [![][appveyor-img]][appveyor-url] [![][codecov-img]][codecov-url] | | [![][docs-latest-img]][docs-latest-url] | [![][travis-img]][travis-url] [![][appveyor-img]][appveyor-url] [![][codecov-img]][codecov-url] |
`Examples.jl` is a package that, based on a single source file, generates markdown, `Literate.jl` is a package that, based on a single source file, generates markdown,
for e.g. [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl), for e.g. [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl),
[Jupyter notebooks](http://jupyter.org/) and uncommented scripts for documentation [Jupyter notebooks](http://jupyter.org/) and uncommented scripts for documentation
of your package. of your package.
[docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg [docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg
[docs-latest-url]: https://fredrikekre.github.io/Examples.jl/latest/ [docs-latest-url]: https://fredrikekre.github.io/Literate.jl/latest/
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg [docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg
[docs-stable-url]: https://fredrikekre.github.io/Examples.jl/stable [docs-stable-url]: https://fredrikekre.github.io/Literate.jl/stable
[travis-img]: https://travis-ci.org/fredrikekre/Examples.jl.svg?branch=master [travis-img]: https://travis-ci.org/fredrikekre/Literate.jl.svg?branch=master
[travis-url]: https://travis-ci.org/fredrikekre/Examples.jl [travis-url]: https://travis-ci.org/fredrikekre/Literate.jl
[appveyor-img]: https://ci.appveyor.com/api/projects/status/xe0ghtyas12wv555/branch/master?svg=true [appveyor-img]: https://ci.appveyor.com/api/projects/status/xe0ghtyas12wv555/branch/master?svg=true
[appveyor-url]: https://ci.appveyor.com/project/fredrikekre/Examples-jl/branch/master [appveyor-url]: https://ci.appveyor.com/project/fredrikekre/Literate-jl/branch/master
[codecov-img]: https://codecov.io/gh/fredrikekre/Examples.jl/branch/master/graph/badge.svg [codecov-img]: https://codecov.io/gh/fredrikekre/Literate.jl/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/fredrikekre/Examples.jl [codecov-url]: https://codecov.io/gh/fredrikekre/Literate.jl

4
appveyor.yml

@ -39,7 +39,7 @@ build_script:
# Need to convert from shallow to complete for Pkg.clone to work # Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow) - IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo(); - C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Examples\"); Pkg.build(\"Examples\")" Pkg.clone(pwd(), \"Literate\"); Pkg.build(\"Literate\")"
test_script: test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"Examples\")" - C:\projects\julia\bin\julia -e "Pkg.test(\"Literate\")"

14
docs/make.jl

@ -1,18 +1,18 @@
using Documenter using Documenter
using Examples using Literate
# generate examples # generate examples
EXAMPLE = joinpath(@__DIR__, "..", "examples", "example.jl") EXAMPLE = joinpath(@__DIR__, "..", "examples", "example.jl")
OUTPUT = joinpath(@__DIR__, "src/generated") OUTPUT = joinpath(@__DIR__, "src/generated")
Examples.markdown(EXAMPLE, OUTPUT) Literate.markdown(EXAMPLE, OUTPUT)
Examples.notebook(EXAMPLE, OUTPUT) Literate.notebook(EXAMPLE, OUTPUT)
Examples.script(EXAMPLE, OUTPUT) Literate.script(EXAMPLE, OUTPUT)
makedocs( makedocs(
modules = [Examples], modules = [Literate],
format = :html, format = :html,
sitename = "Examples.jl", sitename = "Literate.jl",
pages = Any[ pages = Any[
"index.md", "index.md",
"fileformat.md", "fileformat.md",
@ -24,7 +24,7 @@ makedocs(
) )
deploydocs( deploydocs(
repo = "github.com/fredrikekre/Examples.jl.git", repo = "github.com/fredrikekre/Literate.jl.git",
target = "build", target = "build",
deps = nothing, deps = nothing,
make = nothing make = nothing

8
docs/src/customprocessing.md

@ -5,12 +5,12 @@ to create a nice example for the documentation it is important that
the package maintainer does not feel limited by the by default provided syntax the package maintainer does not feel limited by the by default provided syntax
that this package offers. While you can generally come a long way by utilizing that this package offers. While you can generally come a long way by utilizing
[line filtering](@ref Filtering-lines) there might be situations where you need [line filtering](@ref Filtering-lines) there might be situations where you need
to manually hook into the generation and change things. In `Examples.jl` this to manually hook into the generation and change things. In `Literate.jl` this
is done by letting the user supply custom pre- and post-processing functions is done by letting the user supply custom pre- and post-processing functions
that may do transformation of the content. that may do transformation of the content.
All of the generators ([`Examples.markdown`](@ref), [`Examples.notebook`](@ref) All of the generators ([`Literate.markdown`](@ref), [`Literate.notebook`](@ref)
and [`Examples.script`](@ref)) accepts `preprocess` and `postprocess` keyword and [`Literate.script`](@ref)) accepts `preprocess` and `postprocess` keyword
arguments. The default "transformation" is the `identity` function. The input arguments. The default "transformation" is the `identity` function. The input
to the transformation functions is a `String`, and the output should be the to the transformation functions is a `String`, and the output should be the
transformed `String`. transformed `String`.
@ -43,5 +43,5 @@ end
which would replace every occurrence of `"DATEOFTODAY"` with the current date. We would which would replace every occurrence of `"DATEOFTODAY"` with the current date. We would
now simply give this function to the generator, for example: now simply give this function to the generator, for example:
```julia ```julia
Examples.markdown("input.jl", "outputdir"; preprocess = update_date) Literate.markdown("input.jl", "outputdir"; preprocess = update_date)
``` ```

10
docs/src/documenter.md

@ -1,14 +1,14 @@
# [**6.** Interaction with Documenter.jl](@id Interaction-with-Documenter) # [**6.** Interaction with Documenter.jl](@id Interaction-with-Documenter)
`Examples.jl` can be used for any purpose, it spits out regular markdown files, `Literate.jl` can be used for any purpose, it spits out regular markdown files,
and notebooks. Typically, though, these files will be used to render documentation and notebooks. Typically, though, these files will be used to render documentation
for your package. The generators ([`Examples.markdown`](@ref), [`Examples.notebook`](@ref) for your package. The generators ([`Literate.markdown`](@ref), [`Literate.notebook`](@ref)
and [`Examples.script`](@ref)) supports a keyword argument `documenter` that lets and [`Literate.script`](@ref)) supports a keyword argument `documenter` that lets
the generator perform some extra things, keeping in mind that the generated files will, the generator perform some extra things, keeping in mind that the generated files will,
eventually, be used with Documenter.jl. So lets take a look at what will happen eventually, be used with Documenter.jl. So lets take a look at what will happen
if we set `documenter = true`: if we set `documenter = true`:
[`Examples.markdown`](@ref): [`Literate.markdown`](@ref):
- The default code fence will change from - The default code fence will change from
```` ````
```julia ```julia
@ -30,7 +30,7 @@ if we set `documenter = true`:
``` ```
```` ````
[`Examples.notebook`](@ref): [`Literate.notebook`](@ref):
- Documenter style `@ref`s and `@id` will be removed. This means that you can use - Documenter style `@ref`s and `@id` will be removed. This means that you can use
`@ref` and `@id` in the source file without them leaking to the notebook. `@ref` and `@id` in the source file without them leaking to the notebook.
- Documenter style markdown math - Documenter style markdown math

14
docs/src/fileformat.md

@ -1,6 +1,6 @@
# **2.** File Format # **2.** File Format
The source file format for `Examples.jl` is a regular, commented, julia (`.jl`) scripts. The source file format for `Literate.jl` is a regular, commented, julia (`.jl`) scripts.
The idea is that the scripts also serve as documentation on their own and it is also The idea is that the scripts also serve as documentation on their own and it is also
simple to include them in the test-suite, with e.g. `include`, to make sure the examples simple to include them in the test-suite, with e.g. `include`, to make sure the examples
stay up do date with other changes in your package. stay up do date with other changes in your package.
@ -36,7 +36,7 @@ julia code. We note a couple of things:
For simple use this is all you need to know, the script above is valid. Let's take a look For simple use this is all you need to know, the script above is valid. Let's take a look
at what the above snippet would generate, with default settings: at what the above snippet would generate, with default settings:
- [`Examples.markdown`](@ref): leading `#'` are removed, and code lines are wrapped in - [`Literate.markdown`](@ref): leading `#'` are removed, and code lines are wrapped in
`@example`-blocks: `@example`-blocks:
````markdown ````markdown
# Rational numbers # Rational numbers
@ -56,7 +56,7 @@ at what the above snippet would generate, with default settings:
``` ```
```` ````
- [`Examples.notebook`](@ref): leading `#'` are removed, markdown lines are placed in - [`Literate.notebook`](@ref): leading `#'` are removed, markdown lines are placed in
`"markdown"` cells, and code lines in `"code"` cells: `"markdown"` cells, and code lines in `"code"` cells:
``` ```
│ # Rational numbers │ # Rational numbers
@ -76,7 +76,7 @@ at what the above snippet would generate, with default settings:
Out [2]: │ 11//15 Out [2]: │ 11//15
``` ```
- [`Examples.script`](@ref): all lines starting with `#'` are removed: - [`Literate.script`](@ref): all lines starting with `#'` are removed:
```julia ```julia
x = 1//3 x = 1//3
y = 2//5 y = 2//5
@ -101,9 +101,9 @@ since `@docs` is Documenter syntax that the notebook will not understand. This
is a case where we can prepend `#md` to those lines: is a case where we can prepend `#md` to those lines:
````julia ````julia
#md #' ```@docs #md #' ```@docs
#md #' Examples.markdown #md #' Literate.markdown
#md #' Examples.notebook #md #' Literate.notebook
#md #' Examples.markdown #md #' Literate.markdown
#md #' ``` #md #' ```
```` ````
The lines in the example above would be filtered out in the preprocessing step, unless we are The lines in the example above would be filtered out in the preprocessing step, unless we are

18
docs/src/index.md

@ -1,11 +1,11 @@
# **1.** Introduction # **1.** Introduction
Welcome to the documentation for `Examples.jl`. A simplistic package Welcome to the documentation for `Literate.jl`. A simplistic package
to help you organize examples for you package documentation. to help you organize examples for you package documentation.
### What? ### What?
`Examples.jl` is a package that, based on a single source file, generates markdown, `Literate.jl` is a package that, based on a single source file, generates markdown,
for e.g. [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl), for e.g. [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl),
[Jupyter notebooks](http://jupyter.org/) and uncommented scripts for documentation [Jupyter notebooks](http://jupyter.org/) and uncommented scripts for documentation
of your package. of your package.
@ -15,20 +15,20 @@ be simple. In short all you have to do is to write a commented julia script!
The package consists mainly of three functions, which all takes the same script file The package consists mainly of three functions, which all takes the same script file
as input, but generates different output: as input, but generates different output:
- [`Examples.markdown`](@ref): generates a markdown file - [`Literate.markdown`](@ref): generates a markdown file
- [`Examples.notebook`](@ref): generates an (optionally executed) notebook - [`Literate.notebook`](@ref): generates an (optionally executed) notebook
- [`Examples.script`](@ref): generates a plain script file, removing everything - [`Literate.script`](@ref): generates a plain script file, removing everything
that is not code that is not code
### Why? ### Why?
Examples are (probably) the best way to showcase your awesome package, and examples Literate are (probably) the best way to showcase your awesome package, and examples
are often the best way for a new user to learn how to use it. It is therefore important are often the best way for a new user to learn how to use it. It is therefore important
that the documentation of your package contains examples for users to read and study. that the documentation of your package contains examples for users to read and study.
However, people are different, and we all prefer different ways of trying out a new However, people are different, and we all prefer different ways of trying out a new
package. Some people wants to RTFM, others want to explore the package interactively in, package. Some people wants to RTFM, others want to explore the package interactively in,
for example, a notebook, and some people wants to study the source code. The aim of for example, a notebook, and some people wants to study the source code. The aim of
`Examples.jl` is to make it easy to give the user all of these options, while still `Literate.jl` is to make it easy to give the user all of these options, while still
keeping maintenance to a minimum. keeping maintenance to a minimum.
It is quite common that packages have "example notebooks" to showcase the package. It is quite common that packages have "example notebooks" to showcase the package.
@ -42,8 +42,8 @@ by using [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl) `@example`-
This is also great, but it is not quite as interactive as a notebook, for the users This is also great, but it is not quite as interactive as a notebook, for the users
who prefer that. who prefer that.
`Examples.jl` tries to solve the problems above by creating the output as a part of the doc `Literate.jl` tries to solve the problems above by creating the output as a part of the doc
build. `Examples.jl` generates the output from a single source file which makes it easier to build. `Literate.jl` generates the output from a single source file which makes it easier to
maintain, test, and keep the manual and your example notebooks in sync. maintain, test, and keep the manual and your example notebooks in sync.
### How? ### How?

6
docs/src/outputformats.md

@ -33,18 +33,18 @@ y = x.^2 - x
```` ````
```@docs ```@docs
Examples.markdown Literate.markdown
``` ```
## [**4.2.** Notebook output](@id Notebook-output) ## [**4.2.** Notebook output](@id Notebook-output)
```@docs ```@docs
Examples.notebook Literate.notebook
``` ```
## [**4.3.** Script output](@id Script-output) ## [**4.3.** Script output](@id Script-output)
```@docs ```@docs
Examples.script Literate.script
``` ```

2
examples/example.jl

@ -1,6 +1,6 @@
#' # **7.** Example #' # **7.** Example
#' #'
#' This is an example for Examples.jl. #' This is an example for Literate.jl.
#' The source file can be found [here](@__REPO_ROOT_URL__examples/example.jl). #' The source file can be found [here](@__REPO_ROOT_URL__examples/example.jl).
#' The generated markdown can be found here: [`example.md`](./example.md), the #' The generated markdown can be found here: [`example.md`](./example.md), the
#' generated notebook can be found here: #' generated notebook can be found here:

8
src/Examples.jl → src/Literate.jl

@ -1,4 +1,4 @@
module Examples module Literate
import Compat: replace, popfirst!, @error, @info import Compat: replace, popfirst!, @error, @info
@ -92,7 +92,7 @@ end
filename(str) = first(splitext(last(splitdir(str)))) filename(str) = first(splitext(last(splitdir(str))))
""" """
Examples.script(inputfile, outputdir; kwargs...) Literate.script(inputfile, outputdir; kwargs...)
Generate a plain script file from `inputfile` and write the result to `outputdir`. Generate a plain script file from `inputfile` and write the result to `outputdir`.
@ -160,7 +160,7 @@ function script(inputfile, outputdir; preprocess = identity, postprocess = ident
end end
""" """
Examples.markdown(inputfile, outputdir; kwargs...) Literate.markdown(inputfile, outputdir; kwargs...)
Generate a markdown file from `inputfile` and write the result Generate a markdown file from `inputfile` and write the result
to the directory`outputdir`. to the directory`outputdir`.
@ -270,7 +270,7 @@ end
const JUPYTER_VERSION = v"4.3.0" const JUPYTER_VERSION = v"4.3.0"
""" """
Examples.notebook(inputfile, outputdir; kwargs...) Literate.notebook(inputfile, outputdir; kwargs...)
Generate a notebook from `inputfile` and write the result to `outputdir`. Generate a notebook from `inputfile` and write the result to `outputdir`.

86
test/runtests.jl

@ -1,5 +1,5 @@
import Examples import Literate
import Examples: Chunk, MDChunk, CodeChunk import Literate: Chunk, MDChunk, CodeChunk
using Compat.Test using Compat.Test
# compare content of two parsed chunk vectors # compare content of two parsed chunk vectors
@ -22,7 +22,7 @@ function compare_chunks(chunks1, chunks2)
end end
end end
@testset "Examples.parse" begin @testset "Literate.parse" begin
content = """ content = """
#' Line 1 #' Line 1
Line 2 Line 2
@ -112,7 +112,7 @@ end
CodeChunk(["#Line 49", "Line 50"], false), CodeChunk(["#Line 49", "Line 50"], false),
MDChunk(["Line 53"]), MDChunk(["Line 53"]),
] ]
parsed_chunks = Examples.parse(content) parsed_chunks = Literate.parse(content)
compare_chunks(parsed_chunks, expected_chunks) compare_chunks(parsed_chunks, expected_chunks)
# test leading/trailing whitespace removal # test leading/trailing whitespace removal
@ -131,7 +131,7 @@ end
foreach(x -> println(iows), 1:rand(2:5)) foreach(x -> println(iows), 1:rand(2:5))
end end
compare_chunks(Examples.parse(String(take!(io))), Examples.parse(String(take!(iows)))) compare_chunks(Literate.parse(String(take!(io))), Literate.parse(String(take!(iows))))
end # testset parser end # testset parser
@ -170,7 +170,7 @@ content = """
#' ``` #' ```
""" """
@testset "Examples.script" begin @testset "Literate.script" begin
mktempdir(@__DIR__) do sandbox mktempdir(@__DIR__) do sandbox
cd(sandbox) do cd(sandbox) do
# write content to inputfile # write content to inputfile
@ -179,10 +179,10 @@ content = """
outdir = mktempdir(pwd()) outdir = mktempdir(pwd())
# test defaults # test defaults
withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl",
"TRAVIS_TAG" => "v1.2.0", "TRAVIS_TAG" => "v1.2.0",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do
Examples.script(inputfile, outdir) Literate.script(inputfile, outdir)
end end
expected_script = """ expected_script = """
x = 1 x = 1
@ -198,9 +198,9 @@ content = """
end end
# Link to repo root: https://github.com/fredrikekre/Examples.jl/blob/master/ # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/
# Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/ # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/
# PLACEHOLDER3 # PLACEHOLDER3
# PLACEHOLDER4 # PLACEHOLDER4
@ -210,16 +210,16 @@ content = """
@test script == expected_script @test script == expected_script
# no tag -> latest directory # no tag -> latest directory
withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl",
"TRAVIS_TAG" => "", "TRAVIS_TAG" => "",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do
Examples.script(inputfile, outdir) Literate.script(inputfile, outdir)
end end
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@test contains(script, "fredrikekre/Examples.jl/blob/gh-pages/latest/") @test contains(script, "fredrikekre/Literate.jl/blob/gh-pages/latest/")
# pre- and post-processing # pre- and post-processing
Examples.script(inputfile, outdir, Literate.script(inputfile, outdir,
preprocess = x -> replace(x, "PLACEHOLDER3" => "3REDLOHECALP"), preprocess = x -> replace(x, "PLACEHOLDER3" => "3REDLOHECALP"),
postprocess = x -> replace(x, "PLACEHOLDER4" => "4REDLOHECALP")) postprocess = x -> replace(x, "PLACEHOLDER4" => "4REDLOHECALP"))
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@ -231,13 +231,13 @@ content = """
@test contains(script, "4REDLOHECALP") @test contains(script, "4REDLOHECALP")
# name # name
Examples.script(inputfile, outdir, name = "foobar") Literate.script(inputfile, outdir, name = "foobar")
@test isfile(joinpath(outdir, "foobar.jl")) @test isfile(joinpath(outdir, "foobar.jl"))
end end
end end
end end
@testset "Examples.markdown" begin @testset "Literate.markdown" begin
mktempdir(@__DIR__) do sandbox mktempdir(@__DIR__) do sandbox
cd(sandbox) do cd(sandbox) do
# write content to inputfile # write content to inputfile
@ -246,14 +246,14 @@ end
outdir = mktempdir(pwd()) outdir = mktempdir(pwd())
# test defaults # test defaults
withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl",
"TRAVIS_TAG" => "v1.2.0", "TRAVIS_TAG" => "v1.2.0",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do
Examples.markdown(inputfile, outdir) Literate.markdown(inputfile, outdir)
end end
expected_markdown = """ expected_markdown = """
```@meta ```@meta
EditURL = "https://github.com/fredrikekre/Examples.jl/blob/master/test/$(basename(sandbox))/inputfile.jl" EditURL = "https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl"
``` ```
# [Example](@id example-id) # [Example](@id example-id)
@ -282,16 +282,16 @@ end
end end
``` ```
Link to repo root: https://github.com/fredrikekre/Examples.jl/blob/master/ Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/
```@example inputfile ```@example inputfile
# Link to repo root: https://github.com/fredrikekre/Examples.jl/blob/master/ # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/
``` ```
Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/ Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/
```@example inputfile ```@example inputfile
# Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/ # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/
``` ```
PLACEHOLDER1 PLACEHOLDER1
@ -312,16 +312,16 @@ end
@test markdown == expected_markdown @test markdown == expected_markdown
# no tag -> latest directory # no tag -> latest directory
withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl",
"TRAVIS_TAG" => "", "TRAVIS_TAG" => "",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do
Examples.markdown(inputfile, outdir) Literate.markdown(inputfile, outdir)
end end
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@test contains(markdown, "fredrikekre/Examples.jl/blob/gh-pages/latest/") @test contains(markdown, "fredrikekre/Literate.jl/blob/gh-pages/latest/")
# pre- and post-processing # pre- and post-processing
Examples.markdown(inputfile, outdir, Literate.markdown(inputfile, outdir,
preprocess = x -> replace(replace(x, "PLACEHOLDER1" => "1REDLOHECALP"), "PLACEHOLDER3" => "3REDLOHECALP"), preprocess = x -> replace(replace(x, "PLACEHOLDER1" => "1REDLOHECALP"), "PLACEHOLDER3" => "3REDLOHECALP"),
postprocess = x -> replace(replace(x, "PLACEHOLDER2" => "2REDLOHECALP"), "PLACEHOLDER4" => "4REDLOHECALP")) postprocess = x -> replace(replace(x, "PLACEHOLDER2" => "2REDLOHECALP"), "PLACEHOLDER4" => "4REDLOHECALP"))
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@ -335,7 +335,7 @@ end
@test contains(markdown, "4REDLOHECALP") @test contains(markdown, "4REDLOHECALP")
# documenter = false # documenter = false
Examples.markdown(inputfile, outdir, documenter = false) Literate.markdown(inputfile, outdir, documenter = false)
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@test contains(markdown, "```julia") @test contains(markdown, "```julia")
@test !contains(markdown, "```@example") @test !contains(markdown, "```@example")
@ -343,14 +343,14 @@ end
@test !contains(markdown, "EditURL") @test !contains(markdown, "EditURL")
# codefence # codefence
Examples.markdown(inputfile, outdir, codefence = "```c" => "```") Literate.markdown(inputfile, outdir, codefence = "```c" => "```")
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@test contains(markdown, "```c") @test contains(markdown, "```c")
@test !contains(markdown, "```@example") @test !contains(markdown, "```@example")
@test !contains(markdown, "```julia") @test !contains(markdown, "```julia")
# name # name
Examples.markdown(inputfile, outdir, name = "foobar") Literate.markdown(inputfile, outdir, name = "foobar")
markdown = read(joinpath(outdir, "foobar.md"), String) markdown = read(joinpath(outdir, "foobar.md"), String)
@test contains(markdown, "```@example foobar") @test contains(markdown, "```@example foobar")
@test !contains(markdown, "```@example inputfile") @test !contains(markdown, "```@example inputfile")
@ -358,7 +358,7 @@ end
end end
end end
@testset "Examples.notebook" begin @testset "Literate.notebook" begin
mktempdir(@__DIR__) do sandbox mktempdir(@__DIR__) do sandbox
cd(sandbox) do cd(sandbox) do
# write content to inputfile # write content to inputfile
@ -367,10 +367,10 @@ end
outdir = mktempdir(pwd()) outdir = mktempdir(pwd())
# test defaults # test defaults
withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl",
"TRAVIS_TAG" => "v1.2.0", "TRAVIS_TAG" => "v1.2.0",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do
Examples.notebook(inputfile, outdir, execute = false) Literate.notebook(inputfile, outdir, execute = false)
end end
expected_cells = rstrip.(( expected_cells = rstrip.((
""" """
@ -425,25 +425,25 @@ end
""" """
"source": [ "source": [
"Link to repo root: https://github.com/fredrikekre/Examples.jl/blob/master/" "Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/"
] ]
""", """,
""" """
"source": [ "source": [
"# Link to repo root: https://github.com/fredrikekre/Examples.jl/blob/master/" "# Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/"
] ]
""", """,
""" """
"source": [ "source": [
"Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/" "Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/"
] ]
""", """,
""" """
"source": [ "source": [
"# Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/" "# Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/"
] ]
""", """,
@ -487,13 +487,13 @@ end
end end
# no tag -> latest directory # no tag -> latest directory
withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl",
"TRAVIS_TAG" => "", "TRAVIS_TAG" => "",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do
Examples.notebook(inputfile, outdir, execute = false) Literate.notebook(inputfile, outdir, execute = false)
end end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test contains(notebook, "fredrikekre/Examples.jl/blob/gh-pages/latest/") @test contains(notebook, "fredrikekre/Literate.jl/blob/gh-pages/latest/")
# pre- and post-processing # pre- and post-processing
function post(nb) function post(nb)
@ -505,7 +505,7 @@ end
end end
return nb return nb
end end
Examples.notebook(inputfile, outdir, execute = false, Literate.notebook(inputfile, outdir, execute = false,
preprocess = x -> replace(replace(x, "PLACEHOLDER1" => "1REDLOHECALP"), "PLACEHOLDER3" => "3REDLOHECALP"), preprocess = x -> replace(replace(x, "PLACEHOLDER1" => "1REDLOHECALP"), "PLACEHOLDER3" => "3REDLOHECALP"),
postprocess = post) postprocess = post)
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@ -519,13 +519,13 @@ end
@test contains(notebook, "4REDLOHECALP") @test contains(notebook, "4REDLOHECALP")
# documenter = false # documenter = false
Examples.notebook(inputfile, outdir, documenter = false, execute = false) Literate.notebook(inputfile, outdir, documenter = false, execute = false)
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test contains(notebook, "# [Example](@id example-id") @test contains(notebook, "# [Example](@id example-id")
@test contains(notebook, "[foo](@ref), [bar](@ref bbaarr)") @test contains(notebook, "[foo](@ref), [bar](@ref bbaarr)")
# name # name
Examples.notebook(inputfile, outdir, name = "foobar", execute = false) Literate.notebook(inputfile, outdir, name = "foobar", execute = false)
@test isfile(joinpath(outdir, "foobar.ipynb")) @test isfile(joinpath(outdir, "foobar.ipynb"))
end end
end end

Loading…
Cancel
Save