#!/usr/bin/env ruby require 'gli' require 'bookingit' include GLI::App include FileUtils program_desc 'Manage a bookingit book' version Bookingit::VERSION desc 'Set up a new book' arg_name 'dir (defaults to .)' command :init do |c| c.action do |global_options,options,args| dir = args.shift || "." chdir dir do File.open('config.json','w') do |file| file.puts %{ { "front_matter": "front.md", "main_matter": "main.md", "back_matter": "back.md", } } end File.open("front.md",'w') do |file| file.puts "# Intro Goes Here" end File.open("main.md",'w') do |file| file.puts "# Main stuff here" end File.open("back.md",'w') do |file| file.puts "# Appendeces and whatnot" end end end end desc 'build your book from markdown files' arg_name 'config_file output_dir' command :build do |c| 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 %{
} index.puts "