Skip to content

Commit 84efaa2

Browse files
author
Pietro Vertechi
authored
copy assets folder, do not show src folder to user (#42)
* copy assets folder * rework folder structure * update README * use Glob * add title option in example make file
1 parent 5f25455 commit 84efaa2

File tree

12 files changed

+115
-43
lines changed

12 files changed

+115
-43
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name = "Remark"
22
uuid = "79b45036-8e38-5d04-8f49-b9fb23ff5a0d"
33
authors = ["Pietro Vertechi <[email protected]>"]
4-
version = "0.2.1"
4+
version = "0.3.0"
55

66
[deps]
77
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
88
DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85"
99
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1010
DocumenterMarkdown = "997ab1e6-3595-5248-9280-8efb232c3433"
11+
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
1112
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1213
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
1314
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -17,6 +18,7 @@ BinaryProvider = "0.5"
1718
DefaultApplication = "1"
1819
Documenter = "0.20, 0.21, 0.22, 0.23, 0.24, 0.25"
1920
DocumenterMarkdown = "0.2"
21+
Glob = "1"
2022
JSON = "0.21"
2123
Literate = "2"
2224
julia = "0.7, 1"

README.md

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,71 @@ To install type the following command in the Julia Pkg REPL
1313
(v1.0) pkg> add Remark
1414
```
1515

16-
Check out the [Remark docs](https://github.com/gnab/remark/wiki/Markdown) on how to write the markdown for a Remark slideshow. The most important thing is to use `---` to separate slides; an example markdown file can be found [here](https://github.com/piever/Remark.jl/blob/master/examples/example.md).
16+
Check out the [Remark docs](https://github.com/gnab/remark/wiki/Markdown) on how to write the markdown for a Remark slideshow. The most important thing is to use `---` to separate slides; an example markdown file can be found [here](https://github.com/piever/Remark.jl/blob/master/examples/markdown/src/index.md).
1717

1818
```julia
1919
import Remark
2020

21-
# Generate a presentation (html+markdown) from the markdown file "example.md"
22-
# and save it in the folder "presentation/mybeautifulslides".
23-
slideshowdir = Remark.slideshow("example.md", "presentation/mybeautifulslides",
24-
options = Dict("ratio" => "16:9"))
21+
# Generate a presentation (html+markdown) from the markdown template
22+
# and save it in the folder "presentation".
23+
markdown_template = joinpath(dirname(dirname(pathof(Remark))), "examples", "markdown")
24+
cp(markdown_template, "presentation")
25+
slideshowdir = Remark.slideshow("presentation",
26+
options = Dict("ratio" => "16:9"),
27+
title = "My beautiful slides")
2528

2629
# Open presentation in default browser.
2730
Remark.open(slideshowdir)
2831
```
2932

30-
## Features
33+
The `presentation` folder will also include a `make.jl` file that can be used to automatically rebuild the presentation (it is enough to `include` it).
34+
Of course, the `make.jl` file can be customized to fit your needs, e.g., setting keyword arguments of `Remark.slideshow` or activating a `Project.toml` file for reproducibility.
3135

32-
- The `slideshow` command creates a slideshow that uses local javascript libraries: the resulting presentation folder can be opened offline.
36+
It is also possible to use a julia file as a starting point (i.e., `index.jl`), thanks to the [Literate](https://github.com/fredrikekre/Literate.jl) package.
37+
As explained in the Literate documentation, add a comment to slides corresponding to markdown. A slide separator is now `# ---` for example.
38+
39+
To get started, simple do:
40+
41+
```julia
42+
import Remark
43+
44+
# Generate a presentation (html+markdown) from the julia template
45+
# and save it in the folder "julia_presentation".
46+
julia_template = joinpath(dirname(dirname(pathof(Remark))), "examples", "julia")
47+
cp(julia_template, "julia_presentation")
48+
slideshowdir = Remark.slideshow("julia_presentation",
49+
options = Dict("ratio" => "16:9"),
50+
title = "My beautiful slides")
51+
52+
# Open presentation in default browser.
53+
Remark.open(slideshowdir)
54+
```
55+
56+
## External assets, styling, and customization
57+
58+
If you need extra assets, simply add a `assets` folder inside `src`. It will be copied in the `build` folder automatically.
59+
60+
If you want to use a custom stylesheet rather than the default, simply add a `style.css` file in your `src` folder.
61+
Your overall folder structure would be:
62+
63+
```
64+
presentation/
65+
├── src/
66+
│ └── index.md (or .jl)
67+
│ └── style.css
68+
│ └── assets/
69+
├── build/ (generated by the package)
70+
│ └── index.html
71+
│ └── style.css
72+
│ └── assets/
73+
```
3374

34-
- Using the [Literate](https://github.com/fredrikekre/Literate.jl) package, it is possible to create a presentation from a Julia script. As explained in the Literate documentation, add a comment to slides corresponding to markdown. A slide separator is now `# ---` for example.
75+
The title of the presentation can be customized via the `title` keyword.
76+
[Remark.js options](https://github.com/gnab/remark/wiki/Configuration#api) can be set using the `options` keyword.
77+
[Documenter](https://github.com/JuliaDocs/Documenter.jl) is run on the markdown by default: to keep the markdown as is, use `documenter=false`.
3578

36-
- [Documenter](https://github.com/JuliaDocs/Documenter.jl) is run on the markdown by default: to keep the markdown as is, use `documenter=false`.
79+
## Features
80+
81+
- The `slideshow` command creates a slideshow that uses local javascript libraries: the resulting presentation folder can be opened offline.
3782

38-
- All features of Documenter are automatically available here, for example use `# hide` at the end of a line of code for it to not appear in the slideshow (useful for saving plots, see [example](https://github.com/piever/Remark.jl/blob/master/examples/example.md)).
83+
- All features of Documenter are automatically available here, for example use `# hide` at the end of a line of code for it to not appear in the slideshow (useful for saving plots, see [example](https://github.com/piever/Remark.jl/blob/master/examples/markdown/src/index.md)).

assets/indextemplate.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title>$title</title>
55
<meta charset="utf-8">
6-
<link rel="stylesheet" type="text/css" href="styles.css">
6+
<link rel="stylesheet" type="text/css" href="style.css">
77
</head>
88
<body>
99
<textarea id="source">
File renamed without changes.

examples/julia/make.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Remark, FileWatching
2+
3+
while true
4+
Remark.slideshow(@__DIR__; options = Dict("ratio" => "16:9"), title = "Presentation")
5+
@info "Rebuilt"
6+
FileWatching.watch_folder(joinpath(@__DIR__, "src"))
7+
end
File renamed without changes.

examples/markdown/make.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Remark, FileWatching
2+
3+
while true
4+
Remark.slideshow(@__DIR__; options = Dict("ratio" => "16:9"), title = "Presentation")
5+
@info "Rebuilt"
6+
FileWatching.watch_folder(joinpath(@__DIR__, "src"))
7+
end
File renamed without changes.

src/Remark.jl

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Documenter, DocumenterMarkdown
55
import DefaultApplication
66
import JSON
77
using Random
8+
using Glob: glob
89

910
export slideshow
1011

@@ -20,10 +21,24 @@ const deps = [
2021
const depnames = ["remark.min.js", "katex.min.js", "auto-render.min.js", "katex.min.css"]
2122
const depfiles = joinpath.(_pkg_assets, depnames)
2223

23-
const styles_css = joinpath(_pkg_assets, "styles.css")
24+
const style_css = joinpath(_pkg_assets, "style.css")
2425

25-
function slideshow(inputfile, outputdir = dirname(inputfile);
26-
title = "Title", documenter = true, css = styles_css, options = Dict())
26+
function slideshow(presentation_dir;
27+
title="Title", documenter=true, options=Dict())
28+
29+
@assert isdir(presentation_dir)
30+
presentation_dir = realpath(abspath(presentation_dir))
31+
indices = ["index.md", "index.jl"]
32+
indices_path = filter(ispath, joinpath.(presentation_dir, "src", indices))
33+
length(indices_path) == 1 || error("Exactly one of index.md and index.jl must be present")
34+
inputfile = indices_path[1]
35+
36+
css_file = joinpath(presentation_dir, "src", "style.css")
37+
css_dir = joinpath(presentation_dir, "src", "style")
38+
css_list = isfile(css_file) ? [css_file] :
39+
isdir(css_dir) ? glob("*.css", css_dir) : [style_css]
40+
41+
assets_dir = joinpath(dirname(inputfile), "assets")
2742

2843
# We do all the creation of files in a workingdir in a tempdir, then move them to
2944
# output dir at the end. We do this because some operations e.g. Documenter will
@@ -32,27 +47,22 @@ function slideshow(inputfile, outputdir = dirname(inputfile);
3247
# can't find the file they are reloading, and not find the file means they have no
3348
# reload script afterwards, so stop working.
3449
# to solve this we move everything in place at the end as a single fast operation
35-
mktempdir() do tempdir
36-
# cp is required if `outputdir` is not empty.
37-
workingdir = realpath(abspath(cp(outputdir, joinpath(tempdir, "working"))))
38-
39-
40-
inputfile = realpath(abspath(inputfile))
41-
css = realpath(abspath(css))
50+
mktempdir() do workingdir
4251
mkpath.(joinpath.(workingdir, ("src", "build")))
43-
mk_file = _create_index_md(inputfile, workingdir; documenter = documenter)
44-
_create_index_html(workingdir, mk_file, options; title = title)
45-
cp(css, joinpath(workingdir, "build", "styles.css"), force=true)
46-
rm(mk_file)
47-
48-
mv(workingdir, outputdir, force=true)
52+
mk_file = _create_index_md(inputfile, workingdir; documenter=documenter)
53+
_create_index_html(workingdir, mk_file, options; title=title)
54+
Base.open(joinpath(workingdir, "build", "style.css"), "w") do io
55+
foreach(file -> Base.open(content -> write(io, content), file), css_list)
56+
end
57+
isdir(assets_dir) && cp(assets_dir, joinpath(workingdir, "build", "assets"), force=true)
58+
mv(joinpath(workingdir, "build"), joinpath(presentation_dir, "build"), force=true)
4959
end
50-
return realpath(abspath(outputdir))
60+
return presentation_dir
5161
end
5262

53-
function _create_index_md(inputfile, outputdir; documenter = true)
63+
function _create_index_md(inputfile, outputdir; documenter=true)
5464
if occursin(r".jl$", inputfile)
55-
Literate.markdown(inputfile, joinpath(outputdir, "src"), name = "index")
65+
Literate.markdown(inputfile, joinpath(outputdir, "src"), name="index")
5666
else
5767
cp(inputfile, joinpath(outputdir, "src", "index.md"), force=true)
5868
end
@@ -66,7 +76,7 @@ function _create_index_md(inputfile, outputdir; documenter = true)
6676
r"^(\s)*(--)(\s)*$" => s1,
6777
r"^(\s)*(\$\$)(\s)*$" => s2,
6878
)
69-
Documenter.makedocs(format = DocumenterMarkdown.Markdown(), root = outputdir)
79+
Documenter.makedocs(format=DocumenterMarkdown.Markdown(), root=outputdir)
7080
replace_linewise(
7181
outputfile,
7282
Regex("^($s1)\$") => "--",
@@ -79,7 +89,7 @@ function _create_index_md(inputfile, outputdir; documenter = true)
7989
outputfile
8090
end
8191

82-
function _create_index_html(outputdir, md_file, options = Dict(); title = "Title")
92+
function _create_index_html(outputdir, md_file, options=Dict(); title="Title")
8393

8494
optionsjs = JSON.json(options)
8595
template = joinpath(_pkg_assets, "indextemplate.html")

test/indexjl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title>Title</title>
55
<meta charset="utf-8">
6-
<link rel="stylesheet" type="text/css" href="styles.css">
6+
<link rel="stylesheet" type="text/css" href="style.css">
77
</head>
88
<body>
99
<textarea id="source">

0 commit comments

Comments
 (0)