riven 1.1.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile.lock +2 -5
  4. data/README.md +20 -153
  5. data/bin/riven +17 -18
  6. data/doc/chapters/1-what-is-riven/1-scenario-a.md +12 -0
  7. data/doc/chapters/1-what-is-riven/2-scenario-b.md +8 -0
  8. data/doc/chapters/1-what-is-riven/3-what-is-riven-not.md +16 -0
  9. data/doc/chapters/1-what-is-riven/4-why-was-riven-created.md +35 -0
  10. data/doc/chapters/1-what-is-riven/5-how-can-i-support-riven.md +7 -0
  11. data/doc/chapters/1-what-is-riven/index.md +15 -0
  12. data/doc/chapters/2-setup/1-prerequisites.md +49 -0
  13. data/doc/chapters/2-setup/2-installation.md +17 -0
  14. data/doc/chapters/2-setup/index.md +6 -0
  15. data/doc/chapters/3-basics/1-single-file.md +19 -0
  16. data/doc/chapters/3-basics/2-multiple-files.md +65 -0
  17. data/doc/chapters/3-basics/3-structured-files.md +55 -0
  18. data/doc/chapters/3-basics/4-config-file.md +63 -0
  19. data/doc/chapters/3-basics/index.md +17 -0
  20. data/doc/chapters/4-advanced-usage/1-css.md +34 -0
  21. data/doc/chapters/4-advanced-usage/2-table-of-contents.md +11 -0
  22. data/doc/chapters/4-advanced-usage/3-cover.md +10 -0
  23. data/doc/chapters/4-advanced-usage/4-syntax-highlighting.md +23 -0
  24. data/doc/chapters/4-advanced-usage/index.md +10 -0
  25. data/doc/cover.md +37 -0
  26. data/doc/img/cover.png +0 -0
  27. data/doc/index.md +4 -0
  28. data/doc/riven.pdf +0 -0
  29. data/doc/riven.yml +10 -0
  30. data/doc/style.css +21 -0
  31. data/lib/riven/config.rb +122 -0
  32. data/lib/riven/html_generator.rb +4 -4
  33. data/lib/riven/markup_file.rb +1 -1
  34. data/lib/riven/opt_parser.rb +48 -33
  35. data/lib/riven/version.rb +1 -1
  36. data/lib/riven/wkhtmltopdf.rb +7 -7
  37. metadata +28 -2
@@ -7,11 +7,11 @@ module Riven
7
7
  class HTMLGenerator
8
8
  attr_accessor :html, :html_file
9
9
 
10
- public def initialize(tmp_file, markup, options)
10
+ public def initialize(tmp_file, markup, config)
11
11
  @html_file = Riven::HTMLFile.new(tmp_file)
12
12
 
13
13
  @markup = markup
14
- @options = options
14
+ @config = config
15
15
 
16
16
  @html = generate_html
17
17
  @html_file.write(@html)
@@ -20,9 +20,9 @@ module Riven
20
20
  public def generate_html
21
21
  css = File.read(File.expand_path(File.dirname(__FILE__)) + '/../../css/style.css')
22
22
 
23
- unless @options[:css_file].empty?
23
+ unless @config.css_file.empty?
24
24
  css << "\n\n"
25
- css << File.read(@options[:css_file])
25
+ css << File.read(@config.css_file)
26
26
  end
27
27
 
28
28
  html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
@@ -93,7 +93,7 @@ module Riven
93
93
  end
94
94
  end
95
95
 
96
- return markup
96
+ markup
97
97
  end
98
98
 
99
99
  public def read_cover(cover_file)
@@ -1,5 +1,6 @@
1
1
  require 'optparse'
2
2
  require 'riven'
3
+ require 'riven/config'
3
4
  require 'riven/markup_file'
4
5
 
5
6
  module Riven
@@ -10,70 +11,66 @@ module Riven
10
11
  class OptParser
11
12
  class << self
12
13
  #
13
- # Returns an array of Riven::MarkupFile for each given markdown file
14
+ # Sets the files field of the Config object
14
15
  #
15
16
 
16
- public def files(options)
17
+ public def get_files(config)
17
18
  file_names = ARGV
18
19
 
19
20
  if file_names.size === 1 && File.directory?(file_names[0])
