bin/bookingit in bookingit-0.0.1 vs bin/bookingit in bookingit-0.1.0
- old
+ new
@@ -18,11 +18,11 @@
File.open('config.json','w') do |file|
file.puts %{
{
"front_matter": "front.md",
"main_matter": "main.md",
- "back_matter": "back.md",
+ "back_matter": "back.md"
}
}
end
File.open("front.md",'w') do |file|
file.puts "# Intro Goes Here"
@@ -36,68 +36,19 @@
end
end
end
desc 'build your book from markdown files'
-arg_name 'config_file output_dir'
command :build do |c|
+ c.desc "Use cache for code samples and console sessions"
+ c.default_value true
+ c.switch :cache
c.action do |global_options,options,args|
- puts pwd
- config = Bookingit::Config.new(File.read(args.shift),File.expand_path('.'))
- output_dir = args.shift
- mkdir output_dir unless Dir.exists?(output_dir)
-
- renderer = Bookingit::Renderer.new
- redcarpet = Redcarpet::Markdown.new(renderer, no_intra_emphasis: true,
- tables: true,
- fenced_code_blocks: true,
- autolink: true,
- strikethrough: true,
- superscript: true)
-
- chdir output_dir do
- File.open('index.html','w') do |index|
- index.puts %{<!DOCTYPE html>
-<html>
-<head>
-</head>
-<body>
-}
- index.puts "<ol>"
- %w(front_matter main_matter back_matter).each do |matter|
- index.puts "<li>#{matter}<ol>"
- config.send(matter).chapters.each_with_index do |chapter,i|
- contents = if chapter.path.nil?
- chapter.sections.map(&:path).map { |path|
- File.read(path)
- }.join("\n")
- else
- File.read(chapter.path)
- end
-
- output_file = "#{matter}_#{i+1}.html"
- File.open(output_file,'w') do |file|
- file.puts redcarpet.render(contents)
- end
- title = (Array(renderer.headers[1]) +
- Array(renderer.headers[2]) +
- Array(renderer.headers[3]) +
- Array(renderer.headers[4]) +
- Array(renderer.headers[5]) +
- Array(renderer.headers[6])).first
- index.puts "<li><a href='#{output_file}'>#{title}</a></li>"
- end
- index.puts "</ol></li>"
- end
- index.puts "</ol>"
- index.puts %{
-
-</body>
-</html>
-}
- end
- end
+ config = Bookingit::Config.new(File.read('config.json'),File.expand_path('.'))
+ config.cache = options[:cache]
+ book = Bookingit::Book.new(config)
+ book.render_html!
end
end
pre do |global,command,options,args|
true
@@ -105,9 +56,19 @@
post do |global,command,options,args|
end
on_error do |exception|
- true
+ case exception
+ when Bookingit::UnexpectedShellCommandExit
+ $stderr.puts "'#{exception.command}' exited in an unexpected way with exit status #{exception.exit_code}"
+ $stderr.puts "stdout:"
+ $stderr.puts exception.stdout
+ $stderr.puts "stderr:"
+ $stderr.puts exception.stderr
+ false
+ else
+ true
+ end
end
exit run(ARGV)