kdbook 0.0.1 → 0.0.2
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/bin/kdbook +65 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ed34fbceb2f3785b305bac44002cea2b9073041
|
4
|
+
data.tar.gz: 06a563bfaaaea77704693e0e923812c24351910f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|