kdbook 0.0.5 → 0.1.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/bin/kdbook +83 -1
- metadata +31 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c9644b1eb4c418df651874791afb745ffde8a46
|
4
|
+
data.tar.gz: 1131d6ce4958dca0971b0a5461fd4dff2f91f0d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 453847b962119183241aa93880dd8f93a32b61f11c005b56295bde96507e0f09cc4ab0913891020db87e6adbcfb881fb6619a489c8096a3749348095a89c476c
|
7
|
+
data.tar.gz: bb8857981eac461a53890cf00149fe0451436d511f9560209e4f070d04b05b4e4b609e6897fe5a0d67669b522e30ed19b9043e4678a647cd6f2a5784c4592b9f
|
data/bin/kdbook
CHANGED
@@ -44,8 +44,17 @@ class KdbookBin < Thor
|
|
44
44
|
You can optionally pass in filenames as args to build specific files
|
45
45
|
LONGDESC
|
46
46
|
def build(*files)
|
47
|
+
puts "BUILD REQUEST IN FOR FILES: #{files}".yellow
|
47
48
|
file_list(options).each do |file|
|
48
49
|
file.output.each do |out|
|
50
|
+
puts "files: #{files}"
|
51
|
+
puts "file: #{file}"
|
52
|
+
if build?(files, file)
|
53
|
+
puts 'It _IS_ a build '.blue
|
54
|
+
else
|
55
|
+
puts 'It is not a build '.blue
|
56
|
+
end
|
57
|
+
next unless build?(files, file)
|
49
58
|
case out
|
50
59
|
when /pdf/i
|
51
60
|
to_pdf(file.input, output_file(file.input, out))
|
@@ -81,6 +90,71 @@ class KdbookBin < Thor
|
|
81
90
|
end
|
82
91
|
end
|
83
92
|
|
93
|
+
desc 'serve', 'Start a web serve to serve the files'
|
94
|
+
long_desc <<-LONGDESC
|
95
|
+
Starts a sinatra web server that will serve the book files on demand.
|
96
|
+
They will also be rebuilt on each request, unless disabled.
|
97
|
+
LONGDESC
|
98
|
+
option :port, type: :numeric, aliases: 'p', default: 4567
|
99
|
+
option :interface, type: :string, aliases: 'i', default: 'localhost' # or '0.0.0.0'
|
100
|
+
option :files, type: :array, aliases: 'f', default: []
|
101
|
+
option :build, type: :boolean, aliases: 'b', default: true
|
102
|
+
def serve
|
103
|
+
files = options[:files]
|
104
|
+
files = output_file_list(options) if files.empty?
|
105
|
+
interface = options[:interface]
|
106
|
+
port = options[:port]
|
107
|
+
build = options[:build]
|
108
|
+
do_build = method(:build)
|
109
|
+
|
110
|
+
require 'sinatra'
|
111
|
+
|
112
|
+
kdbook_server = Class.new(Sinatra::Base)
|
113
|
+
kdbook_server.set(:bind, interface)
|
114
|
+
kdbook_server.set(:port, port)
|
115
|
+
|
116
|
+
kdbook_server.get('/') do
|
117
|
+
# show an index with links to all the files
|
118
|
+
<<DOC
|
119
|
+
<!DOCTYPE html>
|
120
|
+
<html>
|
121
|
+
<head>
|
122
|
+
<title>kdbook list of files</title>
|
123
|
+
</head>
|
124
|
+
<body>
|
125
|
+
<p><strong>kdbook list of files:</strong></p>
|
126
|
+
<ul>
|
127
|
+
#{files.map{|f| "<li><a href=\"#{f}\">#{f}</a></li>"}.join(' ') }
|
128
|
+
</ul>
|
129
|
+
</body>
|
130
|
+
</html>
|
131
|
+
DOC
|
132
|
+
end
|
133
|
+
|
134
|
+
kdbook_server.get('/:filename') do |filename|
|
135
|
+
puts "Received request for file '#{filename}'".green
|
136
|
+
if build
|
137
|
+
puts "Building all files fresh before responding".green
|
138
|
+
do_build.call(filename)
|
139
|
+
puts "Done building".green
|
140
|
+
else
|
141
|
+
puts "Not building before serving cause build is disabled".yellow
|
142
|
+
end
|
143
|
+
|
144
|
+
if File.exist?(filename)
|
145
|
+
puts "File '#{filename}' found. serving...".green
|
146
|
+
send_file(filename)
|
147
|
+
else
|
148
|
+
puts "File '#{filename}' not found. Check URL and make sure files are built. Returning 404".red
|
149
|
+
halt 404
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
puts "Starting the server on port #{options[:port]}.".green
|
154
|
+
kdbook_server.run!
|
155
|
+
puts 'Server has exited.'.green
|
156
|
+
end
|
157
|
+
|
84
158
|
private
|
85
159
|
|
86
160
|
def config_file_comments
|
@@ -213,10 +287,18 @@ class KdbookBin < Thor
|
|
213
287
|
.map { |f| add_missing_output(f) }
|
214
288
|
.map { |f| RecursiveOpenStruct.new(f, recurse_over_arrays: true) }
|
215
289
|
end
|
290
|
+
|
291
|
+
def build?(files, file)
|
292
|
+
return true if files.empty?
|
293
|
+
files.include?(file.input) || files.include?(file.output) || files.any? do |f|
|
294
|
+
file.input.include?(f) || file.output.include?(f)
|
295
|
+
end
|
296
|
+
end
|
216
297
|
end
|
217
298
|
|
218
299
|
aliases = {
|
219
|
-
'wc' => 'wordcount'
|
300
|
+
'wc' => 'wordcount',
|
301
|
+
'server' => 'serve'
|
220
302
|
}
|
221
303
|
|
222
304
|
if !ARGV.empty? && %w[-v --version].include?(ARGV.first)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kdbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.4'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: thin
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.7'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.7'
|
97
125
|
description: book writing in markdown made easy
|
98
126
|
email: BenjaminPorter86@gmail.com
|
99
127
|
executables:
|
@@ -122,9 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
150
|
version: '0'
|
123
151
|
requirements: []
|
124
152
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.2.5
|
126
154
|
signing_key:
|
127
155
|
specification_version: 4
|
128
156
|
summary: book writing in markdown made easy
|
129
157
|
test_files: []
|
130
|
-
has_rdoc:
|