riven 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1d15b3e000390101dcda3dca562e42a14713cfa
4
- data.tar.gz: 2fcd70e0c9116075b2b65ea8046ceef03b08eeb5
3
+ metadata.gz: 249713d59e43598175a09dbf188fdc4afaf4023c
4
+ data.tar.gz: 9843a8a2a382623f06c416d6e074d9c8cf9efea4
5
5
  SHA512:
6
- metadata.gz: 45b1316495eff7da3960c231223e82ec12cec36c20638560a4a5945dffb57052ed537972adf74cf1bca10bec774d55c1fe9df51f78d5a3d7bf0026ae45a929c7
7
- data.tar.gz: 163bcb01c7d628845ebcf775784bd5c700be3fff255879cb59720b31239b3aa16406816b9adfd09684cc511385ec0e7c4a347ed371549325955946e820626fac
6
+ metadata.gz: ebe32bc24a34766e3eda31553d1205adc2c2457976d1eb9f32d1113fde593fe842ecc1022d3fa8b0d4b328aa910a81dfc1f11662b78cdc3c97ebea6d21e59019
7
+ data.tar.gz: 52592999799d5e60e0ea8ead3c192187a0d3bc1f5dd3ddb8bf77ca3d22da600860509bbb35587cc2c53b8d69304f64ae6f8e70b88414583379090ea872593b57
data/Gemfile.lock CHANGED
@@ -3,12 +3,16 @@ PATH
3
3
  specs:
4
4
  riven (0.0.1)
5
5
  coderay (~> 1.1.0)
6
+ github-markup (~> 1.2.0)
6
7
  redcarpet (~> 3.2.2)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
12
  coderay (1.1.0)
13
+ github-markup (1.2.1)
14
+ posix-spawn (~> 0.3.8)
15
+ posix-spawn (0.3.9)
12
16
  rake (10.4.2)
13
17
  redcarpet (3.2.2)
14
18
 
data/README.md CHANGED
@@ -6,21 +6,23 @@ Converts GitHub Flavored Markdown files to PDFs! Feature highlights:
6
6
  - Syntax Highlighting with GitHub like theme
7
7
  - Smart page breaks
8
8
  - Smart directory based file merging
9
- - Page numbers (not finised yet, sorry)
9
+ - Page numbers (see *Prerequisites* section)
10
10
  - ~~Custom CSS~~ (not finised yet, sorry)
11
- - ~~Covers~~ (not finised yet, sorry)
12
- - ~~Table of Contents~~ (not finised yet, sorry)
11
+ - Covers (see *Prerequisites* section)
12
+ - Table of Contents (see *Prerequisites* section)
13
13
 
14
14
  The gem is still under development, but it already works. In the current version the output PDF file name will always be `test.pdf`. This will change soon.
15
15
 
16
16
 
17
17
  ## Prerequisites
18
18
 
19
- You need `wkhtmltopdf` in order to generate PDFs, since that's the PDF generator backend for riven:
19
+ You need `wkhtmltopdf` in order to generate PDFs, since that's the PDF generator backend for riven. You should use the QT patched version of `wkhtmltopdf`. You may also use the version without patched qt, but that will disable the following features of riven: Page numbers, table of contents, covers.
20
20
 
21
- - If you got a Linux Distribution or OSX and your package mangement offers `wkhtmltopdf` in a newer version than `0.9.9.3`, then install it via your package manager.
21
+ - If you got Arch Linux, you can just install the packages `wkhtmltopdf-static`and `icu48` from the AUR.
22
22
 