20
- options[:dir_given] = file_names.first
21
+ config.dir_given = file_names.first
21
22
  file_names = Dir["#{file_names[0]}/*.md"].sort
23
+ elsif file_names.size > 0
24
+ config.files = file_names.map { |file| Riven::MarkupFile.new(file) }
22
25
  end
23
-
24
- file_names.map { |file| Riven::MarkupFile.new(file) }
25
26
  end
26
27
 
27
28
 
28
29
  #
29
- # Parses the options and returns a map with the options and their values.
30
+ # Parses the options and the config file if any and returns the Config object
30
31
  #
31
32
 
32
- public def options
33
- options = {
34
- output_file: '',
35
- cover_file: '',
36
- css_file: '',
37
- toc: false,
38
- toc_headline: 'Contents',
39
- dump_html: false,
40
- dump_cover_html: false,
41
- verbose: false,
42
- dir_given: false
43
- }
33
+ public def get_config
34
+ config = Riven::Config.new
44
35
 
45
36
  opt_parser = OptionParser.new do |opts|
46
37
  opts.banner = 'Usage: riven [OPTIONS] Markdown Files'
47
38
  opts.separator ''
48
39
  opts.separator 'Options'
49
40
 
50
- opts.on("-o FILE", "--output=FILE", "File name of the output PDF file") do |output_file|
51
- options[:output_file] = output_file
41
+ opts.on('-C FILE', '--config=FILE', 'Path to the riven config file') do |config_file|
42
+ current_config = config
43
+ config = Riven::Config.parse(config_file)
44
+ config.merge(current_config)
45
+ end
46
+
47
+ opts.on('-o FILE', '--output=FILE', 'File name of the output PDF file') do |pdf_output_file|
48
+ config.pdf_output_file = pdf_output_file
52
49
  end
53
50
 
54
- opts.on("-s FILE", "--css=FILE", "Path to the custom CSS file") do |css_file|
55
- options[:css_file] = File.expand_path(css_file)
51
+ opts.on('-s FILE', '--css=FILE', 'Path to the custom CSS file') do |css_file|
52
+ config.css_file = css_file
56
53
  end
57
54
 
58
- opts.on("-c FILE", "--cover=FILE", "Path to the cover MD file") do |cover_file|
59
- options[:cover_file] = Riven::MarkupFile.new(cover_file)
55
+ opts.on('-c FILE', '--cover=FILE', 'Path to the cover MD file') do |cover_file|
56
+ config.cover_file = cover_file
60
57
  end
61
58
 
62
- opts.on("-t HEADLINE", "--toc=HEADLINE", "Enabled the table of contents auto generation") do |headline|
63
- options[:toc] = true
64
- options[:toc_headline] = headline
59
+ opts.on('-t HEADLINE', '--toc=HEADLINE', 'Enabled the table of contents auto generation') do |headline|
60
+ config.generate_toc = true
61
+ config.toc_headline = headline
65
62
  end
66
63
 
67
- opts.on("-d", "--dump-html", "Dumps the main HTML file to STDOUT") do
68
- options[:dump_html] = true
64
+ opts.on('-d', '--dump-html', 'Dumps the main HTML file to STDOUT') do
65
+ config.dump_html = true
69
66
  end
70
67
 
71
- opts.on("-D", "--dump-cover-html", "Dumps the cover HTML file to STDOUT") do
72
- options[:dump_cover_html] = true
68
+ opts.on('-D', '--dump-cover-html', 'Dumps the cover HTML file to STDOUT') do
69
+ config.dump_cover_html = true
73
70
  end
74
71
 
75
72
  opts.on('-v', '--verbose', 'Print the output of wkhtmltopdf to STDOUT. Don\'t combine with -d') do
76
- options[:verbose] = true
73
+ config.verbose = true
77
74
  end
78
75
 
79
76
  opts.on('-V', '--version', 'Displays the version') do
@@ -85,7 +82,25 @@ module Riven
85
82
 
86
83
  opt_parser.parse!
87
84
 
88
- return options
85
+
86
+ # Load default config if necessary
87
+
88
+ default_config_file = 'riven.yml'
89
+
90
+ if config.config_file == nil && File.exist?(default_config_file)
91
+ current_config = config
92
+ config = Riven::Config.parse(default_config_file)
93
+ config.merge(current_config)
94
+ end
95
+
96
+
97
+ # Determine which files should be used
98
+ get_files(config)
99
+
100
+ # Print current config in verbose mode
101
+ config.print if config.verbose
102
+
103
+ config
89
104
  end
