kdbook 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/kdbook +65 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b662b7d1f0e04d742dd2c5f37985e9a3fd46e4eb
4
- data.tar.gz: e41ddc9fcd127efb7a080f858afa5a6e91854ede
3
+ metadata.gz: 7ed34fbceb2f3785b305bac44002cea2b9073041
4
+ data.tar.gz: 06a563bfaaaea77704693e0e923812c24351910f
5
5
  SHA512:
6
- metadata.gz: 65d277d1a0557635a7005da31c50b23e9562a5381c64f6e16009265a8c814a8d5ada532c1cb97231a7f37bb1412d40b44c09e9a6edefe7047ee34b0385d566e0
7
- data.tar.gz: fce4f9f047fa4b2954701d008140f35d650396da71a15677ee379b0918871fbd48602ebbbc17d34a53714aa01633f31ced75a1e2f1a7fdd69c6b5a291c0460b7
6
+ metadata.gz: bd402e3e7957ce14ef245020e0629c7d16a15a24e639888b871c734d4963f38c596f484c684689c9281caeee728b52ef38d0622964d61bed75c2b55ca062c997
7
+ data.tar.gz: 41cfdcddd5cb10961c4542dbb1ea4bccc174cd15a3633138801e7f2db090e43a430fd201b0e2b0af61fa000d068b6f692759694fe25c1c1cfc9b2c66eafd8645
data/bin/kdbook CHANGED
@@ -6,7 +6,7 @@ require 'colorize'
6
6
  require 'kramdown'
7
7
  require 'recursive-open-struct'
8
8
 
9
- VERSION = '0.0.1'
9
+ VERSION = '0.0.2'
10
10
 
11
11
  class KdbookBin < Thor
12
12
  class_option :'config-file', type: :string, aliases: 'f', default: 'kdbook.yml'
@@ -67,8 +67,72 @@ class KdbookBin < Thor
67
67
  end
68
68
  end
69
69
 
70
+ desc 'gen-config', 'Write an example config file'
71
+ long_desc <<-LONGDESC
72
+ Writes an example config file to specified file or the default
73
+ file (kdbook.yml). This can then be configured as desired.
74
+ LONGDESC
75
+ option :force, type: :boolean, aliases: 'f', default: false
76
+ def gen_config
77
+ if File.exists?(options[:'config-file'])
78
+ confirm_write(options)
79
+ else
80
+ write_default_file(options)
81
+ end
82
+ end
83
+
70
84
  private
71
85
 
86
+ def config_file_comments
87
+ %q(---
88
+ # array of: either just a string (input file), a hash
89
+ # with input (which is input filename), optional output
90
+ # formats, optional template file for HTML, optional
91
+ # flag to count toward word count (defaults to true if
92
+ # not specified). Example entry in array:
93
+ #
94
+ # kdbook:
95
+ # - input: 'main-book.md'
96
+ # output: ['html', 'pdf']
97
+ # wordcount:
98
+ # min: 60000
99
+ # max: 90000
100
+ #).split("\n").map{|s| s.sub(' ' * 6, '')}.join("\n")
101
+ end
102
+
103
+ def config_file_defaults
104
+ {
105
+ 'output' => ['html', 'pdf'],
106
+ 'wordcount' => { 'min' => 60000, 'max' => 90000 }
107
+ }
108
+ end
109
+
110
+ def write_default_file(options)
111
+ comments = config_file_comments
112
+ defaults = config_file_defaults
113
+ glob = Dir.glob('*.md')
114
+ puts "Writing config file to '#{options[:'config-file']}' containing files: #{glob.join(', ')}".green
115
+ yaml = { 'kdbook' => glob
116
+ .map{ |f| { 'input' => f }
117
+ .merge(defaults) }}
118
+ File.write(
119
+ options[:'config-file'],
120
+ yaml.to_yaml.gsub('---', comments)
121
+ )
122
+ end
123
+
124
+ def confirm_write(options)
125
+ print "A config file already exists at #{options[':config-file']}. Overwrite? (Y/N): ".yellow
126
+ action = STDIN.gets.chomp
127
+ if action =~ /y/i
128
+ puts "Overwriting config file with new version at #{options[:'config-file']}".green
129
+ write_default_file(options)
130
+ else
131
+ puts "User declined. Not writing config file".red
132
+ return
133
+ end
134
+ end
135
+
72
136
  def file_list(options)
73
137
  config(options)
74
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Porter