riven 1.1.4 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Gemfile.lock +2 -5
- data/README.md +20 -153
- data/bin/riven +17 -18
- data/doc/chapters/1-what-is-riven/1-scenario-a.md +12 -0
- data/doc/chapters/1-what-is-riven/2-scenario-b.md +8 -0
- data/doc/chapters/1-what-is-riven/3-what-is-riven-not.md +16 -0
- data/doc/chapters/1-what-is-riven/4-why-was-riven-created.md +35 -0
- data/doc/chapters/1-what-is-riven/5-how-can-i-support-riven.md +7 -0
- data/doc/chapters/1-what-is-riven/index.md +15 -0
- data/doc/chapters/2-setup/1-prerequisites.md +49 -0
- data/doc/chapters/2-setup/2-installation.md +17 -0
- data/doc/chapters/2-setup/index.md +6 -0
- data/doc/chapters/3-basics/1-single-file.md +19 -0
- data/doc/chapters/3-basics/2-multiple-files.md +65 -0
- data/doc/chapters/3-basics/3-structured-files.md +55 -0
- data/doc/chapters/3-basics/4-config-file.md +63 -0
- data/doc/chapters/3-basics/index.md +17 -0
- data/doc/chapters/4-advanced-usage/1-css.md +34 -0
- data/doc/chapters/4-advanced-usage/2-table-of-contents.md +11 -0
- data/doc/chapters/4-advanced-usage/3-cover.md +10 -0
- data/doc/chapters/4-advanced-usage/4-syntax-highlighting.md +23 -0
- data/doc/chapters/4-advanced-usage/index.md +10 -0
- data/doc/cover.md +37 -0
- data/doc/img/cover.png +0 -0
- data/doc/index.md +4 -0
- data/doc/riven.pdf +0 -0
- data/doc/riven.yml +10 -0
- data/doc/style.css +21 -0
- data/lib/riven/config.rb +122 -0
- data/lib/riven/html_generator.rb +4 -4
- data/lib/riven/markup_file.rb +1 -1
- data/lib/riven/opt_parser.rb +48 -33
- data/lib/riven/version.rb +1 -1
- data/lib/riven/wkhtmltopdf.rb +7 -7
- metadata +28 -2
@@ -0,0 +1,19 @@
|
|
1
|
+
## 3.1. A single file
|
2
|
+
|
3
|
+
Let's start small and transform a single file into your first beautiful PDF!
|
4
|
+
|
5
|
+
Create a new markdown file where ever you want and name it `awesome.md`. Put some markdown into the file just like this:
|
6
|
+
|
7
|
+
```markdown
|
8
|
+
# Hello World!
|
9
|
+
|
10
|
+
**This** is my first Riven generated PDF!
|
11
|
+
```
|
12
|
+
|
13
|
+
Now we compile the PDF with a simple Riven call:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ riven awesome.pdf
|
17
|
+
```
|
18
|
+
|
19
|
+
You should get a PDF file called `awesome.pdf`. Open it and admire your first PDF.
|
@@ -0,0 +1,65 @@
|
|
1
|
+
## 3.2. Many at once
|
2
|
+
|
3
|
+
Now we know how to convert a single file into a PDF document. But usually we have more then one file. For example one
|
4
|
+
file for each chapter. Riven may take a bunch of markdown files and compile them into a single PDF file.
|
5
|
+
|
6
|
+
In order to use that feature, we need some more markdown files:
|
7
|
+
|
8
|
+
`chapter-1.md`:
|
9
|
+
|
10
|
+
```markdown
|
11
|
+
# Chapter 1
|
12
|
+
|
13
|
+
Hello World!
|
14
|
+
```
|
15
|
+
|
16
|
+
|
17
|
+
`chapter-2.md`:
|
18
|
+
|
19
|
+
```markdown
|
20
|
+
# Chapter 2
|
21
|
+
|
22
|
+
Another example
|
23
|
+
```
|
24
|
+
|
25
|
+
`chapter-3.md`:
|
26
|
+
|
27
|
+
```markdown
|
28
|
+
# Chapter 3
|
29
|
+
|
30
|
+
Last but not least
|
31
|
+
```
|
32
|
+
|
33
|
+
Now you can merge all these files into a single PDF with the following command:
|
34
|
+
|
35
|
+
```bash
|
36
|
+
$ riven -o awesome.pdf chapter-1.md chapter-2.md chapter-3.md
|
37
|
+
```
|
38
|
+
|
39
|
+
You'll get a single PDF file, just as in chapter 3.1., which contains all three chapters and the regarding content. The
|
40
|
+
`-o` param determines the name of the generated PDF file.
|
41
|
+
|
42
|
+
|
43
|
+
Riven is also able to guess the PDF file name if all markdown files are located in one directory. So let's create
|
44
|
+
a directory called `awesome` and put our three markdown files into it. Now you should have a file structure like this:
|
45
|
+
|
46
|
+
```bash
|
47
|
+
$ ls -1
|
48
|
+
awesome/
|
49
|
+
|
50
|
+
$ ls -1 awesome/
|
51
|
+
chapter-1.md
|
52
|
+
chapter-2.md
|
53
|
+
chapter-3.md
|
54
|
+
```
|
55
|
+
|
56
|
+
The following command will generate exactly the same PDF file as the command we used before, but you don't have to
|
57
|
+
provide a PDF file name. Riven will take the directory name as the PDF file name.
|
58
|
+
|
59
|
+
```bash
|
60
|
+
$ riven awesome/
|
61
|
+
```
|
62
|
+
|
63
|
+
You'll receive a `awesome.pdf` file like before.
|
64
|
+
|
65
|
+
Consider that Riven will merge the markdown files of the directory in alphabetical order.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
## 3.3. Structure your files
|
2
|
+
|
3
|
+
In the two previous chapters you learned how to convert a single file or a bunch of files into a PDF. In this chapter
|
4
|
+
you'll learn a nice mixed way how to structure bigger documents with many markdown files without the need to pass all
|
5
|
+
those files to the riven command or to ensure the alphabetical order is the order you want.
|
6
|
+
|
7
|
+
The magical feature of Riven which allows us to bring a clean tidiness in your files, is called *include directive*.
|
8
|
+
It's a markdown syntax which is not part of the original markdown language, but a feature of the Riven Extended
|
9
|
+
Markdown - or REM. REM is a superset of the GitHub Flavored Markdown introduced by Riven in order to provide some
|
10
|
+
additional features. The include directive allows you to define another markdown file. Riven will merge the content of
|
11
|
+
that markdown file into the outer markdown file by replacing the include directive.
|
12
|
+
|
13
|
+
The include syntax looks like that:
|
14
|
+
|
15
|
+
`_<<[ file ]`
|
16
|
+
|
17
|
+
where `file` is the path to another markdown file.
|
18
|
+
|
19
|
+
**Here's an example:**
|
20
|
+
|
21
|
+
`a.md`:
|
22
|
+
|
23
|
+
```markdown
|
24
|
+
Hello World!
|
25
|
+
|
26
|
+
_<<[ b.md ]
|
27
|
+
|
28
|
+
Bye World!
|
29
|
+
```
|
30
|
+
|
31
|
+
`b.md`:
|
32
|
+
|
33
|
+
```markdown
|
34
|
+
This content is **included**!
|
35
|
+
```
|
36
|
+
|
37
|
+
If you call
|
38
|
+
|
39
|
+
```bash
|
40
|
+
$ riven -o a.pdf a.md
|
41
|
+
```
|
42
|
+
|
43
|
+
Riven will merge the two files like that:
|
44
|
+
|
45
|
+
```markdown
|
46
|
+
Hello World!
|
47
|
+
|
48
|
+
This content is **included**!
|
49
|
+
|
50
|
+
Bye World!
|
51
|
+
```
|
52
|
+
|
53
|
+
This feature allows you to organize your document over many markdown files and subdirectories. Take a look at
|
54
|
+
https://github.com/phortx/riven/tree/master/doc to see a good example for the usage of includes and how to structure
|
55
|
+
a document.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
## 1.4. The config file
|
2
|
+
|
3
|
+
If you take a look at the Riven help (`riven -h`), you'll see that riven supports a bunch of command line options. It
|
4
|
+
can be a bit painful to remember all those parameters in order to regenerate your PDF from time to time. So it's
|
5
|
+
recommended to setup a config file for riven where you can set all your settings instead of passing them to the `riven`
|
6
|
+
command. This can you save you a lot of time.
|
7
|
+
|
8
|
+
A Riven config file is a simple YAML file, like you may know from Rails or Symfony. But they're really easy to
|
9
|
+
understand, so no panic if you never heard of it before.
|
10
|
+
|
11
|
+
An example riven.yml looks like that:
|
12
|
+
|
13
|
+
```yml
|
14
|
+
pdf_output_file: example.pdf
|
15
|
+
cover_file: cover.md
|
16
|
+
css_file: style.css
|
17
|
+
generate_toc: true
|
18
|
+
toc_headline: 'Contents'
|
19
|
+
dump_html: false
|
20
|
+
dump_cover_html: false
|
21
|
+
verbose: false
|
22
|
+
files:
|
23
|
+
- index.md
|
24
|
+
```
|
25
|
+
|
26
|
+
You may provide as many files as you want under the `files` section. Each file gets one line. For example:
|
27
|
+
|
28
|
+
```yml
|
29
|
+
files:
|
30
|
+
- index.md
|
31
|
+
- chapter-1.md
|
32
|
+
- chapter-2.md
|
33
|
+
- chapter-3.md
|
34
|
+
```
|
35
|
+
|
36
|
+
Riven searches for a `riven.yml` in the current directory. But if you config file is located in another directory, you
|
37
|
+
should pass it via the `-C` param. However if you structure your document like this:
|
38
|
+
|
39
|
+
```bash
|
40
|
+
$ ls -1
|
41
|
+
|
42
|
+
chapters/
|
43
|
+
cover.md
|
44
|
+
index.md
|
45
|
+
riven.yml
|
46
|
+
style.css
|
47
|
+
```
|
48
|
+
|
49
|
+
it will be pretty easy to generate your PDF, since you just have to call `riven` without any params:
|
50
|
+
|
51
|
+
```bash
|
52
|
+
$ riven
|
53
|
+
```
|
54
|
+
|
55
|
+
It will use the `riven.yml` from the current directory and load all settings from it.
|
56
|
+
|
57
|
+
You're also allowed to mix up command line parameters and the config file. For example you can override the stylesheet:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
$ riven -s another_style.css
|
61
|
+
```
|
62
|
+
|
63
|
+
The command line params will override the settings from the `riven.yml`.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# 3. Learn the basics
|
2
|
+
|
3
|
+
Now as Riven is up and running, let's have some fun and start writing! In this chapter you'll learn the basics and how
|
4
|
+
to use Riven to generate PDFs.
|
5
|
+
|
6
|
+
However if you're looking for an good example: You're actually reading one! This documentation is generated with Riven
|
7
|
+
and you can read the markdown source code at the [doc directory](https://github.com/phortx/riven/blob/master/doc/) in
|
8
|
+
the GitHub repository of riven. The [generated PDF](https://github.com/phortx/riven/blob/master/doc/riven.pdf) can be
|
9
|
+
found in that directory too.
|
10
|
+
|
11
|
+
If you want to learn markdown, you should take a look at the
|
12
|
+
[Learn Markdown book from GitBook](https://gitbookio.gitbooks.io/markdown/content/) which can be read online.
|
13
|
+
|
14
|
+
<<[ 1-single-file.md ]
|
15
|
+
<<[ 2-multiple-files.md ]
|
16
|
+
<<[ 3-structured-files.md ]
|
17
|
+
<<[ 4-config-file.md ]
|
@@ -0,0 +1,34 @@
|
|
1
|
+
## 4.1. Style your PDF
|
2
|
+
|
3
|
+
Riven allows you to style your PDF via CSS rules. This feature makes it possible to change colors, fonts, margins and
|
4
|
+
many more.
|
5
|
+
|
6
|
+
However please consider that this is a PDF, so the capabilities of the layouting via CSS is limited. Not every CSS rule
|
7
|
+
you know will work.
|
8
|
+
|
9
|
+
In order to use a CSS file, you have to create a `style.css` for example and pass it to the `-s` param of riven:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ riven -s style.css documentation.md
|
13
|
+
```
|
14
|
+
|
15
|
+
Some hints:
|
16
|
+
|
17
|
+
- Every text paragraph is wrapped into a `<p>` tag
|
18
|
+
- The headlines will be transformed to `<h1>`, `<h2>`, `<h3>` ... tags, where `#` is `<h1>`, `##` is `<h2>` and so on
|
19
|
+
- Quotes (`>`) are transformed to a `<blockquote>` tag
|
20
|
+
- Bold text is transformed to a `<strong>` tag
|
21
|
+
- `<hr>` tags are used for horizontal lines (`-----`)
|
22
|
+
- Unordered lists are transformed to `<ul>` and `<li>` tags and ordered lists are transformed to `<ol>` and `<li>` tags.
|
23
|
+
Nested lists are `<ul>` tags within a `<li>` tag
|
24
|
+
- Inline fixed width text (backticks) is transformed to `<code>` tags
|
25
|
+
- Multiline code blocks are transformed into `<pre>` tags
|
26
|
+
|
27
|
+
To style the cover page, you can use the `.cover-page` CSS class. The following example will change the h1 color on the
|
28
|
+
cover page to red:
|
29
|
+
|
30
|
+
```css
|
31
|
+
.cover-page h1 {
|
32
|
+
color: red;
|
33
|
+
}
|
34
|
+
```
|
@@ -0,0 +1,11 @@
|
|
1
|
+
## 4.2. Automatic Table of Contents
|
2
|
+
|
3
|
+
For an automatic generated table of contents after the cover page, you can add the `-t` param and pass a headline for
|
4
|
+
the table of contents:
|
5
|
+
|
6
|
+
```bash
|
7
|
+
$ riven -t "Contents" -c documentation/cover.md documentation/
|
8
|
+
```
|
9
|
+
|
10
|
+
Riven will generate a table of contents for all headlines. The user can click on the entries to jump directly to the
|
11
|
+
regarding headline.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
## 4.3. Cover pages
|
2
|
+
|
3
|
+
To start your PDF with a nice cover page, define a cover markdown file and pass it to the `-c` param. Riven will prepend
|
4
|
+
that file before all other files and doesn't attach a page number.
|
5
|
+
|
6
|
+
```bash
|
7
|
+
$ riven -c documentation/cover.md documentation/
|
8
|
+
```
|
9
|
+
|
10
|
+
It can be helpful to use HTML within the cover page to have more control over it's layout.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
## 4.4. Syntax highlighting
|
2
|
+
|
3
|
+
Riven comes with syntax highlighting for code blocks:
|
4
|
+
|
5
|
+
```markdown
|
6
|
+
` ``ruby
|
7
|
+
def foo
|
8
|
+
puts 'bar'
|
9
|
+
end
|
10
|
+
` ``
|
11
|
+
```
|
12
|
+
|
13
|
+
(Ignore the whitespace between the backticks)
|
14
|
+
|
15
|
+
This code sample will produce the following field in the PDF:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
def foo
|
19
|
+
puts 'bar'
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
The syntax highlighting is powered by [coderay](https://github.com/rubychan/coderay) and Riven is using a [github theme](https://github.com/pie4dan/CodeRay-GitHub-Theme).
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# 4. Advanced topics
|
2
|
+
|
3
|
+
In this last chapter we'll tackle all advanced features of Riven like the styling of the PDF with CSS, the table of
|
4
|
+
contents, cover pages and syntax highlighting of code snippets.
|
5
|
+
|
6
|
+
|
7
|
+
<<[ 1-css.md ]
|
8
|
+
<<[ 2-table-of-contents.md ]
|
9
|
+
<<[ 3-cover.md ]
|
10
|
+
<<[ 4-syntax-highlighting.md ]
|
data/doc/cover.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
<br />
|
2
|
+
<br />
|
3
|
+
<br />
|
4
|
+
<br />
|
5
|
+
<br />
|
6
|
+
<br />
|
7
|
+
|
8
|
+

|
9
|
+
|
10
|
+
<br />
|
11
|
+
<br />
|
12
|
+
<br />
|
13
|
+
<br />
|
14
|
+
<br />
|
15
|
+
<br />
|
16
|
+
<br />
|
17
|
+
<br />
|
18
|
+
|
19
|
+
# Official Riven Manual
|
20
|
+
## Write Markdown. Get a nice PDF. Have fun.
|
21
|
+
|
22
|
+
|
23
|
+
<br />
|
24
|
+
<br />
|
25
|
+
<br />
|
26
|
+
<br />
|
27
|
+
<br />
|
28
|
+
<br />
|
29
|
+
<br />
|
30
|
+
<br />
|
31
|
+
<br />
|
32
|
+
<br />
|
33
|
+
<br />
|
34
|
+
<br />
|
35
|
+
|
36
|
+
|
37
|
+
> powered by Benjamin Kammerl | visit *[github.com/phortx/riven](https://github.com/phortx/riven)* | MIT license
|
data/doc/img/cover.png
ADDED
Binary file
|
data/doc/index.md
ADDED
data/doc/riven.pdf
ADDED
Binary file
|
data/doc/riven.yml
ADDED
data/doc/style.css
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
body {
|
2
|
+
color: #555;
|
3
|
+
}
|
4
|
+
|
5
|
+
h1 {
|
6
|
+
color: #337AB7;
|
7
|
+
font-weight: normal;
|
8
|
+
}
|
9
|
+
|
10
|
+
h2 {
|
11
|
+
font-weight: 500;
|
12
|
+
}
|
13
|
+
|
14
|
+
.cover-page h1 {
|
15
|
+
background-color: #337AB7;
|
16
|
+
color: #fff;
|
17
|
+
}
|
18
|
+
|
19
|
+
.cover-page blockquote {
|
20
|
+
background-color: #eee;
|
21
|
+
}
|
data/lib/riven/config.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
module Riven
|
2
|
+
class Config
|
3
|
+
attr_accessor \
|
4
|
+
:pdf_output_file,
|
5
|
+
:cover_file,
|
6
|
+
:css_file,
|
7
|
+
:generate_toc,
|
8
|
+
:toc_headline,
|
9
|
+
:dump_html,
|
10
|
+
:dump_cover_html,
|
11
|
+
:verbose,
|
12
|
+
:dir_given,
|
13
|
+
:config_file,
|
14
|
+
:files
|
15
|
+
|
16
|
+
|
17
|
+
#
|
18
|
+
# Constructor with the default values
|
19
|
+
#
|
20
|
+
public def initialize
|
21
|
+
@pdf_output_file = nil
|
22
|
+
@cover_file = nil
|
23
|
+
@css_file = nil
|
24
|
+
@generate_toc = false
|
25
|
+
@toc_headline = 'Contents'
|
26
|
+
@dump_html = false
|
27
|
+
@dump_cover_html = false
|
28
|
+
@verbose = false
|
29
|
+
@dir_given = false
|
30
|
+
@config_file = nil
|
31
|
+
@files = []
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
#
|
36
|
+
# Overrides the value in the current config if the value of the other config is not the default value
|
37
|
+
#
|
38
|
+
public def merge(another_config)
|
39
|
+
@pdf_output_file = another_config.pdf_output_file if another_config.pdf_output_file != nil
|
40
|
+
@cover_file = another_config.cover_file if another_config.cover_file != nil
|
41
|
+
@css_file = another_config.css_file if another_config.css_file != nil
|
42
|
+
@generate_toc = another_config.generate_toc if another_config.generate_toc != false
|
43
|
+
@toc_headline = another_config.toc_headline if another_config.toc_headline != 'Contents'
|
44
|
+
@dump_html = another_config.dump_html if another_config.dump_html != false
|
45
|
+
@dump_cover_html = another_config.dump_cover_html if another_config.dump_cover_html != false
|
46
|
+
@verbose = another_config.verbose if another_config.verbose != false
|
47
|
+
@dir_given = another_config.dir_given if another_config.dir_given != false
|
48
|
+
@config_file = another_config.config_file if another_config.config_file != nil
|
49
|
+
@files = another_config.files if another_config.files != []
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
#
|
54
|
+
# Prints the current config
|
55
|
+
#
|
56
|
+
public def print
|
57
|
+
puts
|
58
|
+
puts "Using config file #{config_file}" if config_file != nil
|
59
|
+
puts
|
60
|
+
puts 'Riven configuration:'
|
61
|
+
puts " - pdf_output_file: #{@pdf_output_file}"
|
62
|
+
puts " - cover_file: #{@cover_file.path}"
|
63
|
+
puts " - css_file: #{@css_file}"
|
64
|
+
puts " - generate_toc: #{@generate_toc}"
|
65
|
+
puts " - toc_headline: #{@toc_headline}"
|
66
|
+
puts " - dump_html: #{@dump_html}"
|
67
|
+
puts " - dump_cover_html: #{@dump_cover_html}"
|
68
|
+
puts " - verbose: #{@verbose}"
|
69
|
+
puts " - dir_given: #{@dir_given}"
|
70
|
+
puts " - config_file: #{@config_file}"
|
71
|
+
|
72
|
+
puts ' - files:'
|
73
|
+
|
74
|
+
@files.each do |file|
|
75
|
+
puts " - #{file.path}"
|
76
|
+
end
|
77
|
+
|
78
|
+
puts
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
#
|
83
|
+
# Setter for @css_file
|
84
|
+
#
|
85
|
+
public def css_file=(file)
|
86
|
+
@css_file = File.expand_path(file)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
#
|
91
|
+
# Setter for @cover_file
|
92
|
+
#
|
93
|
+
public def cover_file=(file)
|
94
|
+
@cover_file = Riven::MarkupFile.new(file)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
#
|
99
|
+
# Setter for @files
|
100
|
+
#
|
101
|
+
public def files=(files)
|
102
|
+
@files = files.map { |file| Riven::MarkupFile.new(file) }
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
#
|
107
|
+
# Parses a riven config yml file and constructs a Config object
|
108
|
+
#
|
109
|
+
def self.parse(config_file)
|
110
|
+
require 'yaml'
|
111
|
+
config = Riven::Config.new
|
112
|
+
config.config_file = config_file
|
113
|
+
parsed = YAML::load(File.open(File.expand_path(config.config_file)))
|
114
|
+
|
115
|
+
parsed.each do |key, value|
|
116
|
+
config.send(:"#{key}=", value)
|
117
|
+
end
|
118
|
+
|
119
|
+
config
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|