90
105
  end
91
106
  end
@@ -1,3 +1,3 @@
1
1
  module Riven
2
- VERSION = '1.1.4'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -5,12 +5,12 @@ module Riven
5
5
  `wkhtmltopdf -V > /dev/null 2>&1`
6
6
 
7
7
  unless $?.exitstatus == 0
8
- puts "Seems like wkhtmltopdf is not correctly installed or set up"
8
+ puts 'Seems like wkhtmltopdf is not correctly installed or set up'
9
9
  exit
10
10
  end
11
11
  end
12
12
 
13
- public def generate_pdf(html_file, cover_html_file, output_file, options)
13
+ public def generate_pdf(html_file, cover_html_file, output_file, config)
14
14
  params = [
15
15
  '--page-size A4',
16
16
  '--margin-bottom 20mm',
@@ -23,13 +23,13 @@ module Riven
23
23
  '--footer-spacing 10'
24
24
  ]
25
25
 
26
- unless options[:cover_file] === ''
26
+ unless config.cover_file === ''
27
27
  params << "cover \"#{cover_html_file.file_name}\""
28
28
  end
29
29
 
30
- if options[:toc]
30
+ if config.generate_toc
31
31
  xsl = File.read(File.expand_path(File.dirname(__FILE__)) + '/../../toc.xsl')
32
- xsl.gsub! '[[toc_headline]]', options[:toc_headline]
32
+ xsl.gsub! '[[toc_headline]]', config.toc_headline
33
33
  xsl_file_name = '_tmp_toc.xsl'
34
34
  File.open(xsl_file_name, 'w') { |file| file.write(xsl) }
35
35
 
@@ -39,9 +39,9 @@ module Riven
39
39
 
40
40
  output = `wkhtmltopdf #{params.join(' ')} "#{html_file.file_name}" "#{output_file}" 2>&1`
41
41
 
42
- File.delete xsl_file_name if options[:toc]
42
+ File.delete xsl_file_name if config.generate_toc
43
43
 
44
- return output
44
+ output
45
45
  end
46
46
  end
47
47
  end
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: 1.1.4
4
+ version: 1.3.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-10-15 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,33 @@ files:
81
81
  - README.md
82
82
  - bin/riven
83
83
  - css/style.css
84
+ - doc/chapters/1-what-is-riven/1-scenario-a.md
85
+ - doc/chapters/1-what-is-riven/2-scenario-b.md
86
+ - doc/chapters/1-what-is-riven/3-what-is-riven-not.md
87
+ - doc/chapters/1-what-is-riven/4-why-was-riven-created.md
88
+ - doc/chapters/1-what-is-riven/5-how-can-i-support-riven.md
89
+ - doc/chapters/1-what-is-riven/index.md
90
+ - doc/chapters/2-setup/1-prerequisites.md
91
+ - doc/chapters/2-setup/2-installation.md
92
+ - doc/chapters/2-setup/index.md
93
+ - doc/chapters/3-basics/1-single-file.md
94
+ - doc/chapters/3-basics/2-multiple-files.md
95
+ - doc/chapters/3-basics/3-structured-files.md
96
+ - doc/chapters/3-basics/4-config-file.md
97
+ - doc/chapters/3-basics/index.md
98
+ - doc/chapters/4-advanced-usage/1-css.md
99
+ - doc/chapters/4-advanced-usage/2-table-of-contents.md
100
+ - doc/chapters/4-advanced-usage/3-cover.md
101
+ - doc/chapters/4-advanced-usage/4-syntax-highlighting.md
102
+ - doc/chapters/4-advanced-usage/index.md
103
+ - doc/cover.md
104
+ - doc/img/cover.png
105
+ - doc/index.md
106
+ - doc/riven.pdf
107
+ - doc/riven.yml
108
+ - doc/style.css
84
109
  - lib/riven.rb
110
+ - lib/riven/config.rb
85
111
  - lib/riven/html_file.rb
86
112
  - lib/riven/html_generator.rb
87
113
  - lib/riven/markup/code.rb