23
- - If you there's no newer version, you should use the `wkhtmltopdf-binary` gem: `gem install wkhtmltopdf-binary`
23
+ - If you got a Linux Distribution or OSX you may compile `wkhtmltopdf` from the sources. See http://stackoverflow.com/questions/10981960/wkhtmltopdf-patched-qt.
24
+
25
+ - Otherwise, you should download `wkhtmltopdf` from the [official website](http://wkhtmltopdf.org/downloads.html).
24
26
 
25
27
  After that, make sure you can execute the `wkhtmltopdf` command in your shell:
26
28
 
@@ -123,8 +125,8 @@ The syntax highlightning is powered by [coderay](https://github.com/rubychan/cod
123
125
 
124
126
  ### Table of Contents
125
127
 
126
- For an automatic generated table of contents after the cover, just add the `-t` param:
128
+ For an automatic generated table of contents after the cover, just add the `-t` param and provide a headline for the table of contents:
127
129
 
128
130
  ```bash
129
- $ riven -t -c documentation/cover.md -o doc.pdf documentation/
130
- ```
131
+ $ riven -t "Contents" -c documentation/cover.md -o doc.pdf documentation/
132
+ ```
data/bin/riven CHANGED
@@ -14,26 +14,51 @@ Riven::Wkhtmltopdf.check_installation
14
14
 
15
15
  ## Step 2: Parse command line options
16
16
  options = Riven::OptParser.options
17
- files = Riven::OptParser.files
17
+ files = Riven::OptParser.files(options)
18
18
 
19
19
 
20
- ## Step 3: Generate HTML
21
- markup = Riven::MarkupFile.read_all(files)
22
- generator = Riven::HTMLGenerator.new(markup)
20
+ ## Step 3: Change dir if directory is given to ensure the image pathes work
21
+ unless options[:dir_given] === false
22
+ working_dir = Dir.pwd
23
+ Dir.chdir options[:dir_given]
24
+ end
23
25
 
24
26
 
25
- ## Step 4: Determine PDF file name
27
+ ## Step 4: Generate HTML for cover
28
+ unless options[:cover_file] === ''
29
+ cover_markup = Riven::MarkupFile.read_cover(options[:cover_file])
30
+ end
31
+ cover_generator = Riven::HTMLGenerator.new('_riven_cover_tmp_file.html', cover_markup || '')
32
+
33
+
34
+ ## Step 5: Generate HTML for main document
35
+ markup = Riven::MarkupFile.read_all(files, options[:cover_file])
36
+ generator = Riven::HTMLGenerator.new('_riven_tmp_file.html', markup)
37
+
38
+
39
+ ## Step 6: Determine PDF file name
26
40
  # TODO auto generate output file name or take it from the options
27
41
  output_file = 'test.pdf'
28
42
 
29
43
 
30
- ## Step 5: Generate the PDF file from HTML file
31
- Riven::Wkhtmltopdf.generate_pdf(generator.html_file, output_file)
44
+ ## Step 7: Generate the PDF file from HTML file
45
+ output = Riven::Wkhtmltopdf.generate_pdf(generator.html_file, cover_generator.html_file, output_file, options)
46
+ puts output if options[:verbose]
32
47
 
33
48
 
34
- ## Step 6: Close the generator
49
+ ## Step 8: Close the generators
35
50
  generator.close!
51
+ cover_generator.close!
52
+
53
+
54
+ ## Step 9: Dump the HTML code if requested
55
+ puts generator.html if options[:dump_html]
56
+ puts cover_generator.html if options[:dump_cover_html]
36
57
 
37
58
 
38
- ## Step 7: Dump the HTML code if requested
39
- puts generator.html if options[:dump_html]
59
+ ## Step 10: If we changed the directory before, the PDF file is now located in the wrong directory,
60
+ ## so wie have to move it
61
+ unless options[:dir_given] === false
62
+ require 'fileutils'
63
+ FileUtils.mv output_file, working_dir + '/' + output_file
64
+ end
data/css/style.css CHANGED
@@ -40,10 +40,6 @@ hr {
40
40
  height: 0;
41
41
  }
42
42
 
43
- pre {
44
- overflow: auto;
45
- }
46
-
47
43
  code,
48
44
  kbd,
49
45
  pre {
@@ -265,6 +261,7 @@ h1 .anchor {
265
261
 
266
262
  h2 {
267
263
  padding-bottom: 0.3em;
264
+ margin-top: 2.5em;
268
265
  line-height: 1.225;
269
266
  border-bottom: 1px solid #eee;
270
267
  }
@@ -274,6 +271,7 @@ h2 .anchor {
274
271
  }
275
272
 
276
273
  h3 {
274
+ margin-top: 1.7em;
277
275
  line-height: 1.43;
278
276
  }
279
277
 
@@ -418,7 +416,8 @@ pre>code {
418
416
  margin: 0;
419
417
  font-size: 100%;
420
418
  word-break: normal;
421
- white-space: pre;
419
+ white-space: pre-wrap;
420
+ word-wrap: break-word;
422
421
  background: transparent;
423
422
  border: 0;
424
423
  }
@@ -442,10 +441,6 @@ pre {
442
441
  word-break: normal;
443
442
  }
444
443
 
445
- pre {
446
- word-wrap: normal;
447
- }
448
-
449
444
  pre code {
450
445
  display: inline;
451
446
  max-width: initial;
@@ -453,7 +448,8 @@ pre code {
453
448
  margin: 0;
454
449
  overflow: initial;
455
450
  line-height: inherit;
456
- word-wrap: normal;
451
+ white-space: pre-wrap;
452
+ word-wrap: break-word;
457
453
  background-color: transparent;
458
454
  border: 0;
459
455
  }
@@ -636,7 +632,7 @@ kbd {
636
632
  }
637
633
 
638
634
  div.CodeRay { }
639
- span.CodeRay { white-space: pre; border: 0px; padding: 2px }
635
+ span.CodeRay { white-space: pre-wrap; word-wrap: break-word; border: 0px; padding: 2px }
640
636
 
641
637
  table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
642
638
  table.CodeRay td {
@@ -661,9 +657,8 @@ table.CodeRay td {
661
657
  .CodeRay .code { width: 100% }
662
658
 
663
659
  ol.CodeRay { font-size: 10pt }
664
- ol.CodeRay li { white-space: pre }
660
+ ol.CodeRay li { white-space: pre-wrap; word-wrap: break-word; }
665
661
 
666
- .CodeRay .code pre { overflow: auto }
667
662
  .CodeRay .debug { color:white ! important; background:blue ! important; }
668
663
 
669
664
  .CodeRay .annotation { color:#007 }
@@ -754,4 +749,26 @@ ol.CodeRay li { white-space: pre }
754
749
  .CodeRay .insert .insert { color: #080; font-weight:bold }
755
750
  .CodeRay .delete .delete { color: #800; font-weight:bold }
756
751
  .CodeRay .change .change { color: #66f; }
757
- .CodeRay .head .head { color: #f4f; }
752
+ .CodeRay .head .head { color: #f4f; }
753
+
754
+
755
+
756
+
757
+ .cover-page h1,
758
+ .cover-page h2,
759
+ .cover-page h3,
760
+ .cover-page img {
761
+ text-align: center;
762
+ border-bottom: none;
763
+ }
764
+
765
+ .cover-page h1 {
766
+ margin: 15px 0;
767
+ font-size: 60px;
768
+ page-break-before: avoid;
769
+ }
770
+
771
+ .cover-page h2 {
772
+ margin-top: 0.5em;
773
+ color: #666;
774
+ }
@@ -3,7 +3,7 @@ module Riven
3
3
  attr_accessor :file_name
4
4
 
5
5
  public def initialize(file_name)
6
- @file_name = file_name
6
+ @file_name = File.expand_path('./' + file_name)
7
7
  end
8
8
 
9
9
  public def write(content)
@@ -7,8 +7,8 @@ module Riven
7
7
  class HTMLGenerator
8
8
  attr_accessor :html, :html_file
9
9
 
10
- public def initialize(markup)
11
- @html_file = Riven::HTMLFile.new('_riven_tmp_file.html')
10
+ public def initialize(tmp_file, markup)
11
+ @html_file = Riven::HTMLFile.new(tmp_file)
12
12
 
13
13
  @markup = markup
14
14
 
@@ -35,7 +35,6 @@ module Riven
35
35
  tables: true,
36
36
  underline: true,
37
37
  highlight: true,
38
- filter_html: true,
39
38
  with_toc_data: true,
40
39
  lax_spacing: true,
41
40
  xhtml: true,
@@ -47,6 +46,9 @@ module Riven
47
46
 
48
47
  html = code.process(html)
49
48
 
49
+ html.gsub! '////[COVERSTART]////', '<div class="cover-page">'
50
+ html.gsub! '////[COVEREND]////', '</div>'
51
+
50
52
  return html
51
53
  end
52
54
 
@@ -26,15 +26,28 @@ module Riven
26
26
 
27
27
 
28
28
  class << self
29
- public def read_all(markup_files)
29
+ public def read_all(markup_files, except = [])
30
30
  markup = ''
31
31
 
32
+ markup_files = [markup_files] unless markup_files.respond_to?(:each)
33
+ except = [except] unless except.respond_to?(:each)
34
+
32
35
  markup_files.each do |file|
33
- markup << "\n\n" + File.read(file.path)
36
+ markup << "\n\n" + File.read(file.path) unless exclude?(except, file)
34
37
  end
35
38
 
36
39
  return markup
37
40
  end
41
+
42
+ public def read_cover(cover_file)
43
+ cover_markup = "\n////[COVERSTART]////\n"
44
+ cover_markup << Riven::MarkupFile.read_all(cover_file)
45
+ cover_markup << "\n////[COVEREND]////\n"
46
+ end
47
+
48
+ private def exclude?(except, file)
49
+ except.select { |f| f.path === file.path }.any?
50
+ end
38
51
  end
39
52
  end
40
53
  end
@@ -13,10 +13,11 @@ module Riven
13
13
  # Returns an array of Riven::MarkupFile for each given markdown file
14
14
  #
15
15
 
16
- public def files
16
+ public def files(options)
17
17
  file_names = ARGV
18
18
 
19
19
  if file_names.size === 1 && File.directory?(file_names[0])
20
+ options[:dir_given] = file_names.first
20
21
  file_names = Dir["#{file_names[0]}/*.md"].sort
21
22
  end
22
23
 
@@ -34,7 +35,11 @@ module Riven
34
35
  cover_file: '',
35
36
  css_file: '',
36
37
  toc: false,
37
- dump_html: false
38
+ toc_headline: 'Contents',
39
+ dump_html: false,
40
+ dump_cover_html: false,
41
+ verbose: false,
42
+ dir_given: false
38
43
  }
39
44
 
40
45
  opt_parser = OptionParser.new do |opts|
@@ -51,17 +56,26 @@ module Riven
51
56
  end
52
57
 
53
58
  opts.on("-c FILE", "--cover=FILE", "Path to the cover MD file") do |cover_file|
54
- options[:cover_file] = cover_file
59
+ options[:cover_file] = Riven::MarkupFile.new(cover_file)
55
60
  end
56
61
 
57
- opts.on("-t", "--toc", "Enabled the table of contents auto generation") do
62
+ opts.on("-t HEADLINE", "--toc=HEADLINE", "Enabled the table of contents auto generation") do |headline|
58
63
  options[:toc] = true
64
+ options[:toc_headline] = headline
59
65
  end
60
66
 
61
- opts.on("-d", "--dump-html", "Dumps the HTML file to STDOUT") do
67
+ opts.on("-d", "--dump-html", "Dumps the main HTML file to STDOUT") do
62
68
  options[:dump_html] = true
63
69
  end
64
70
 
71
+ opts.on("-D", "--dump-cover-html", "Dumps the cover HTML file to STDOUT") do
72
+ options[:dump_cover_html] = true
73
+ end
74
+
75
+ opts.on('-v', '--verbose', 'Print the output of wkhtmltopdf to STDOUT. Don\'t combine with -d') do
76
+ options[:verbose] = true
77
+ end
78
+
65
79
  opts.on('-V', '--version', 'Displays the version') do
66
80
  puts Riven::VERSION.to_s
67
81
  exit
data/lib/riven/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Riven
2
- VERSION = '0.0.1'
3
- end
2
+ VERSION = '0.1.0'
3
+ end
@@ -10,17 +10,38 @@ module Riven
10
10
  end
11
11
  end
12
12
 
13
- public def generate_pdf(html_file, output_file)
13
+ public def generate_pdf(html_file, cover_html_file, output_file, options)
14
14
  params = [
15
- '--disable-smart-shrinking',
16
15
  '--page-size A4',
17
16
  '--margin-bottom 10mm',
18
17
  '--margin-top 10mm',
19
- '--margin-left 8mm',
20
- '--margin-right 8mm'
18
+ '--margin-left 20mm',
19
+ '--margin-right 20mm',
20
+ '--footer-left "[section]"',
21
+ '--footer-right "[page] / [toPage]"',
22
+ '--footer-font-size 7',
23
+ '--footer-spacing 4'
21
24
  ]
22
25
 
23
- output = `wkhtmltopdf #{params.join(' ')} #{html_file.file_name} #{output_file} 2>&1`
26
+ unless options[:cover_file] === ''
27
+ params << "cover \"#{cover_html_file.file_name}\""
28
+ end
29
+
30
+ if options[:toc]
31
+ xsl = File.read(File.expand_path(File.dirname(__FILE__)) + '/../../toc.xsl')
32
+ xsl.gsub! '[[toc_headline]]', options[:toc_headline]
33
+ xsl_file_name = '_tmp_toc.xsl'
34
+ File.open(xsl_file_name, 'w') { |file| file.write(xsl) }
35
+
36
+ params << 'toc'
37
+ params << "--xsl-style-sheet \"#{xsl_file_name}\""
38
+ end
39
+
40
+ output = `wkhtmltopdf #{params.join(' ')} "#{html_file.file_name}" "#{output_file}" 2>&1`
41
+
42
+ File.delete xsl_file_name
43
+
44
+ return output
24
45
  end
25
46
  end
26
47
  end
data/riven.gemspec CHANGED
@@ -29,4 +29,4 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_dependency 'redcarpet', '~> 3.2'
31
31
  spec.add_dependency 'coderay', '~> 1.1'
32
- end
32
+ end
data/toc.xsl ADDED
@@ -0,0 +1,72 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet version="2.0"
3
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
+ xmlns:outline="http://wkhtmltopdf.org/outline"
5
+ xmlns="http://www.w3.org/1999/xhtml">
6
+ <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
7
+ doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
8
+ indent="yes" />
9
+ <xsl:template match="outline:outline">
10
+ <html>
11
+ <head>
12
+ <title>[[toc_headline]]</title>
13
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
14
+ <style>
15
+ body {
16
+ color: #333;
17
+ font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
18
+ font-size: 14px;
19
+ line-height: 1.6;
20
+ }
21
+ a {
22
+ background: transparent;
23
+ }
24
+
25
+ a:active,
26
+ a:hover {
27
+ outline: 0;
28
+ }
29
+ h1 {
30
+ margin-top: 15px;
31
+ margin-bottom: 15px;
32
+ line-height: 1.2;
33
+ font-size: 24px;
34
+ page-break-inside: avoid;
35
+ border-bottom: 1px solid #eee;
36
+ }
37
+ div {border-bottom: 1px dashed #eee; margin: 0 0 5px 0;}
38
+ span {float: right;}
39
+ li {list-style: none; padding: 0; margin: 0;}
40
+ ul {padding: 0; margin: 0; font-size: 14px;}
41
+ ul ul {font-size: 85%; padding-left: 1em;}
42
+ </style>
43
+ </head>
44
+ <body>
45
+ <h1>[[toc_headline]]</h1>
46
+ <ul><xsl:apply-templates select="outline:item/outline:item"/></ul>
47
+ </body>
48
+ </html>
49
+ </xsl:template>
50
+ <xsl:template match="outline:item">
51
+ <li>
52
+ <xsl:if test="@title!=''">
53
+ <div>
54
+ <a>
55
+ <xsl:if test="@link">
56
+ <xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
57
+ </xsl:if>
58
+ <xsl:if test="@backLink">
59
+ <xsl:attribute name="name"><xsl:value-of select="@backLink"/></xsl:attribute>
60
+ </xsl:if>
61
+ <xsl:value-of select="@title" />
62
+ </a>
63
+ <span> <xsl:value-of select="@page" /> </span>
64
+ </div>
65
+ </xsl:if>
66
+ <ul>
67
+ <xsl:comment>added to prevent self-closing tags in QtXmlPatterns</xsl:comment>
68
+ <xsl:apply-templates select="outline:item"/>
69
+ </ul>
70
+ </li>
71
+ </xsl:template>
72
+ </xsl:stylesheet>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Kammerl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - lib/riven/version.rb
92
92
  - lib/riven/wkhtmltopdf.rb
93
93
  - riven.gemspec
94
+ - toc.xsl
94
95
  homepage: https://github.com/phortx/riven
95
96
  licenses:
96
97
  - MIT
@@ -111,8 +112,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.4.5
115
+ rubygems_version: 2.2.2
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: Converts Markdown to PDF
118
119
  test_files: []
120
+ has_rdoc: